diff --git a/sensor/platformio.ini b/sensor/platformio.ini index 9c2f4c5..8175603 100644 --- a/sensor/platformio.ini +++ b/sensor/platformio.ini @@ -19,7 +19,7 @@ lib_deps = https://github.com/dawidchyrzynski/arduino-home-assistant.git#2.0.0 links2004/WebSockets@^2.3.7 https://github.com/EinarArnason/ArduinoQueue.git@^1.2.5 - https://github.com/scottchiefbaker/ESP-WebOTA.git#aefb6c1a9190601b12b973a0c1cce39cb4e0f453 + https://github.com/netmindz/ESP-WebOTA.git#disable-interrupts [env:wemos_d1_mini32] diff --git a/sensor/src/sensor.ino b/sensor/src/sensor.ino index e394355..f90687b 100644 --- a/sensor/src/sensor.ino +++ b/sensor/src/sensor.ino @@ -164,6 +164,14 @@ void IRAM_ATTR panelSelected() { clearRXbuffer(); } +/** + * @brief enable interrupt for pin5 falling level change so we can clear the rx buffer + * every time our panel is selected + */ +void attachPanelInterrupt() { + attachInterrupt(digitalPinToInterrupt(PIN_5_PIN), panelSelected, FALLING); +} + void sendCommand(String command, int count) { Serial.printf("Sending %s - %u times\n", command.c_str(), count); for (int i = 0; i < count; i++) { @@ -356,9 +364,30 @@ void setup() { TX_PIN); // added here to see if line about was where the hang was tub.updateBaudRate(115200); #endif - // enable interrupt for pin5 falling level change so we can clear the rx buffer - // everytime our panel is selected - attachInterrupt(digitalPinToInterrupt(PIN_5_PIN), panelSelected, FALLING); + + attachPanelInterrupt(); + + webota + .onStart([]() { + Serial.println("Start updating"); + detachInterrupt(digitalPinToInterrupt(PIN_5_PIN)); + }) + .onEnd([]() { + Serial.println("\nOTA End"); + attachPanelInterrupt(); + }) + .onProgress([](unsigned int progress, unsigned int total) { + Serial.printf("Progress: %u%%\r", (progress / (total / 100))); + }) + .onError([](ota_error_t error) { + Serial.printf("Error[%u]: ", error); + if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed"); + else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed"); + else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed"); + else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed"); + else if (error == OTA_END_ERROR) Serial.println("End Failed"); + attachPanelInterrupt(); + }); init_wifi(ssid, passphrase, "hottub-sensor"); webota.init(8080, "/update"); @@ -560,9 +589,7 @@ void loop() { mqtt.loop(); - detachInterrupt(digitalPinToInterrupt(PIN_5_PIN)); webota.handle(); - attachInterrupt(digitalPinToInterrupt(PIN_5_PIN), panelSelected, FALLING); telnetLoop();