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) else if (strcmp(topic, "alarm/state") == 0)
{ {
if (strcmp(doc["status"], "Armed") == 0) if (doc["changed"] == true) {
{ if (strcmp(doc["status"], "Armed") == 0)
if (bool reed = digitalRead(REED_ACTIVATION_PIN) == 1)
{ {
DynamicJsonDocument doc(1024); if (bool reed = digitalRead(REED_ACTIVATION_PIN) == 1)
{
doc["deviceId"] = deviceId; DynamicJsonDocument doc(1024);
doc["open"] = reed;
doc["deviceId"] = deviceId;
char buffer[1024]; doc["open"] = reed;
size_t n = serializeJson(doc, buffer);
char buffer[1024];
client.publish("door/status", buffer, n); size_t n = serializeJson(doc, buffer);
}
client.publish("door/status", buffer, n);
}
}
} }
} }

Loading…
Cancel
Save