Particle.subscribe trigger at setup()

Hello there,

I have a situation where I need the subscribe handler to be triggered by Particle.publish() during setup(). I register the Particle.subscribe() handler in setup(), and the handler is triggered fine if I publish the event during loop(). But it does not work if Particle.publish() is called in setup()…

To be more clear with my issue:

This works:

void setup() {
    Particle.subscribe("prefix", myHandler);
}

void loop() {
    Particle.publish("prefix/real-thing", "hello", PRIVATE); // this triggers myHandler
}

But this does not:

void setup() {
    Particle.subscribe("prefix", myHandler);
    waitUntil(Particle.connected); // even this does not help
    ...
    Particle.publish("prefix/real-thing", "hello", PRIVATE); // this does NOT trigger myHandler unfortunately
}

void loop() {
    ....
}

If there is some way to fix this, that would be great! Or at least knowing this is intended would be helpful too.

This seems to be the expected behaviour now.
Have a read through this discussion
JSONParserGeneratorRK (0.1.3) and OS 2.0.0 - #13 by ScruffR

1 Like

Thanks for the quick reply. I would +1 that it would be helpful if Particle can be firm about their stance on this and make it explicit in documentation!

We use Particle.subscribe to retrieve initial state from a server, so our first pass was to get this done in setup().

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.