I am working on an Android app that can send events to a Photon and vice versa. I have a system set up that allows for the following exchange of information:
• App sends message “register” to board
• Board receives event and sends its own event to the app
• App parses data and displays it to the user
This exchange works perfectly except for one flaw - after the app sends “register” once, the board stops publishing its events. I have checked the Particle logs and the serial monitor - the event is being sent from the app and the Photon’s handler function for the subscription is running, yet it does not publish its event.
Here is the handler function:
void myHandler(const char *event, const char *data)
{
String e = event;
String d = data;
Serial.println(e);
Serial.println(d);
String total = "REGISTER:name=Test;LED On,LED Off";
Particle.publish("mainBoard", total);
runTask(data);
}
Here is the function sending the events in the app:
The interesting thing in that connection might be what happens in runTask() and what happens after the handler finishes?
The actual Particle.subscribe() instruction and its location in your code would be interesting too.
Also Particle.publish() does only enqueue the event to publish but doesn’t wait for it to get delivered.
You could also check the return value of the publish call whether if does succeede at all.