constexpr char * MAUD_MSSG = "STRING1";
constexpr char * PETER_MSSG = "STRING2";
constexpr char * DOWNSTAIRS_MSSG = "STRING3";
constexpr char * OUTSIDE_MSSG = "STRING4";
void callback(char * topic, byte * payload, unsigned int length) {
char p[length + 1];
memcpy(p, payload, length);
p[length] = NULL;
if (!strcmp(p, "STRING2")) {
Particle.publish(DEVICE_NAME, PETER_MSSG, 60, PRIVATE);
} else if (!strcmp(p, "maud")) {
Particle.publish(DEVICE_NAME, MAUD_MSSG, 60, PRIVATE);
} else if (!strcmp(p, "locked")) {
myDFPlayer.playMp3Folder(23);
}
}
void eventHandler(const char * event,
const char * data) {
if (strcmp(data, DOWNSTAIRS_MSSG) == 0) {
myDFPlayer.playMp3Folder(20);
} else if (strcmp(data, OUTSIDE_MSSG) == 0) {
myDFPlayer.playMp3Folder(23);
}
}
So here are my two event handlers, the top one is for my MQTT messages in and the bottom is for my Particle messages in.
I’d realy like to be able to, if a message comes in on either platform (MQTT or Particle Pub/Sub) to be able to scan it for a preceding $, and if it has one, strip off that $, and simply insert it into where the myDFPlayer specifies the file number to be played. So for example if instead of “STRING2” coming in on MQTT triggering a manual Particle publish of PETER_MSSG (“STRING2”) it’d be cool to be able to instead send $STRING2.
Similarly if a message came through with ‘?’ preceding it such as ?24 I’d love to be able to have a handler which says - right - you’re clearly a command which is destined for myDFPlayer - and if it just took the ?24, stripped off the ? and inserted the 24 into myDFPlayer.playMp3Folder(24). Does this make sense?
I’m sort of using this particular Photon as a dual use “Rosetta stone” between Particle land and the rest of IoT land and also as an output speaker. It reacts to real world events and plays appropriate sound files.
Hope this makes sense…? Thank you and please tell me if I haven’t been clear enough.