From f46e8a7126b879b3c7d24ffa6b9fa2cf66089f8c Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 4 Jun 2020 10:30:19 +0200 Subject: Add self-ping to prevent timeouts --- martin/door/src/main.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'martin/door') diff --git a/martin/door/src/main.cpp b/martin/door/src/main.cpp index 38146e4..5b1efad 100644 --- a/martin/door/src/main.cpp +++ b/martin/door/src/main.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "cc1101.h" #include "hcs200.h" @@ -17,6 +18,10 @@ CC1101 radio(D0 /* GDO0 */, D2 /* GDO2 */, D8 /* SS */); //#define HCS200_TEST HCS200 hcs200; +const int ping_delay = 60000; +long ping_last = 0; +ping_option ping_opt; + void setup() { Serial.begin(9600); @@ -62,12 +67,16 @@ void setup() }); http_service.begin(); + memset(&ping_opt, 0, sizeof(struct ping_option)); + ping_opt.count = 1; + ping_opt.ip = WiFi.localIP(); + Serial.println("Started listening"); } void ICACHE_RAM_ATTR on_hcs200_isr() { - hcs200.on_isr(digitalRead(PIN_HCS200_DATA)); + hcs200.on_isr(digitalRead(PIN_HCS200_DATA) == HIGH); } bool hcs200_get_keycode(HCS200_Keycode &keycode) @@ -82,6 +91,7 @@ bool hcs200_get_keycode(HCS200_Keycode &keycode) if (hcs200.decode(keycode)) break; delay(1); + yield(); } digitalWrite(PIN_HCS200_ENABLE, LOW); detachInterrupt(digitalPinToInterrupt(PIN_HCS200_DATA)); @@ -114,7 +124,6 @@ void http_door_open() Serial.print("Got keycode: "); keycode.print(Serial); - if (http_service.hasArg("power")) { static const uint8_t patable_power_n30[8] = { 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; @@ -215,13 +224,17 @@ void loop() MDNS.update(); http_service.handleClient(); -#if 0 + if (millis() - ping_last > ping_delay) + { + ping_start(&ping_opt); + ping_last = millis(); + } + if (Serial.available() > 0) { while (Serial.read() >= 0) {} - serial_door_open(Serial); + //serial_door_open(Serial); } -#endif delay(1); } -- cgit v1.2.3