-
Notifications
You must be signed in to change notification settings - Fork 70
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
My MQTT Broker disconnects often. #33
Comments
Are your clients connected from via the AP interface or via the STA. The broker has to disconnect all clients when the uplink connection of the STA is (temporarily) lost. |
Hello Martin! My clients and broker are both connected to my home router AP. |
Then I am pretty sure that you have a temporary disconnect of the ESP from the router AP - you should be able to see that on the serial console. To verify that you might also run a script on the broker that does some action "on wifidisconnect", e.g. increase a counter variable. You than can log into the broker and look into "show vars" to see the value of the counter. How to fix that?
|
Ok Martin, Thank you for the advice. I will look into it. Update you when something comes up. |
Off topic Martin, I am using netcat for windows to upload script to the esp, Why is it that it would take about 5mins to upload the script regardless of the size of my script? |
Can you help me understand this log: Waiting for script upload on port 2000 load 0x40100000, len 31244, room 16 connected with Balay24, channel 1 |
Martin, what is wrong with this snippet? % When wifi disconnects I got error: Script upload completed (1387 Bytes) |
So you have the latest version. Added wifidisconnect recently.
Am 1. März 2018 6:23:07 nachm. schrieb jnherm <[email protected]>:
… Martin, what is wrong with this snippet?
**********************************************************
% When wifi disconnects
on wifidisconnect
do
println "Wifi Disconnected"
setvar $wifiDisc = @3 + 1
setvar @3 = $wifiDisc
println "Wifi Disconnected : " | $wifiDisc | " times"
% When wifi connected
on wificonnect
do
println "Wifi Connected"
setvar $wifiCon = @4 + 1
setvar @4 = $wifiCon
println "Wifi Connected : " | $wifiCon | " times"
*****************************************************************
I got error:
Script upload completed (1387 Bytes)
Error ('init', 'mqttconnect', 'topic', 'gpio_interrupt', 'serial', 'alarm',
'htt
p_response', or 'timer' expected) at >>do =
--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
#33 (comment)
|
Just tested it: the script is fine with the lastest build. No, it is not normal, that it takes 5 min - should work immediately. However, never tested it with Windows. What netcat do you use? Some sort of connection problems? Your trace is obviously a reboot. This happened while loading a script? If so, are you able to reproduce it with the same script? If so, I would be interested in this script! |
hello Martin, Thanks for your help. I just upgraded my firmware and it work. I can now monitor my wifi connection. But one thing I observe is "on wifidisconnect" will execute everytime the esp tried to connect to my router. That is if my router is off, the counter keep on increasing even though it was previously disconnected. Regarding my netcat version for windows, I just downloaded if from github, by Diego Casorran. This is my Final Script that I used: % Config params, overwrite any previous settings from the commandline
% The local pushbutton
% When wifi disconnects % When wifi connected |
Can you suggest netcat version for windows? Or any method that will be easier for my to upload script? |
You could try this local web server ( http://fenixwebserver.com/ ) on your windows machine and use the "pull"-mode. |
Hello Martin! It doesn't seems to work from my end. I tried to use fenix webserver but when I "pull" the script from fenix webserver to my sonoff device via serial this is what happend: HTTP request to http://127.0.0.1:81/sonoffScript2.txt started Then nothing happens(i waited for 5 to 10mins), but when I press enter, this is the message: HTTP script upload failed (error code -1). I also tried "pull" request via internet. I uploaded my script to my google drive and get the link. But again this shows: client handshake start. After that, I waited but nothing happens. The when I press enter key, this is the message: HTTP script upload failed (error code 302) |
Hello Martin, I downloaded Android App webserver and it work great. Just after the request, ,my script were downloaded to esp device. |
Good to read! BTW: I guest 127.0.0.1 was the wrong address for the fenix - this is "localhost" you will need the actual IP of your PC in the local net. |
127.0.0.1 was the host ip given by fenix... I tried also localhost, but to no avail. I tried to use my browser and the text were displayed when I use 127.0.0.1. |
I am currently running a setup where also the MQTT connection to the uMQTTBroker is interrupted and than immediatly reestablished by the clients. At least the wireshark trace tells me, that the CLIENTs (using tuampmt's original lib) actively disconnect, not the broker. Up to know I don't know why... |
I also observe the number of disconnections on my setup but I noticed that even the esp MQTT broker did not disconnect from my router, the clients tried to reconnect, at least based on the log of the clients. By the way I am using itead sonoff devices with Tasmota firmware. I also posted an issue on tasmota but unfortunately no one is responding positively to my issue. So, I think your broker is stable. Even if it sometimes disconnect from the router, it will alway reconnects. |
Martin, sorry to bother you again. I observe that when I reconnect my sonoff to your MQTT broker, after subscriptions of topic, your MQTT broker will try to publish(maybe test publish) the topic just subscribed. Is my observation correct? Other MQTT broker I used won't do so. Is it possible that you could have a setting for that so that user can choose if they want to test the subscribed topic or not. |
This is not an intended test publication. I would guess, it is a 'retained'
topic (a flag in publication), e.g. one that has to be stored by the
broker. Could you check this by looking into the output of 'show mqtt'. It
shows all retained topics.
Am 6. März 2018 6:28:39 vorm. schrieb jnherm <[email protected]>:
… Martin, sorry to bother you again. I observe that when I reconnect my
sonoff to your MQTT broker, after subscriptions of topic, your MQTT broker
will try to publish(maybe test publish) the topic just subscribed. Is my
observation correct? Other MQTT broker I used won't do so. Is it possible
that you could have a setting for that so that user can choose if they want
to test the subscribed topic or not.
--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
#33 (comment)
|
Yes there are subscriptions that are 'retained', but the same subscriptions did not cause the other MQTT broker that I am using to send a published MQTT command to my devicce. On the other hand, your broker will to send those subscribed command to my devices after re-connection. |
I think, this behavior is exactly conforming to the specs:
What is your reference broker? Mosquitto? |
Furthermore, if it is due to 'retained' subscriptions, your broker should send the last published topic's payload, for which my device will get a payload that is the same with previous relay state. But in my case, my devices will get a consistent payload. Client A lost MQTT connection with Broker ESP: (Client Relay is ON) Note that if previous client A's relay state is OFF before re-connection, relay will remain OFF since Payload is OFF. |
Don`t understand why the last state that is send after resubscription should be OFF? When it lost connection when switched ON, the retained state should be ON? It's not? |
I am using this Android App as a broker. I don't know if it is Mosquitto. https://play.google.com/store/apps/details?id=server.com.mqtt |
I have a guess: is it possible that you have a restart of the broker? Then this could make sense: if the retained state is saved in flash, it will be constant after restart. This would also explain the connection loss. What kind of ESP are you using? What about power supply? |
I really prefer your ESP broker because it is the most economical for a small/lightweight application like controlling a room. |
I am using ITEAD's sonoff basic as ESP broker. Power supply is SMPS inside sonoff basic connected directly to mains. |
"Don Yes you are right, It should be ON. I have other scenarios which toggle my relay, no matter what is my previous relay state. Maybe ESP broker saved "toggle" payload |
I simulate lost connection by turning Off then ON the ESP broker. |
Okay, then the behavior is clear: you have a saved state in flash: OFF. If you reset the broker (on/off), it will restart with this state from flash.
|
Thank you Martin. |
Good news Martin. With autoretain set to 1 my problem solved! Thank you again! |
Does anybody experience in your broker always disconnects all clients? All my clients were all disconnected sometimes.
The text was updated successfully, but these errors were encountered: