fredlcore / BSB-LAN

LAN/WiFi interface for Boiler-System-Bus (BSB) and Local Process Bus (LPB) and Punkt-zu-Punkt Schnittstelle (PPS) with a Siemens® controller used by Elco®, Brötje® and similar heating systems
225 stars 84 forks source link

Don't hang on MQTT connection attempt #639

Closed jbaudoux closed 6 months ago

jbaudoux commented 6 months ago

Relates to https://github.com/fredlcore/BSB-LAN/issues/638

Before

Hanging for 3 * 1s

Connected to MQTT broker, updating will topic
Subscribed to topic 'BSB2'
Published status 'online' to topic 'BSB2/status'
[ 38796][D][WiFiClient.cpp:536] connected(): Disconnected: RES: 0, ERR: 128
Client ID: BSB-LAN2
Will topic: BSB2/status
[ 38797][E][WiFiGeneric.cpp:1584] hostByName(): DNS Failed for 
Failed to connect to MQTT broker, retrying...
[ 39801][E][WiFiGeneric.cpp:1584] hostByName(): DNS Failed for 
Failed to connect to MQTT broker, retrying...
[ 40801][E][WiFiGeneric.cpp:1584] hostByName(): DNS Failed for 
Failed to connect to MQTT broker, retrying...
Client ID: BSB-LAN2
Will topic: BSB2/status
Connect to MQTT broker, updating will topic

After

Connected to MQTT broker, updating will topic
Subscribed to topic 'BSB2'
Published status 'online' to topic 'BSB2/status'
[ 41887][D][WiFiClient.cpp:536] connected(): Disconnected: RES: 0, ERR: 128
MQTT connection lost
Client ID: BSB-LAN2
Will topic: BSB2/status
Connected to MQTT broker, updating will topic
fredlcore commented 6 months ago

Thanks!

fredlcore commented 6 months ago

I just tried it with my setup here, and if the broker is not reachable, I get this:

00:58:49.481 > Will topic: BSB-LAN/status
00:58:49.496 > [ 38299][E][WiFiClient.cpp:275] connect(): socket error on fd 50, errno: 104, "Connection reset by peer"
00:58:49.504 > Failed to connect to MQTT broker, retrying...
00:58:49.507 > Client ID: BSB-LAN
00:58:49.510 > Will topic: BSB-LAN/status
00:58:49.537 > [ 38340][E][WiFiClient.cpp:275] connect(): socket error on fd 50, errno: 104, "Connection reset by peer"
00:58:49.545 > Failed to connect to MQTT broker, retrying...
00:58:49.548 > Client ID: BSB-LAN
00:58:49.551 > Will topic: BSB-LAN/status
00:58:49.568 > [ 38372][E][WiFiClient.cpp:275] connect(): socket error on fd 50, errno: 104, "Connection reset by peer"
00:58:49.576 > Failed to connect to MQTT broker, retrying...
00:58:49.579 > Client ID: BSB-LAN
00:58:49.582 > Will topic: BSB-LAN/status
00:58:49.598 > [ 38402][E][WiFiClient.cpp:275] connect(): socket error on fd 50, errno: 104, "Connection reset by peer"
00:58:49.606 > Failed to connect to MQTT broker, retrying...
00:58:49.609 > Client ID: BSB-LAN
00:58:49.612 > Will topic: BSB-LAN/status
00:58:49.628 > [ 38431][E][WiFiClient.cpp:275] connect(): socket error on fd 50, errno: 104, "Connection reset by peer"
00:58:49.636 > Failed to connect to MQTT broker, retrying...
00:58:49.639 > Client ID: BSB-LAN
00:58:49.641 > Will topic: BSB-LAN/status
00:58:49.661 > [ 38464][E][WiFiClient.cpp:275] connect(): socket error on fd 50, errno: 104, "Connection reset by peer"
00:58:49.669 > Failed to connect to MQTT broker, retrying...
00:58:49.672 > Client ID: BSB-LAN
00:58:49.674 > Will topic: BSB-LAN/status
00:58:49.690 > [ 38493][E][WiFiClient.cpp:275] connect(): socket error on fd 50, errno: 104, "Connection reset by peer"
00:58:49.698 > Failed to connect to MQTT broker, retrying...
00:58:49.701 > Client ID: BSB-LAN
00:58:49.704 > Will topic: BSB-LAN/status
00:58:49.717 > [ 38520][E][WiFiClient.cpp:275] connect(): socket error on fd 50, errno: 104, "Connection reset by peer"
00:58:49.725 > Failed to connect to MQTT broker, retrying...
00:58:49.728 > Client ID: BSB-LAN
00:58:49.730 > Will topic: BSB-LAN/status
00:58:49.752 > [ 38555][E][WiFiClient.cpp:275] connect(): socket error on fd 50, errno: 104, "Connection reset by peer"
00:58:49.760 > Failed to connect to MQTT broker, retrying...
00:58:49.763 > Client ID: BSB-LAN
00:58:49.766 > Will topic: BSB-LAN/status
00:58:49.777 > [ 38580][E][WiFiClient.cpp:275] connect(): socket error on fd 50, errno: 104, "Connection reset by peer"
00:58:49.785 > Failed to connect to MQTT broker, retrying...
00:58:49.788 > Client ID: BSB-LAN
00:58:49.790 > Will topic: BSB-LAN/status
00:58:49.803 > [ 38606][E][WiFiClient.cpp:275] connect(): socket error on fd 50, errno: 104, "Connection reset by peer"
00:58:49.811 > Failed to connect to MQTT broker, retrying...
00:58:49.814 > Client ID: BSB-LAN
00:58:49.816 > Will topic: BSB-LAN/status
00:58:49.830 > [ 38633][E][WiFiClient.cpp:275] connect(): socket error on fd 50, errno: 104, "Connection reset by peer"
00:58:49.838 > Failed to connect to MQTT broker, retrying...
00:58:49.841 > Client ID: BSB-LAN
00:58:49.844 > Will topic: BSB-LAN/status
00:58:49.862 > [ 38666][E][WiFiClient.cpp:275] connect(): socket error on fd 50, errno: 104, "Connection reset by peer"
00:58:49.871 > Failed to connect to MQTT broker, retrying...
00:58:49.873 > Client ID: BSB-LAN
00:58:49.876 > Will topic: BSB-LAN/status
00:58:49.889 > [ 38693][E][WiFiClient.cpp:275] connect(): socket error on fd 50, errno: 104, "Connection reset by peer"
00:58:49.897 > Failed to connect to MQTT broker, retrying...
00:58:49.900 > Client ID: BSB-LAN
00:58:49.903 > Will topic: BSB-LAN/status
00:58:49.918 > [ 38721][E][WiFiClient.cpp:275] connect(): socket error on fd 50, errno: 104, "Connection reset by peer"
00:58:49.926 > Failed to connect to MQTT broker, retrying...
00:58:49.929 > Client ID: BSB-LAN

So it's constantly trying to reconnect. Any idea why this is the case?

fredlcore commented 6 months ago

Ok, after half an hour testing and searching I realized that you forgot to set mqtt_reconnect_timer to the actual value if the connection fails (e.g. due to an unavailable broker). I wonder how this could not have occurred during your testings :(...