Some more logging and cosmetics
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
[env:esp32doit-devkit-v1]
|
||||
platform = espressif32
|
||||
board = esp32doit-devkit-v1
|
||||
monitor_speed = 115200
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
knolleary/PubSubClient@^2.8
|
||||
|
||||
15
src/main.cpp
15
src/main.cpp
@@ -15,7 +15,6 @@ unsigned long lastMsg = 0;
|
||||
char msg[MSG_BUFFER_SIZE];
|
||||
|
||||
void setup_wifi() {
|
||||
|
||||
delay(10);
|
||||
// We start by connecting to a WiFi network
|
||||
Serial.println();
|
||||
@@ -61,6 +60,11 @@ void reconnect() {
|
||||
}
|
||||
|
||||
void send_mqtt(String status, long time_min=0) {
|
||||
Serial.print("MQTT Send status ");
|
||||
Serial.print(status);
|
||||
Serial.print(" mins ");
|
||||
Serial.println(time_min);
|
||||
|
||||
const size_t CAPACITY = JSON_OBJECT_SIZE(1);
|
||||
StaticJsonDocument<CAPACITY> doc;
|
||||
|
||||
@@ -101,10 +105,14 @@ void loop() {
|
||||
|
||||
short currentState = digitalRead(PIR_PIN);
|
||||
if (currentState != previousState) {
|
||||
Serial.print("Status changed; currentState: ");
|
||||
Serial.print(currentState);
|
||||
Serial.print(" previousState: ");
|
||||
Serial.println(previousState);
|
||||
if (currentState == HIGH) {
|
||||
send_mqtt("motion");
|
||||
digitalWrite(LED_BUILTIN,HIGH);
|
||||
delay(1000);
|
||||
delay(5000);
|
||||
digitalWrite(LED_BUILTIN,LOW);
|
||||
previousMotionMillis=millis();
|
||||
}
|
||||
@@ -112,9 +120,10 @@ void loop() {
|
||||
}
|
||||
|
||||
long minsSinceLastMotion=(millis()-previousMotionMillis)/(1000*60);
|
||||
if (previousNoMoNotifyMins != minsSinceLastMotion) {
|
||||
if ((previousNoMoNotifyMins != minsSinceLastMotion) && (0 != minsSinceLastMotion)) {
|
||||
send_mqtt("no_motion",minsSinceLastMotion);
|
||||
previousNoMoNotifyMins = minsSinceLastMotion;
|
||||
}
|
||||
|
||||
delay(20);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user