There are some things to note
e.g. in your master code
Particle.variable("relayStatus", STATUS_MESSAGE_UNAVAILABLE, STRING);
...
Particle.variable("relayStatus", message, STRING);
This is not how Particle.variable()
is used.
You should rather declare one global variable (e.g. char relayState[64]
) and register that with the cloud via Particle.variable("relayStatus", relayState)
and from then on set relayState
(e.g. via strcpy()
) to whatever content you want relayStatus
to reflect when requested by the cloud.
I'm also always advocating against the use of String
and rather use C strings.
for the risk of heap fragmentation.
Next, you should only publish PUBLIC
events when absolutely required (aka "talk to somone else's device"), so you should rather do this
// Particle.publish(IDname, logString); // PUBLIC is default (for some obscure reason)
Particle.publish(IDname, logString, PRIVATE);
Your slaves should then subscribe via
Particle.subscribe("EVENT:InteriorOn", interiorOnHandler, MY_DEVICES);
Why do you compare to a single literal device ID?
if (strcmp(myId, "3c003a001247343438323536") == 0) {
I'd rather put the device IDs into an array of which the index aligns with your "device names" BAPS_LA_x
(don't introduce two diffferent numbers for the same thing) and search that array for the desired ID.
If you need to call your first device BAPS_LA_1
then just add a dummy item at index 0.
With that you can easily achieve what you're asking here
e.g.
if (strcmp(data, myID)) return; // leave when data parameter doesn't match `myID`
BTW, it's poor style to use delay(1000)
in a Particle.function()
callback.