-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lag when MQTT Server is down (possible workaround) #1992
Comments
Hello, no offend |
Hi, no offend taken. I just post an idea to be discussed ;) May be I wasn't clear. I'm not saying of taking out MQTT from tasmota. No. That's not the idea. You are right. Will be useless that. What I'm saying is changing the MQTT library from pubsubclient to esp-mqtt-arduino. Just using another library for MQTT on Tasmota Firmware. The actual library (pubsubclient) is a generic MQTT library to be used for any Arduino compatible device. So it is NOT optimized for ESP8266. However, esp-mqtt-arduino library is a MQTT library optimized for ESP8266. So, I tested both libraries and pubsubclient has a 5 second lag when there is not a MQTT server active while the other has not that bug and remains fast responsive. When I say MQTT Server Down I meant the case where you are using the MQTT feature and because a Wifi disconnection or a problem in a MQTT server, a Sonoff disconnects from the server. Using pubsubclient, Tasmota gets unresponsive for 5 seconds each 10 seconds. With the other library, this bug should be resolved. So, @arendst, What do you think about changing the library from pubsubclient to esp-mqtt-arduino? |
I'll take a look at it. |
This sounds really nice! WAF is very low when the wall switches are not working because the WIFI is acting up.. |
UPDATE: Installed patched esp-mqtt-arduino as the original does not support LWT like Tasmota does and I want it to be compatible with PubSubClient. It adds 5k to the code base while using the same amount of ram so that's fine. It does not support TLS using WifiClientSecure as PubSubClient does so it is only a replacement for non-TLS configurations. Blocking is indeed gone so that's positive. I also tried ESP8266MQTTClient but that only seems to support TLS which is very code hungry: +52k code and exceptions everywhere. So that's no way to go. I'll tune/rewrite/strip the current esp-mqtt-arduino library and will release a TasmotaMQTT library being a wrapper around slightly modified TuanPmt code and to be used on non-TLS sytems. TO BE CONTINUED. |
5.12.0d * Add support for optional MQTT drivers to be selected in user_config.h (#1992)
Work really well !!! Thanks 👍 @arendst please put the TasmotaMQTT as default option. Works really good. |
Issue solved. Closing... |
@ascillato Update: Nevermind, I found it in user config.h
|
great!!! 👍 |
5.12.0d * Add support for optional MQTT drivers to be selected in user_config.h (arendst#1992)
Use the last Tasmota version without modifications. It doesn't have any lag. The lags were solved with newer Pubsubclient versions already available in libs folder. If you try the precompiled bins (http://thehackbox.org/tasmota/) you will not have any issue. If you compile by yourself, update Tasmota to last (v6.3.0.7 is now) and also update all the libraries (delete the previous you have first) TasmotaMQTT is deprecated and has some restart with exception issues. Not recommended. The new Pubsubclient works fine. (BTW you were writing in a very old closed issue) |
Thank you for quick help. Downloaded the newest v6.3.0 precompiled software from https://github.com/arendst/Sonoff-Tasmota/releases. Did an OTA update from the web-interface and tested it. |
Seems that you are having another issue. Did you check the console output? may be your device is rebooting due to a problem, not lagging |
To discard other issues, please, upgrade to last version 6.3.0.7 (http://thehackbox.org/tasmota/) that have several improvements on performance. |
Also, if you can, please try to erase all before flash. If after all that, you still experience the lag, Please, open a new issue but with the troubleshooting template completed and the output of your console. Thanks |
Precompiled 6.6.0 version still having lag with mqtt server down. |
@khriss75 I eventually fixed the problem. I think MQTT_TASMOTAMQTT helps, but make sure to erase all flash before updating. |
Thanks Kepete, I'm searcing to define MQTT_TASMOTAMQTT in "my user config" tab but I can't find the mqtt_tasmota line #define |
MQTT_TASMOTAMQTT is not used anymore.... |
Thanks Janson2866 for your replay, but I'm still having issue! As described I downloaded latest version (6.6.0) PRECOMPILED using on ESP8266. If I switch off my mqtt server I have a lag for about 3-4 seconds every time retry mqtt connection. During mqtt connection my buttons/relays don't react. I can provide a video of this issue. Tasmota 6.6.0 precompiled + NODEMCU. |
Mhh, why does you mqtt server goes offline? Yes i know bad things can happen, but normally it should run. And for the times it doesnt run you have some side effects |
Mhh, imagine a door sensor (magnetic switch), and siren. Mqtt connected: If someone open and close the door siren start and send mqtt to my smartphone. |
Hi, will investigate your issue. |
Thank you so much Adrian. If you need some other info ask to me. I can provide a video. |
Using Tasmota from today (6.6.0.6): The lag CAN NOT be reproduced on Core 2.3.0 So, bad news. Confirmed Issue and core related. @khriss75 Please, use Tasmota precompiled bins with core 2.3.0 (like http://thehackbox.org/tasmota/020300/sonoff.bin) to avoid this issue until a solution could be found for the core. For core 2.3.0, 2.4.2, 2.5.2 there is no lag issue. The issue seems to be inside the new ArduinoESP8266 WIFICLIENT Library. Will report to Arduino Esp8266 devs. Thanks for reporting. |
The wificlient library from Arduino didn't change from 2.5.2 to STAGE. It is the same. So, it is something in the SDK ? |
With core pre2.6 and feature/stage nonos-sdk 22y is standard and different to all other core builds |
As your suggestion, tested SDK 22x and the lags is there in core STAGE. So, it is not SDK related due sdk22y and sdk22x are used in core 2.5.2 too and with that core there is no lag. So, the issue seems to be inside the core stage or in the way that pubsubclient-espeasy uses wificlient. In the precompiled bins (core 2.3.0, 2.4.2 and 2.5.2) I could not reproduce any lag. |
Hi, I have just found the issue in the Arduino core that produces this 5 seconds hung when the MQTT broker goes down. The issue appears with this PR: esp8266/Arduino#6213 I have just proposed the PR: esp8266/Arduino#6440 in order to fix this hung. |
@ascillato , I'm still having problem with the precompiled core 2.3.0 linked. I erased my nodemcu and flashed the linked .bin but the lag persist. |
Other info: |
Cant reproduce the lag in my setup. |
Jason, thanks for interesting! Just to test as my configuration:Generic Module. D6 Relay1 Setoption13 1As you can see from console, at mqtt connection tentative there are about 5 seconds: Can you send me a link of version without issue (You have tested)? |
You have a general problem in your wifi / mqtt setup. |
Fix is already merged into Arduino Core STAGE. esp8266/Arduino#6454 |
If anyone is having any blocking or lag, please open a new issue with the troubleshooting template complete or address it to the Tasmota Support Chat. Thanks. |
Hi
It is a known Tasmota issue (Wiki) that when a Sonoff try to connect to a MQTT server that is DOWN (IP and Port, both down), the pubsubclient library hangs for 5 second on each reconnection attempt making a Sonoff unresponsive.
So, looking for a work around for this, found this other MQTT Library (https://github.com/i-n-g-o/esp-mqtt-arduino). I tested on ESP8266 and with Home Assistant, and it has no lag when losing connection to MQTT Server. It has a different approach for conecting to an MQTT Server that is not using the wificlient library like pubsubclient.
What about changing the library so as to make Tasmota faster?
The text was updated successfully, but these errors were encountered: