I am trying to figure out to get notified via Google Home / Fritzbox phone when someone rings the door bell.
Therefore I use NodeMCU LUA AMICA V2 Modul with ESP8266E. Which should be outside in the door bell connected to the door bell switch.
I have got inspired by this articel. This articel only shows the code for fritzbox phone notification.
https://www.reichelt.com/magazin/en/build-smart-doorbell-arduino/
This code I combined with "esp8266-google-home-notifier.h" for following action:
a) If someone presses the door bell button, ESP8266E sends a notification via google home mini like "Someone rings the door bell".
b) If someone presses the door bell button for the second time, ESP8266E sends a notification via google home mini like "Someone rings the door bell" again.
c) If someone presses the door bell button for the third time, ESP8266E activite Fitzbox and rings all connected phones and hang up after e.g. 4 times.
Therefore I created this source code (the LEDs are just for development purpose and shows in which state the controller actually is), see below.
During the test following issue came up. Everything works fine. Pressing two times the button google home mini notify the message. After the third time, Fritzbox sends me phone call.
Issue:
If i press the button for the fourth time. I got a message: "connection failed". Means google home mini is not available.
Sometimes I got an error message if calling Fritzbox "[action] got an unauthenticated error. Using the new nonce and trying again in 3s.".
The thing is nofication via google home mini (stand alone) works fine. Also notification via fritzbox (stand alone) works fine.
If i combine both: google home mini and fritzbox, always these two failures occure.
Example: Connection failed to google home mini
12:29:25.757 -> WiFi connected..!
12:29:25.757 -> Got IP: 192.168.2.176
12:29:25.757 -> Connecting to
12:29:25.791 -> Stangl
12:29:25.791 -> Connect to Google
12:29:25.791 -> connecting to Google Home...
12:29:26.772 -> found Google Home(192.168.2.133:8009)
12:29:32.195 -> Initialize TR-064 connection
12:30:23.131 -> Fritzbox call
12:30:23.131 -> taster_counter
12:30:23.131 -> Call **621
12:30:27.230 -> Dial Hangup
12:30:37.711 -> connection failed
#include <Bounce2.h>
#include <ESP8266WiFi.h>
#include <esp8266-google-home-notifier.h>
#include <tr064.h>
//**********************************************************
const int taster = D7;
const int rot = D6;
const int gruen = D8;
int tasterstatus = 0;
int tasterstatusAlt = 0;
int taster_counter = 0;
//***************************************************************
const char* ssid = "Wifi-Network"; <- must be changed
const char* password = "12345678"; <- must be changed
const char GoogleHomeName[] = "Büro"; //Must match the name on Google Home APP
/* Put IP Address details */
const IPAddress local_ip(192, 168, 2, 160);
const IPAddress gateway(192, 168, 2, 1);
const IPAddress subnet(255, 255, 255, 0);
const IPAddress DNS(gateway);
const char DEVICE_NAME[] = "Door bell";
//fritzbox
const char USER[] = "admin";
const char PASSWORD[] = "fritzbox password"; // <-- ändern
const char FRITZBOX_IP[] = "192.168.2.1"; //<- fitzbox IP
const int FRITZBOX_PORT = 49000;
TR064 tr064_connection(FRITZBOX_PORT, FRITZBOX_IP, USER, PASSWORD);
// Instantiate a Bounce object
Bounce debouncer = Bounce();
//Google
GoogleHomeNotifier ghn;
void connectToGH() {
Serial.println("connecting to Google Home...");
if (ghn.device(GoogleHomeName, "de") != true) {
Serial.println(ghn.getLastError());
TRACE();
return;
}
Serial.print("found Google Home(");
Serial.print(ghn.getIPAddress());
Serial.print(":");
Serial.print(ghn.getPort());
Serial.println(")");
}
//**********************************************************************
void setup() {
Serial.begin(115200);
pinMode(taster, INPUT);
pinMode(rot, OUTPUT);
pinMode(gruen, OUTPUT);
// After setting up the button, setup the Bounce instance :
debouncer.attach(taster);
debouncer.interval(100); // interval in ms
//connect to your local wi-fi network
WiFi.hostname(DEVICE_NAME);
WiFi.begin(ssid, password);
WiFi.config(local_ip, gateway, subnet, DNS);
//check wi-fi is connected to wi-fi network
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected..!");
Serial.print("Got IP: "); Serial.println(WiFi.localIP());
Serial.println("Connecting to ");
Serial.println(ssid);
Serial.println("Connect to Google");
connectToGH();
ghn.notify("Microcontroller gestartet!");
Serial.println("Initialize TR-064 connection");
tr064_connection.init();
}
//*************************************************************************************
void loop() {
// Update the Bounce instance :
debouncer.update();
// Get the updated value :
tasterstatus = debouncer.read();
if ( debouncer.fell() )
{
if (taster_counter<2)
{
digitalWrite(rot, HIGH);
digitalWrite(gruen, LOW);
taster_counter++;
ghn.notify("Hey, es klingelt jemand an der Tür!");
}
else
{ digitalWrite(rot, LOW);
digitalWrite(gruen, HIGH);
taster_counter=0;
Serial.println("Fritzbox call");
Serial.println("taster_counter");
String tr064_service = "urn:dslforum-org:service:X_VoIP:1";
Serial.println("Call **621");
// Telephone number **621 vor calling phones
String call_params[][2] = {{"NewX_AVM-DE_PhoneNumber", "**621"}};
tr064_connection.action(tr064_service, "X_AVM-DE_DialNumber", call_params, 1);
// Wait 4 seconds until hang up
// 16000 ~ 4x ring bell
delay(4000);
tr064_connection.action(tr064_service, "X_AVM-DE_DialHangup"); //hier: [action]<error> nonce/realm request not successful!
Serial.println("Dial Hangup");
delay (5000);
}
}
}