I am having an issue where my devices loose their connection to the cloud - rapidly blinking cyan. This happens sometimes at the same time on all devices . I suspect this is during a publish event.
I am using the ethernet featherwing with the following:
SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(SEMI_AUTOMATIC);
then in my setup:
System.enableFeature(FEATURE_ETHERNET_DETECTION);
WiFi.off(); // this is an argon device
Ethernet.on();
Ethernet.connect();
Particle.connect();
waitFor(Particle.connected, 1000);
client.connect(MQTT_CLIENT_NAME, "xxx", "xxxx"); // connect to mqtt server
then in my loop
if(currentMillis - previousMillis > Publishinterval) {
previousMillis = currentMillis;
if (Particle.connected()) {
publishQueue.publish(eventName, payload, PRIVATE, WITH_ACK);
}
// send to mqtt broker
if (client.isConnected()) {
client.publish(eventName, payload);
}
}
I looked up the device connection status on my pfsense router and its showing as offline. Which leads me to believe it may not be a cloud connection issue?
Should I be checking the ethernet connection and/or the particle cloud connection before pushing data to the cloud and mqtt server? here is what I am thinking of doing now in my loop. I’d appreciate some help to clean this up - perhaps add the check for ethernet connection and also merge it all into a nice if else non blocking statement?
// this keeps the mqtt connection live
if (!client.isConnected()) {
client.connect(MQTT_CLIENT_NAME, "xxx", "xxx");
} else {
client.loop();
}
// check cloud connection
if (Particle.connected() == false) {
Particle.connect(); // will this block loop?
}
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > Publishinterval) {
previousMillis = currentMillis;
if (Particle.connected()) {
publishQueue.publish(eventName, payload, PRIVATE, WITH_ACK);
}
// send to mqtt broker
if (client.isConnected()) {
client.publish(eventName, payload);
}
}