Particle.publish() hangs on Photon when called in listening mode with SYSTEM_THREAD(ENABLED)

#include "application.h"


#define PUBLISH_PERIOD_MS 2000

int last_publish_attempt_ms;

void setup() {
  Particle.connect(); // Should be run without credentials present.
  last_publish_attempt_ms = 0;

void loop() {
   if (millis() - last_publish_attempt_ms >= PUBLISH_PERIOD_MS) {
     last_publish_attempt_ms = millis();

If the above program is run without credentials present, so that the call to Particle.connect() puts the module into listening mode, it will only print a single “pre-publish” message, with no “post-publish” following. The call to Particle.publish(“test”) never seems to return, even through timeout. This is true for MANUAL, SEMI_AUTOMATIC and AUTOMATIC system modes. I saw no mention of this behavior in the documentation, so I figured that it’s a bug. I’ve raised a issue on GitHub here:


It can be considered a bug, since it would be good for Particle.publish() just to return false if Particle.connected() == false.
As a workaround (or in general defensive programming practice) it might be good to ensure that the instruction actually has got any chance to succeede. Without connection it definetly won’t.

Further more with SYSTEM_MODE(MANUAL) you code might never really run stable since you are not calling Particle.process() anywhere in your code.

But again, it would still be good to have that check inside Particle.publish() too.

Issue being tracked here -