I have an E-Series LTE running the 1.5.1 Device OS.
It was previously working without issue. It will now publish messages to the cloud fine, but returns device unreachable when requesting vitals. Pings and function call are also not working.
In order to rule out application firmware issues, I’m running the following code with the same results.
#include "Particle.h"
SerialLogHandler logHandler(115200, LOG_LEVEL_ALL);
int testFunction(String extra);
void setup()
{
Particle.function("TEST", testFunction);
}
int testFunction(String extra)
{
Particle.publish("test", "this is a test message", PRIVATE);
return 1;
}
Any insight would be appreciated.
UPDATE:
adding the following line to setup seems to resolve the issue:
Particle.publishVitals(10)
I thought that it may be a keep alive issue so I tried this:
#include "Particle.h"
SYSTEM_MODE(SEMI_AUTOMATIC);
SerialLogHandler logHandler(115200, LOG_LEVEL_ALL);
int testFunction(String extra);
void setup()
{
Particle.function("TEST", testFunction);
Particle.keepAlive(10);
Particle.connect();
}
int testFunction(String extra)
{
Particle.publish("test", "this is a test message", PRIVATE);
return 1;
}
This also works. Setting the keep alive interval greater than 10 seconds causes intermittent outages.
I did not override it for clarity of example i.e. loop function is empty. The application I am debugging which does implement code in the loop demonstrates the same behavior.
A quibble I have with this is that you’re publishing before the connection is made, which makes the message to publish wait in a very limited queue area. I don’t know if it’s affecting your problem though. Maybe trying throwing
Thank you for the suggestion, but I think you may be conflating Particle.publish() and Particle.function().
According to the Device OS API Particle functions should be registered as soon as possible in Setup() when running in AUTOMATIC mode and before Particle.connect() is called when running in SEMI_AUTOMATIC code.