Build your own smart doorbell with the ESP8266 and Fritz! Box  

Build your own smart doorbell with the ESP8266 and Fritz! Box

Sometimes it’s difficult to hear the doorbell at home when you’re in the garden, have headphones on or are playing loud music. Wouldn’t it be useful to have a simple, portable solution that integrates with the technology you already own at home?

The Project

Suitable for: Advanced

Time required: approx. 2 hours

What you need: NodeMCU ESP8266 Wi-Fi moduleoptocoupler, rectifier dioderesistor 560 Ohmbreadboardbuilt-in coupling for testing/simulating the bell

Budget: approx. £15

The Component

In this how-to we show you how to use the ESP8266 microcontroller and a Fritz! Box to turn a DECT handset into a mobile doorbell.

The special features of the ESP8266 make it the perfect component for this project. It has WiFi capabilities, consumes less than one mW in deep-sleep mode and is easy to program.

There’s also a broad developer community that provides good tool support and resources. The developer module we’ve used is programmable via a commercially available micro USB cable, which simultaneously serves as the power supply during development.

Those who want the bell circuit to be particularly handy, can fall back on particularly compact modules such as the ESP-12F (DEBO ESP8266-12F). For this you need a USB-TTL-UART converter.

For programming we’ve used Arduino IDE.

The Electronics

The Test Circuit

To create the circuit, you only need a small amount of wire besides the ESP. To simulate the ringing, you simply connect the Reset (RST) and Ground (GND) of the ESP.

The Bell Circuit

Only a few components are required for use with the real doorbell: an optocoupler separates the circuits of the bell transformer and the ESP. If the optocoupler receives power, then the reset (RST) and ground (GND) of the ESP are connected. The microcontroller wakes up from the deep-sleep state and starts the ringer program.

circuit diagram

Conventional ring transformers supply an alternating voltage between eight and 24 V. The resistor (R1) ensures that the optocoupler receives a voltage of 1.2 V and must therefore be tuned to the ringing voltage. The diode ensures that the alternating voltage of the bell DC voltage pulses for the optocoupler. Incidentally, as long as the program is running, it does not matter if the reset is triggered several times.

For a power supply with batteries (3-3.6 V), the battery holder must be connected to the pins 3V and GND.

R1 values for usual ringing voltages:

Fritz! Prepare the box

In order for the microcontroller to communicate with the Fritz! Box, it needs access via the TR-064 protocol. The correct setting must be selected in the administration menu of the Fritz! Box (http // fritz.box) under “Home” → “Home Network Overview” → “Network Settings” the check mark “Allow access for applications”.

The Software

Arduino IDE setting

Programming of the ESP8266 takes place on the developer board via a USB, which also serves as power supply during development.

We‘ve used Arduino IDE to compile the software and program the microcontroller.

  1. By default, only Arduino family boards are available in the Arduino IDE. The ESP8266 developers provide corresponding board configurations for this. In the settings of the Arduino IDE (“File” -> “Change preferences”) enter the URL for ESP8266 boards in the field “Additional Board Administrator URLs”: http://arduino.esp8266.com/stable/package_esp8266com_index.json
  2. Install the board configuration with appropriate tooling via the “Board Manager” (“Tools” -> “Board: Arduino / Genuino Uno” -> “Board Administrator”). Simply specify ESP8266 as the target directory and select the latest version. The download is about 150 MB because its own compilers, libraries and tools for ESP8266 systems are needed.

After completing the installation, ESP8266 boards can also be selected, in this case “NodeMCU 1.0 (ESP-12E modules)”.

The complete documentation can be found at: https://arduino-esp8266.readthedocs.io/en/2.4.2/ 

Installation of the TR-064 library

Communication with the Fritz! Box takes place via the TR-064 protocol. A corresponding library can be found at: https://github.com/Aypac/Arduino-TR-064-SOAP-Library

To install, simply move the “TR-064-SOAP-Library” folder to the directory for Arduino libraries in the home directory (Arduino / libraries on Linux or Documents / Arduino / libraries on Windows).

The Program

With this short program, the ESP8266 board will call each connected phone for four seconds when the bell rings and then enter the deep sleep mode again:

#include <Arduino.h>
#include <ESP8266WiFi.h>

#include <ESP8266HTTPClient.h>

#include <tr064.h>

 

const char WIFI_SSID[] = “WLANNAME(SSID)”;   // <– ändern

const char WIFI_PASSWORD[] = “WLANPASSWORT”; // <– ändern

const char USER[] = “admin”;

const char PASSWORD[] = “PASSWORT”; // <– ändern

const char FRITZBOX_IP[] = “192.168.178.1”;

const int FRITZBOX_PORT = 49000;

 

TR064 tr064_connection(FRITZBOX_PORT, FRITZBOX_IP, USER, PASSWORD);

 

const IPAddress STATIC_IP(192, 168, 178, 230);

const IPAddress GATEWAY(192, 168, 178, 1);

const IPAddress SUBNET(255, 255, 255, 0);

const IPAddress DNS(GATEWAY);

 

const char DEVICE_NAME[] = “ESP-Klingel”;

 

void setup() {

WiFi.hostname(DEVICE_NAME);

WiFi.config(STATIC_IP, SUBNET, GATEWAY, DNS);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

WiFi.mode(WIFI_STA);

 

while (WiFi.status() != WL_CONNECTED) {

delay(50);

}

 

tr064_connection.init();

 

String tr064_service = “urn:dslforum-org:service:X_VoIP:1”;

 

// Die Telefonnummer **9 ist der Fritzbox-Rundruf.

String call_params[][2] = {{“NewX_AVM-DE_PhoneNumber”, “**9”}};

tr064_connection.action(tr064_service, “X_AVM-DE_DialNumber”, call_params, 1);

 

// Warte vier Sekunden bis zum auflegen

delay(4000);

tr064_connection.action(tr064_service, “X_AVM-DE_DialHangup”);

 

ESP.deepSleep(0);

}

 

void loop() {}

First, the necessary parameters need to be defined so that the ESP8266 can connect to the network and call the TR-064 interface. You will need to log in with your username and password for the Fritz! Box to authenitcate the TR-064 interface (the user name is ex factory “admin”). It also creates an instance of the TR-064 API client.

So that the microcontroller can spend most of its time in the energy-saving deep-sleep mode, it logs on to the network each time it is called. In order to keep the reaction time between the operation of the bell and the call on the phones short, use a fixed IP address and refrain from a slower dynamic allocation via DHCP.

Experienced Arduino developers will immediately notice that the entire program logic is in setup () and not in loop (). This is due to the way the ESP8266 works, which shuts down all components except the Real Time Clock, including the CPU, in deep sleep mode. Thus, loop () can not be executed in this state. setup () is executed each time the microcontroller wakes up.

The WiFi connection is made first, then the connection to the TR-064 interface. This is a first call on all connected handsets, after four seconds we hang up again. If you want, you can of course also use the direct dial for a particular handset.

To upload the program, a port must still be selected (even if there is usually only one, under “Tools” → “Port” → “COM3” under Windows or “ttyUSB0” under Linux). Then simply click on the button with the arrow. The program will run for the first time after uploading and the phones will ring briefly. To run the program again, simply short circuit GND and RST on the microcontroller.

Have fun!

 

Cover picture: Adobe Stock, 161405299, terovesalainen

 

Your opinion counts. What do you think about this topic?

Previous voting results loading.
 

Leave a Reply

Your email address will not be published. Required fields are marked *