Check alarm/state change field

main
Filip B P 2 years ago
parent 6cb2ad48a9
commit 9ac58c65f1

@ -84,20 +84,22 @@ void callback(char* topic, byte* payload, unsigned int length) {
}
else if (strcmp(topic, "alarm/state") == 0)
{
if (strcmp(doc["status"], "Armed") == 0)
{
if (bool reed = digitalRead(REED_ACTIVATION_PIN) == 1)
if (doc["changed"] == true) {
if (strcmp(doc["status"], "Armed") == 0)
{
DynamicJsonDocument doc(1024);
doc["deviceId"] = deviceId;
doc["open"] = reed;
char buffer[1024];
size_t n = serializeJson(doc, buffer);
client.publish("door/status", buffer, n);
}
if (bool reed = digitalRead(REED_ACTIVATION_PIN) == 1)
{
DynamicJsonDocument doc(1024);
doc["deviceId"] = deviceId;
doc["open"] = reed;
char buffer[1024];
size_t n = serializeJson(doc, buffer);
client.publish("door/status", buffer, n);
}
}
}
}

Loading…
Cancel
Save