Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/horihiro/esp8266-google-home-notifier
https://github.com/horihiro/esp8266-google-home-notifier
arduino arduino-ide castv2 esp32 esp8266 google-home googlehome
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/horihiro/esp8266-google-home-notifier
- Owner: horihiro
- License: mit
- Created: 2018-04-02T12:43:07.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-02-09T22:40:35.000Z (almost 3 years ago)
- Last Synced: 2023-03-05T22:11:33.625Z (almost 2 years ago)
- Topics: arduino, arduino-ide, castv2, esp32, esp8266, google-home, googlehome
- Language: C
- Size: 143 KB
- Stars: 97
- Watchers: 14
- Forks: 22
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# esp8266-google-home-notifier
Send notifications to Google Home from esp8266.This library depends on Google Translate Service.
[This](https://qiita.com/horihiro/items/4ab0edf415916a2cd542) is the Japanese document on [Qiita.com](https://qiita.com/);
## Install
This library can be installed from the Library Manager on Arduino IDE![](./librarymanager.png)
## Requirement
- Arduino board
- esp8266 ***Arduino Core ESP8266 2.x only**
- esp32
(note: 1.0.2 and later, and 1.0.4 requires [83810fa](https://github.com/espressif/arduino-esp32/tree/83810fa1563f77145272583e36dfb076d3a92018) or later of [arduino-esp32](https://github.com/espressif/arduino-esp32))
- [esp8266-google-tts](https://github.com/horihiro/esp8266-google-tts)
[download from Library Manager](https://github.com/horihiro/esp8266-google-tts/blob/master/README.md#install) of Arduino IDE- (only for ver 1.0.1 and earlier) Latest ESP8266mDNS
- download [ESP8266mDNS.cpp](https://github.com/mblythe86/Arduino/blob/master/libraries/ESP8266mDNS/ESP8266mDNS.cpp)/[.h](https://github.com/mblythe86/Arduino/blob/master/libraries/ESP8266mDNS/ESP8266mDNS.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
- ~~use [Arduino Core for ESP8266](https://github.com/esp8266/Arduino/) **2.5.0**, which will [merge ESP8266mDNS.cpp/.h](https://github.com/esp8266/Arduino/pull/3107), or later.~~
-> The PR wasn't merged, so MDNS handling in this library should be fix under ESP8266 cor 2.5.0 or later.## Usage
### Simple for esp8266/32
```
#ifdef ARDUINO_ARCH_ESP8266
#include
#endif#ifdef ARDUINO_ARCH_ESP32
#include
#endif
#includeconst char* ssid = "";
const char* 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
#include
#includeconst char* ssid = "";
const char* 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", "speechvar d = document;d.querySelector('button').addEventListener('click',function(){xhr = new XMLHttpRequest();xhr.open('GET','/speech?phrase='+encodeURIComponent(d.querySelector('input').value));xhr.send();});");
}void loop() {
// put your main code here, to run repeatedly:
server.handleClient();
}
```