• Stars
    star
    100
  • Rank 340,703 (Top 7 %)
  • Language
    C
  • License
    MIT License
  • Created over 6 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

esp8266-google-home-notifier

Send notifications to Google Home from esp8266.

This library depends on Google Translate Service.

This is the Japanese document on Qiita.com;

Install

This library can be installed from the Library Manager on Arduino IDE

Requirement

  • Arduino board

    • esp8266 *Arduino Core ESP8266 2.x only
    • esp32
      (note: 1.0.2 and later, and 1.0.4 requires 83810fa or later of arduino-esp32)
  • esp8266-google-tts
    download from Library Manager of Arduino IDE

  • (only for ver 1.0.1 and earlier) Latest ESP8266mDNS

    • download ESP8266mDNS.cpp/.h to $LIBRARIES_DIR/esp8266-google-home-notifier/src/ and restart Arduino IDE, like below structure.
    $LIBRARIES_DIR
      └── esp8266-google-home-notifier/
          ├── LICENSE
          ├── README.md
          :
          └── src/
              ├── ESP8266mDNS.cpp  # <- additional file
              ├── ESP8266mDNS.h    # <- additional file
              :
              ├── esp8266-google-home-notifier.cpp
              └── esp8266-google-home-notifier.h
    

    or

Usage

Simple for esp8266/32

#ifdef ARDUINO_ARCH_ESP8266
#include <ESP8266WiFi.h>
#endif

#ifdef ARDUINO_ARCH_ESP32
#include <WiFi.h>
#endif
#include <esp8266-google-home-notifier.h>

const char* ssid     = "<REPLASE_YOUR_WIFI_SSID>";
const char* password = "<REPLASE_YOUR_WIFI_PASSWORD>";

GoogleHomeNotifier ghn;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("");
  Serial.print("connecting to Wi-Fi");
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(250);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("connected.");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());  //Print the local IP
  
  const char displayName[] = "Family Room";

  Serial.println("connecting to Google Home...");
  if (ghn.device(displayName, "en") != true) {
    Serial.println(ghn.getLastError());
    return;
  }
  Serial.print("found Google Home(");
  Serial.print(ghn.getIPAddress());
  Serial.print(":");
  Serial.print(ghn.getPort());
  Serial.println(")");
  
  if (ghn.notify("Hello, World!") != true) {
    Serial.println(ghn.getLastError());
    return;
  }
  Serial.println("Done.");
}

void loop() {
  // put your main code here, to run repeatedly:

}

Notification Server for esp8266

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <esp8266-google-home-notifier.h>

const char* ssid     = "<REPLASE_YOUR_WIFI_SSID>";
const char* password = "<REPLASE_YOUR_WIFI_PASSWORD>";

ESP8266WebServer server(80);
GoogleHomeNotifier ghn;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("");
  Serial.print("connecting to Wi-Fi");
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(250);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("connected.");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());  //Print the local IP
  
  const char displayName[] = "Family Room";

  Serial.println("connecting to Google Home...");
  if (ghn.device(displayName, "en") != true) {
    Serial.println(ghn.getLastError());
    return;
  }
  Serial.print("found Google Home(");
  Serial.print(ghn.getIPAddress());
  Serial.print(":");
  Serial.print(ghn.getPort());
  Serial.println(")");
  
  server.on("/speech", handleSpeechPath);
  server.on("/", handleRootPath);
  server.begin();
 }

void handleSpeechPath() {
  String phrase = server.arg("phrase");
  if (phrase == "") {
    server.send(401, "text / plain", "query 'phrase' is not found");
    return;
  }
  if (ghn.notify(phrase.c_str()) != true) {
    Serial.println(ghn.getLastError());
    server.send(500, "text / plain", ghn.getLastError());
    return;
  }
  server.send(200, "text / plain", "OK");
}

void handleRootPath() {
  server.send(200, "text/html", "<html><head></head><body><input type=\"text\"><button>speech</button><script>var d = document;d.querySelector('button').addEventListener('click',function(){xhr = new XMLHttpRequest();xhr.open('GET','/speech?phrase='+encodeURIComponent(d.querySelector('input').value));xhr.send();});</script></body></html>");
}

void loop() {
  // put your main code here, to run repeatedly:
  server.handleClient();
}

More Repositories

1

esp8266-google-tts

C++
65
star
2

node-fitbit-livedata

This project aims to getting `livedata` from Fitbit tracker, is unofficial and experimental.
JavaScript
10
star
3

moddable-polyfill

polyfill libraries for Moddable SDK
JavaScript
7
star
4

TextBlurrer-ChromeExtension

TypeScript
6
star
5

azure-functions-puppeteer-node-cjkfont

Sample project for running puppeteer with CJK font on Azure Functions
TypeScript
6
star
6

azure-functions-python-opencv-example

Example for using OpenCV in Python 🐍 on Azure Functions <⚡> consumption plan
Python
5
star
7

nuxt-express-azure-webapps

This template is for Azure Web Apps (Windows) and generated by https://github.com/nuxt-community/express-template .
Vue
4
star
8

wio-setup

JavaScript
4
star
9

functions-on-azure-containerapp

Shell
4
star
10

enebular-infotype-electrocardiogram

JavaScript
3
star
11

azurePortalNotification

JavaScript
2
star
12

esp32-fitbit-livedata

C++
2
star
13

deno-azure-webapps

Deno 🦕 container image for Azure Web App for Containers
TypeScript
2
star
14

azure-functions-playwright-dotnet5-linux-consumption

Azure Functions Playwright for dotnet5 on Linux Consumption plan
C#
2
star
15

ssh2webapp

Wrapper script of Azure CLI and ssh for connecting to App Service on Linux
Shell
1
star
16

moddable-google-tts

JavaScript
1
star
17

moddable-google-home-notifier

C
1
star
18

containers-cicd-handson-tutorial

Bicep
1
star
19

node-red-contrib-fitbit-livedata

JavaScript
1
star
20

azure-custom-role-generator

A command line tool generating Azure Custom Role definition template
Rust
1
star
21

simple-dns-forwarder

Dockerfile
1
star
22

Azure-portal-plus-ChromeExtension

JavaScript
1
star
23

exercise-use-gitignore

1
star