So I’m running a Core in manual mode. I’m trying to run it as a IoT rosetta stone - an intermediary between the Particle Cloud Pub/Sub to MQTT.
I’m running it in manual mode because at one point that seemed more reliable than automatic.
“My” code does this in loop
if (WiFi.ready() && init) { // Wait it out until we have a network to talk to
client.connect(CLIENT_NAME); // connect to the broker as CLIENT_NAME
delay(500);
setMqtt(); // Perform MQTT pub/sub
delay(200);
init = false;
Particle.connect();
delay(200);
Particle.subscribe(DEVICE_NAME, eventHandler, MY_DEVICES);
}
if (client.isConnected()) {
client.loop();
Particle.process();
} else if (WiFi.ready()) {
if (millis() - lastConnect > RECONNECT) {
lastConnect = millis();
WiFi.off();
delay(1000);
WiFi.on();
delay(500);
WiFi.connect();
init = true;
}
}
}
to try to work around any WiFi/cloud/MQTT dropouts but it’s not 100%. It can work for days and then suddenly stop working in the middle of the night (why then?!).
I’m at a bit of a loss as to why the above code doesn’t ALWAYS resurrect my Core (seems to work most of the time, but then when it doesn’t, seems to stop trying!) when either WiFi or the Cloud connection drops. Is there something I could do to make it more robust? Build in a full system reset maybe? Thanks!
Particle.process() is in your client.isConnected() condition. That means that it won’t be called (anymore) if client.isConnected() turns false at some point. Particle.process() is needed to do all the system processes (including reconnects) so if you don’t have Particle.process() somewhere else in your code, in the loop() this might explain why once it disconnects, it never reconnects.
That only is true for SYSTEM_MODE(MANUAL)withoutSYSTEM_THREAD(ENABLED) tho'
But since we don't know whether that's the case or not, it's still a good call
Thanks @ScruffR and @joost - I am not using SYSTEM_THREAD(ENABLED)…
Does that mean I should include SYSTEM_THREAD(ENABLED) or leave it out (as it is now?)
Was a bit unsure.
Thanks, @ScruffR, this is driving me nuts. I inserted lots of particle.process() and recompiled and reflashed. Ran fine for an hour and a half, then started breathing green. I want to weep!
I’m going to go back to automatic mode and see if that helps.
Arrrrrrrrrrrrrrrrrrrrrrrrr
Thanks. I’ve done some more testing and set that Core to ONE WiFi network (I thought having a choice would be beneficial, turns out it’s not?). It’s more reliable now. Seems like a DHCP client joining or leaving that WiFi AP sometimes (not always) knocks the Core offline
Were Cores REALLY this unreliable? I have other Cores connected to the same AP doing different (not MQTT) stuff and they’re a lot more stable. Not bulletproof, but a lot more stable than this. EDIT Scrap that, it’s not DHCP clients I don’t think, it’s happening far too often for that. Anyone using the @hirotakasteron a Core with success?
Just to report that MQTT does not work reliably on a Core. I transferred the same code to a Photon and it’s now rock solid. Posting this for future forum searchers!!
Thanks for all help @ScruffR, @hirotakaster, @peekay123, @joost
@netpex
Unluckily my CORE can’t work anymore now, but I was testing MQTT source code on CORE from the begining.
Not using MQTT, simple TCP client could works on your CORE environment?
You could break down the issue into parts in order to find the real cause(your WiFi or TCP and MQTT).
Hi @hirotakaster - Thanks - but I don’t have the time (or skill, come to that) to find out where the bug is. I’m a working Dad and a IoT hobbyist. It’s all I can do to find a bit of time to “play”, so when I do get chance to “play”, I like to just find a stack that works without bugs and run with it.
I’ve already sort of wasted a week and £40 (buying a new router) before I realised the problem was the Core, not the library or my WiFi.
I’ve found that working stack now: my existing WiFi, your library and the Photon (not the Core!)
Thanks again
MQTT users: would you recommend increasing the MQTT keep alive or does that just mask network problems rather than help mitigate them? As in, I could be missing messages and whereas now at least I know when I’m missing them from checking server logs, if I increase my keep alive, I could be missing them and not even know it?