Skip to content
No description or website provided.
Branch: master
Clone or download
Latest commit d02e32d Feb 11, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples remove the code for esp8266 Jun 6, 2018
src
.gitignore Initial commit Apr 2, 2018
LICENSE
README.md Update README.md Feb 11, 2019
keywords.txt fix bug Aug 11, 2018
library.json Bump version to 1.0.6 Sep 1, 2018
library.properties release 1.0.6 Aug 26, 2018
librarymanager.png release 1.0.2 Jun 7, 2018

README.md

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-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();
}
You can’t perform that action at this time.