issues - most likely caused by light setting
This commit is contained in:
12
src/main.cpp
12
src/main.cpp
@@ -98,7 +98,7 @@ void setup() {
|
|||||||
|
|
||||||
const int millisPerSecond=1000;
|
const int millisPerSecond=1000;
|
||||||
long previousMotionMillis=millis();
|
long previousMotionMillis=millis();
|
||||||
short previousState=0;
|
short previousState=-1;
|
||||||
long previousNoMoNotifyMinutes=0;
|
long previousNoMoNotifyMinutes=0;
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@@ -108,16 +108,20 @@ void loop() {
|
|||||||
mqttClient.loop();
|
mqttClient.loop();
|
||||||
|
|
||||||
short currentState = digitalRead(PIR_PIN);
|
short currentState = digitalRead(PIR_PIN);
|
||||||
|
// This out pin triggering is dependent not only on movement, but also on light levels which can be configured in the app.
|
||||||
|
// I set it to 255 and "below" - this triggered it for me.....
|
||||||
|
//send_mqtt("occupancy_state_debug", currentState);
|
||||||
if (currentState != previousState) {
|
if (currentState != previousState) {
|
||||||
Serial.print("Status changed; currentState: ");
|
Serial.print("Status changed; currentState: ");
|
||||||
Serial.print(currentState);
|
Serial.print(currentState);
|
||||||
Serial.print(" previousState: ");
|
Serial.print(" previousState: ");
|
||||||
Serial.println(previousState);
|
Serial.println(previousState);
|
||||||
if (currentState == HIGH) {
|
if (currentState == HIGH) {
|
||||||
send_mqtt("motion");
|
send_mqtt("motion");
|
||||||
digitalWrite(LED_BUILTIN,HIGH);
|
digitalWrite(LED_BUILTIN,HIGH);
|
||||||
previousMotionMillis=millis();
|
previousMotionMillis=millis();
|
||||||
} else {
|
} else {
|
||||||
|
send_mqtt("no_motion_ignore");
|
||||||
digitalWrite(LED_BUILTIN,LOW);
|
digitalWrite(LED_BUILTIN,LOW);
|
||||||
}
|
}
|
||||||
previousState = currentState;
|
previousState = currentState;
|
||||||
@@ -126,9 +130,9 @@ void loop() {
|
|||||||
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)) {
|
||||||
send_mqtt("no_motion",minutesSinceLastMotion);
|
send_mqtt("no_motion", minutesSinceLastMotion);
|
||||||
previousNoMoNotifyMinutes = minutesSinceLastMotion;
|
previousNoMoNotifyMinutes = minutesSinceLastMotion;
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(20);
|
delay(100);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user