MQTT reconnect help #713
Replies: 15 comments
-
Posted at 2015-12-21 by Ollie I think I need unsubscribe, to clean up, then reconnect |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-12-21 by @gfwilliams Could be... I wonder if you're keeping a reference to the MQTT connection somewhere? Any reference would mean that all the listeners and everything would be kept around, even after the disconnection? You could try |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-12-21 by Ollie @gordon, very likely, and I think the way I've setup my code is not helping me clear and reinstantiate it. I'll have a look at that first before I waste any of your time here. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-12-21 by Ollie Yes. The way I was setup I could destroy the object but then I lost the listeners, so I've moved the whole thing including require, connect and the listener bindings into their own wrapper method which I recall on disconnect event. Appears to be working well with my triggering disconnect, so hopefully works when server triggers it. Thanks for the steer @gordon |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-12-22 by Ollie Almost 24 hours now. Best I had before was about 14, so I'm hoping I can ride out server disconnections now :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-20 by navas hey @ollie would you mind sharing the code how do you do it. I am haveing the same exact problem. Thanks |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-20 by Ollie I think you've got the tinyMQTT module yes? That's the best code I have, although there's a bit of activity in the issues re "keep alive". I've had long running connections with the module, others have too, but I haven't used it a quite a while |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-02-11 by navas @ollie, thanks for fixing the double reconnect and activating the keepalive. Appreciate much! Thanks |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-02-11 by Ollie @navas thanks, but wasn't me. A couple of pull requests have improved it - authors mentioned in the credits. Great to hear it's better though. Still fairly small at 1.45kb too :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-02-11 by navas right, that's what making it special, so that I can run in ESP-01 (1MB) version |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-04-12 by Scargill Hi Ollie I'm somewhat behind you on this having just gotten MQTT working - and discovered the same thing as you - it disconnects, doesn't reconnect and doesn't keep the subscribes. Care to share to save hours of duplicated effort?? Pete. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-04-12 by Ollie @scargill. Hello there! How are you approaching it? Generally, I put a call to connect in the disconnect event handler. Which module are you using? Myself and others have had good success with this cut down module (https://github.com/olliephillips/tinyMQTT). So something like this:
At the time of the espruino to ESP8266 port, there wasn't the room for the full MQTT module, though we now have 1700 jsvars I think some have squeezed it in, but can't save much application code. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-04-12 by Scargill Hi there Ollie That looks good - can't test it - I've put my stuff away for travelling.... that looks good -but - and this is a guess - should that routine now also include any subscribes that you have lost... and if so is there a way to call that routine normally so that we don't duplicate code.. so perhaps that on disconnect could call a routine with the connect and subscribes - and that routine could also be used at startup??? I'm assuming in all of this that the WIFI reconnects automatically? Hopefully early next week I can settle down in my office in Spain and try all of this out. I'm also at a loss as to why the limited space for code - given that the ESP12 has 3 meg spare? I wonder if there are any plans to check for that and expand user space accordingly? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-04-12 by Ollie Re space - I think a part of it is that the port was designed to accommodate the entire ESP8266 family, including the ESP8266-01. You can use that flash, but as a key/val store. Re the module, and subscribe reconnection. It's been a while since I've used, but I seem to think subscriptions resume or at least aren't cancelled by the disconnection, but don't hold me to that. Please feedback how you get on. BTW the Espruino Gitter channel might be useful. There are people in there who know more about the ESP8266 port than I, so could advise what might be possible on the space front, there's also one user of ESP8266/tinyMQTT who's been managing his home with it for 12 months, so he'd be a good person to pick up with. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-04-12 by Wilberforce
The esp8266 has bags of FLASH, but bugger all RAM. There is only 80K and a lot of this is taken up by the OS and interpreter. Quite a bit of work has been done to strings into flash to free up precious RAM. The amount of |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2015-12-21 by Ollie
I'm testing against
test.mosquitto.org
. Every so often I get disconnected - which I imagine is from the server and is to be expected, as I think they regularly rollout the latest version.I have a
disconnect
event I can listen on, and currently I reissuemqtt.connect()
in the events callback. My problem with this approach is that I'm losing memory. It might survive one reconnect, but not two. I have duplicated message listeners which I imagine is part of the memory problem.I considered another approach would be to save to memory and fire the
reset()
function, to bring the board and whole program back up?But is there any pattern/approach that I could use to recover without a restart?
Edit: I've just considered that maybe I should unbind the listeners in the disconnect event callback too?
Beta Was this translation helpful? Give feedback.
All reactions