Changed the sensor from PIR to Radar - technically the mqtt messages are not correct anymore.
This commit is contained in:
26
src/main.cpp
26
src/main.cpp
@@ -101,9 +101,6 @@ long previousMotionMillis=millis();
|
|||||||
short previousState=0;
|
short previousState=0;
|
||||||
long previousNoMoNotifyMinutes=0;
|
long previousNoMoNotifyMinutes=0;
|
||||||
|
|
||||||
uint repeatTriggerCounter=0;
|
|
||||||
const int repeatTriggerResetSeconds=30;
|
|
||||||
const short requiredRepeatsToTrigger=1;
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (!mqttClient.connected()) {
|
if (!mqttClient.connected()) {
|
||||||
reconnect();
|
reconnect();
|
||||||
@@ -117,27 +114,15 @@ void loop() {
|
|||||||
Serial.print(" previousState: ");
|
Serial.print(" previousState: ");
|
||||||
Serial.println(previousState);
|
Serial.println(previousState);
|
||||||
if (currentState == HIGH) {
|
if (currentState == HIGH) {
|
||||||
if (repeatTriggerCounter >= requiredRepeatsToTrigger) {
|
|
||||||
send_mqtt("motion");
|
send_mqtt("motion");
|
||||||
} else {
|
|
||||||
send_mqtt("motion_ignored");
|
|
||||||
}
|
|
||||||
digitalWrite(LED_BUILTIN,HIGH);
|
digitalWrite(LED_BUILTIN,HIGH);
|
||||||
previousMotionMillis=millis();
|
previousMotionMillis=millis();
|
||||||
repeatTriggerCounter++;
|
} else {
|
||||||
}
|
digitalWrite(LED_BUILTIN,LOW);
|
||||||
|
}
|
||||||
previousState = currentState;
|
previousState = currentState;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
|
||||||
(currentState == LOW)
|
|
||||||
&& (repeatTriggerCounter >= requiredRepeatsToTrigger)
|
|
||||||
&& ((millis()-previousMotionMillis)/millisPerSecond >= repeatTriggerResetSeconds)
|
|
||||||
) {
|
|
||||||
repeatTriggerCounter =0;
|
|
||||||
send_mqtt("motion_repeat_trigger_reset");
|
|
||||||
}
|
|
||||||
|
|
||||||
const int secondsPerMinute=60;
|
const int secondsPerMinute=60;
|
||||||
long minutesSinceLastMotion=(millis()-previousMotionMillis)/(millisPerSecond*secondsPerMinute);
|
long minutesSinceLastMotion=(millis()-previousMotionMillis)/(millisPerSecond*secondsPerMinute);
|
||||||
if ((previousNoMoNotifyMinutes != minutesSinceLastMotion) && (0 != minutesSinceLastMotion)) {
|
if ((previousNoMoNotifyMinutes != minutesSinceLastMotion) && (0 != minutesSinceLastMotion)) {
|
||||||
@@ -145,10 +130,5 @@ void loop() {
|
|||||||
previousNoMoNotifyMinutes = minutesSinceLastMotion;
|
previousNoMoNotifyMinutes = minutesSinceLastMotion;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int ledDelaySeconds=5;
|
|
||||||
if ((millis()-previousMotionMillis)/(millisPerSecond) >= ledDelaySeconds) {
|
|
||||||
digitalWrite(LED_BUILTIN,LOW);
|
|
||||||
}
|
|
||||||
|
|
||||||
delay(20);
|
delay(20);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user