Constant MQTT devices disconnections (socket error)

http://thehackbox.org/tasmota/release/020300/

Upgrade minimal, then the normal release and your problems should be gone.

1 Like

Hello sir. Could you please elaborate your suggestion? Iā€™ve stated that I was using version 6.4.1 with core 2.3 and still having problems. Thanks.

Hoping this gets resolved as I have these same issues.

I have the same problem on some of my sonoff s20 with 6.2.1 and 2_3_0 (and some versions before that). Havent found a solution yet.
The webserver of the tasmota is not available until i reboot my raspberry or reconnect the switch.

Those are not even relatedā€¦ Tasmota/Sonoff will work even if the Pi is off so this isnā€™t making sense to me unless you have a WLAN issue with the Pi swamping the networkā€¦

I relented yesterday and compiled 6.4.1.12 with Core 2.3.0 and I have not had any device dropout for 24 hoursā€¦

Those are not even relatedā€¦

iĀ“m sure they are. those constant connection errors seem cause a malfunction on the tasmota device.

btw: iĀ“m using hassbian with a mosquitto server. the problem remains the same.

You could turn off the Pi and still be able to go to the web interface for Tasmota. They are not related in any way.

It is possible the Pi is flooding the network though.

Hello everyone.

Iā€™ve found that the problem is due to wifi instabilities, packet loss.

Iā€™ve managed to ā€œfixā€ the problem by changing a couple of parameters on the Tasmota Firmware ino and changed how long to wait until next MQTT check and keep_alive messages. Compiled and updated the firmware OTA, everything seems to be a lot more stable, no more socket errors on log.

Using firmware 6.3 with core 2.3, pubsubclient mqtt.

Changed these lines on PubSubClient.h file:

// MQTT_KEEPALIVE : keepAlive interval in Seconds
// Keepalive timeout for default MQTT Broker is 10s
#ifndef MQTT_KEEPALIVE
#define MQTT_KEEPALIVE 45
#endif

// MQTT_SOCKET_TIMEOUT: socket timeout interval in Seconds
#ifndef MQTT_SOCKET_TIMEOUT
#define MQTT_SOCKET_TIMEOUT 60
#endif

Here is a default firmware compiled with the above settings: https://mega.nz/#!jQF3xKra!zEx9YInJoyTaOnihdo04oFCn2hNfdYASK9k39n1u2Yw

Hope it helps.

Thanks.

2 Likes

Updated to the following version with your adjustments to PubSubClient.h:

Program Version 6.4.1(sonoff)
Build Date & Time 2019-01-31T22:15:23
Core/SDK Version 2_4_1/2.2.1(cfd48f3)
Uptime 1T23:31:01

also switched from fixed mqtt settings to mqtt discovery and changed the ip adress. i suspect the latter for being the real reason, but no disconnects since nearly 2 days.

iĀ“ve got another problematic device. iĀ“ll check if it helps also.

can you also share your bin file
thank you

I was running 6.4.1 on 8 Sonoffs (S20, touch, basic, T1 2 gang) and had a lot of these socket errors (one more than the other, couldnā€™t really find a pattern).
I tried:

  • changing the IP addresses of my Sonoffs
  • changing the username/password of the MQTT host
  • adding a list of local users in MQTT config for the devices with most errors
  • changing the client name (DVES_xxxx )
  • erase all flash using esptool.py
  • changed sleep settings

Without any result. Uploaded the firmware of @Schneider yesterday, and so far no Socket errors anymore. Will check the next few days. :pray:

1 Like

@stanvv Please make sure your are using core 2.3 previously, too.

I agree. Core 2.3.0 fixed mine as well.

These socket errors were bothering me as well, I decided that reverting to an older core didnā€™t seem like a good fix, that using @Schneiderā€™s fix would be the most beneficial.

I ended up modifying the PubSubClient.h the same wayā€¦ BUTā€¦
After trying to get a STATUS6 message from the switch I noticed that it was still sending a keep alive of 15 seconds!

After a grep search for more keep alive defines, I noticed that sonoff_post.h also had a MQTT_KEEPALIVE 15

After reseting the device and realizing it wasnā€™t in the CFG I rebuilt the firmwares and Iā€™ve had no socket errors since even with a 60 RSSI.

Just for clarification, I did not modify the code in any way, no user settings just changed the keep alive definitions. My configurations are pretty generic on my Sonoff Basic V2ā€™s

1 Like

Schneiderā€™s fix IS using the older 2.3.0 core or didnā€™t you notice that?

1 Like

Bad communication on my part.
I meant I wanted to make it work with 2.4

An update. After two hours it started to do it again. I will compile the 2.3 core version and test it next.

Well, I concede! As described by @Bieniu the Tasmota releases with Core 2.3 with 6.4.1 work perfect

And again verified by eh50

So that seems to be it.

2.4.2 is horrible, 2.5.0 is much better but 2.3.0 is the most stable. All have tradeoffs.

Thanks for the fix! Iā€™m running 2.3//6.4.1 from the hackbox

Iā€™m not really keen on reflashing every device (60+) so i would like to do this by mqtt commands:

The keep alive would be this, as far as i can tell:
MqttRetry 10..32000 = set MQTT connection retry timer in seconds (default = 10 )

But iā€™m having a hard time finding the socket timeout, anyone any idea?