Closed samabsalom closed 6 years ago
Hi @samabsalom, Thanks for your message.
Sam
Hi Sam, I too like how robust your code is but you still haven't answered his second question as your multi sensor code is for different sensors but what about multiple PIR sensors as in my case i would like to use 6 pir's with your code and thats not straight forward as the previous sam suggested. So the question still stands how do I report the status of multiple PIR sensors to the mqtt broker.
Sam
Hi, You may find an answer in this sketch , which contains an array of structures, one structure per device (or sensor in your case).
Define a structure for each PIR sensor :
typedef struct {
...
bool isDiscovered;
bool toNotify;
char mqttTopic[48];
} NFCTag;
Loop through the array of structures and publish the new state of the modified PIR sensor(s) :
void loop() {
connectToMQTT();
mqttClient.loop();
...
yield();
for (uint8_t i = 0; i < NB_OF_NFC_TRACKED_TAGS; i++) {
if (NFCTags[i].toNotify) {
if (NFCTags[i].isDiscovered) {
publishToMQTT(NFCTags[i].mqttTopic, MQTT_PAYLOAD_ON);
} else {
publishToMQTT(NFCTags[i].mqttTopic, MQTT_PAYLOAD_OFF);
}
NFCTags[i].toNotify = false;
}
}
yield();
}
And define two interrupt routines for each sensor, triggered with a FALLING/RISING edge and change the isDiscovered
state accordingly.
Sam
Hi Sam, as always i still love what you've done. it basically all runs my house. i was wondering whether you could point me in the right direction with altering the PIR file?
any little bit of help would be greatly appreciated Thanks, Sam