Hi,
I build a TR064 custom component some years ago. When pressing the door bell button, an ESP8266 catches the power signal of the door bell button and creates a TR064 call to my FritzBox, so that the DECT phone is ringing.
Due to some personal reasons, I didn’t update the ESPHome platform for a long time. But now I started doing that, and I found, that the door bell custom component is working fine with ESPHome v2024.3, but sind ESPHome v2024.4 it is not working anymore, also with newer ESPHome versions. The TR064 Library requires ESP8266HTTPClient and ESP8266Wifi. As far as I did into the code the problem comes somewhere from the WifiClient object used by TR064. When trying to send data, the connection is not valid and the code crashes.
I already compared the tr064.cpp, tr064.h, ESP8266HTTPClient.cpp, ESP8266HTTPClient.h, ESP8266WiFi.cpp and ESP8266WiFi.h files used by ESPHome 2024.3 versus v2024.4 and found that there are some changes for ESP8266HTTPClient and ESP8266WiFi files, while the library.properties files of the libraries are showing the same library versions
Currently I still do not understand the difference and why the problem raises from 2024.3 to 2024.4. That is why I raise this post for getting fresh ideas.
By the way: I already started to convert the custom component to an external component, but this didn’t solve the problem. And because the code is much simpler, stayed with the custom component code for analysing the issue.
Here is the code I’m using for the analysis:
z-tuerklingel-2024-3.yaml
esphome:
name: "z-tuerklingel-2024-3"
friendly_name: z_Türklingel_2024.3
area: Türklingel
libraries:
- "ESP8266WiFi"
- "ESP8266HTTPClient"
# - "TR-064 SOAP Library" # (1) we do not need that library, because of a bug in tr064 library
includes:
- tuerklingel_2024.3/include/tuerklingel.h
- tuerklingel_2024.3/include/tr064.h # (2) we need that local copy, because of a bug in tr064 library
- tuerklingel_2024.3/include/tr064.cpp # (2) we need that local copy, because of a bug in tr064 library
esp8266:
board: d1_mini
# Enable logging
logger:
level: debug
# Enable Home Assistant API
api:
#password: ""
encryption:
key: !secret key_tuerklingel
ota:
password: !secret ota_password
safe_mode: false
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
domain: .fritz.box
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: !secret ap_ssid_tuerklingel
password: !secret ap_password
captive_portal:
binary_sensor:
# Klingelknopf
- platform: gpio
id: z_sensor_doorBell_2024_3
name: "Status Türklingel"
device_class: sound
pin:
number: GPIO0
mode:
input: true
pullup: true
inverted: true
filters:
- delayed_off: 100ms
on_press:
then:
- logger.log: "Türklingel betätigt"
- script.execute: z_ring_phones_script_2024_3
# Status ob der Rundruf läuft
- platform: template
id: z_sensor_telephonesRinging_2024_3
name: "Status Rundruf"
lambda: |-
if ((id(z_is_ringing_2024_3) == true)) {
return true;
} else {
return false;
}
button:
# Viruteller Klingelknopf
- platform: template
name: "Klingeln"
id: z_ring_doorBell_2024_3
on_press:
then:
- logger.log: "Virtuelle Türklingel betätigt"
- script.execute: z_ring_phones_script_2024_3
output:
# Triggert das TR064 Protocoll
- platform: custom
type: binary
lambda: |-
auto tuerklingel = new Tuerklingel();
App.register_component(tuerklingel);
return {tuerklingel};
outputs:
id: z_custom_binary_2024_3
globals:
# Variable die den Zustand ob die Telefone klingeln speichert
- id: z_is_ringing_2024_3
type: bool
restore_value: no
initial_value: 'false'
script:
# Skript zum Klingeln lassen der Telefone
- id: z_ring_phones_script_2024_3
mode: restart
then:
- lambda: |-
if ((id(z_is_ringing_2024_3) == true)) {
id(z_custom_binary_2024_3).turn_off();
id(z_is_ringing_2024_3) = false;
}
- lambda: 'id(z_is_ringing_2024_3) = true;'
- output.turn_on: z_custom_binary_2024_3
- delay: 5s
- output.turn_off: z_custom_binary_2024_3
- lambda: 'id(z_is_ringing_2024_3) = false;'
And here is the custom cpp code im using:
tuerklingel.h
#include "esphome.h"
#include <tr064.h> // (1) changed because of local library bugfix
//#include "tr064.h" // (2) changed because of local library bugfix
#include "esphome/core/log.h"
using namespace esphome;
class Tuerklingel : public Component, public BinaryOutput {
public:
Tuerklingel()
: Component(),
BinaryOutput(),
connection(PORT, IP, fuser, fpass)
{ }
void write_state(bool state) override {
if(state) {
callWahlhilfe();
} else {
hangup();
}
}
private:
void callWahlhilfe() {
/*
if(connection.state() < 0) {
connection.init();
}
*/
String params[][2] = {{"NewX_AVM-DE_PhoneNumber", "**611"}};
String req[][2] = {{""}};
//connection.action("X_VoIP:1", "X_AVM-DE_DialNumber", params, 1, req, 0);
//connection.action("urn:dslforum-org:service:X_VoIP:1", "X_AVM-DE_DialNumber", params, 1, req, 0);
// without loading available services through init() you have to set the url
connection.action("X_VoIP:1", "X_AVM-DE_DialNumber", params, 1, req, 0, "/upnp/control/x_voip");
}
void hangup() {
/*
if(connection.state() < 0) {
connection.init();
}
*/
String params[][2] = {{}};
String req[][2] = {{}};
//connection.action("X_VoIP:1", "X_AVM-DE_DialHangup", params, 0, req, 0);
//connection.action("urn:dslforum-org:service:X_VoIP:1", "X_AVM-DE_DialHangup", params, 0, req, 0);
// without loading available services through init() you have to set the url
connection.action("X_VoIP:1","X_AVM-DE_DialHangup", params, 0, req, 0, "/upnp/control/x_voip");
}
//The username and password you created for login (Anmeldung aus dem Heimnetz mit Benutzername und Passwort)
const char* fuser = "fritzbox_user;
const char* fpass = "securePassword";
//IP address of your router. This should be "192.168.178.1" for most FRITZ!Boxes
const char* IP = "192.168.178.1";
//Port of the API of your router. This should be 49000 for all TR-064 devices.
const int PORT = 49000;
//TR-064 connection
TR064 connection;//(PORT, IP, fuser, fpass);
};
As you can see, I’m not using the TR064 Library that ESPHome would download, but custom files. These custom files are a copy of the default TR064 library, but containing a simple small fix. Otherwise sending the call to the FritzBox could take several seconds to start. HEre ist the simple fix I use:
tr064.cpp
bool TR064::xmlTakeParam(String (*params)[2], int nParam) {
WiFiClient * stream = &tr064client;
stream->setTimeout(10); // <------ Bugfix, this line was added to the original code
while(stream->connected()) {
...
Are there any ideas outside, why the code stops working when using newer ESPHome versions (since v2024.4)?