Check alarm/state change field

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

@ -84,19 +84,21 @@ 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)
{
DynamicJsonDocument doc(1024);
doc["deviceId"] = deviceId; doc["deviceId"] = deviceId;
doc["open"] = reed; doc["open"] = reed;
char buffer[1024]; char buffer[1024];
size_t n = serializeJson(doc, buffer); size_t n = serializeJson(doc, buffer);
client.publish("door/status", buffer, n); client.publish("door/status", buffer, n);
}
} }
} }
} }

Loading…
Cancel
Save