Skip to content

Commit

Permalink
[HCSR501] Update sensor only on change (#1846)
Browse files Browse the repository at this point in the history
Improve performance by avoiding unnecessary calls to handleJsonEnqueue when the HCSR501 sensor's state did not change
  • Loading branch information
diepeterpan authored Jan 24, 2024
1 parent 13f5704 commit 674b0b4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions main/ZsensorHCSR501.ino
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ void MeasureHCSR501() {
# ifdef HCSR501_LED_NOTIFY_GPIO
digitalWrite(HCSR501_LED_NOTIFY_GPIO, pirState == HCSR501_LED_ON);
# endif
HCSR501data["origin"] = subjectHCSR501toMQTT;
handleJsonEnqueue(HCSR501data);
if (HCSR501data.size() > 1) {
HCSR501data["origin"] = subjectHCSR501toMQTT;
handleJsonEnqueue(HCSR501data);
}
}
}
#endif

0 comments on commit 674b0b4

Please sign in to comment.