diff --git a/firmware/firmware.bin b/firmware/firmware.bin index d55f2bd..0cc15b1 100644 Binary files a/firmware/firmware.bin and b/firmware/firmware.bin differ diff --git a/platformio.ini b/platformio.ini index 4e89a53..1a1ba39 100644 --- a/platformio.ini +++ b/platformio.ini @@ -19,6 +19,7 @@ build_flags = -D BAUD=${common_env_data.monitor_speed} ; -DDEBUG_ESP_PORT=Serial ; -DDEBUG_ESP_WIFI + ; -DDEBUG_ESP_HTTP_UPDATE ; -DDEBUG_ESP_CORE ; -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY ; v2 Lower Memory (default) ; -DPIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH ; v2 Higher Bandwidth diff --git a/src/execota.cpp b/src/execota.cpp index e4d0f08..deef173 100644 --- a/src/execota.cpp +++ b/src/execota.cpp @@ -24,7 +24,6 @@ SOFTWARE. */ void execfw() { Log.notice(F("Starting the Firmware OTA pull, will reboot without notice." CR)); - _delay(5000); // Let page finish loading // Stop web server before OTA update - will restart on reset stopWebServer(); @@ -37,8 +36,8 @@ void execfw() { ESPhttpUpdate.setLedPin(LED, LOW); // "http://www.brewbubbles.com/firmware/firmware.bin" - WiFiClient client; - t_httpUpdate_return ret = ESPhttpUpdate.update(client, F(FIRMWAREURL), ""); + WiFiClient _client; + t_httpUpdate_return ret = ESPhttpUpdate.update(_client, F(FIRMWAREURL), "0"); switch(ret) { case HTTP_UPDATE_FAILED: @@ -48,6 +47,7 @@ void execfw() { config.dospiffs2 = false; config.didupdate = false; saveConfig(); + ESP.restart(); break; case HTTP_UPDATE_NO_UPDATES: @@ -57,6 +57,7 @@ void execfw() { config.dospiffs2 = false; config.didupdate = false; saveConfig(); + ESP.restart(); break; case HTTP_UPDATE_OK: diff --git a/src/main.cpp b/src/main.cpp index 1f2751d..d419621 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -112,8 +112,6 @@ void loop() { config.brewfather.update = false; } - _delay(50); // Required to "loosen up" the loop so mDNS and webpages are responsive - yield(); } } diff --git a/src/ntp.cpp b/src/ntp.cpp index 0571df4..be4067c 100644 --- a/src/ntp.cpp +++ b/src/ntp.cpp @@ -39,7 +39,7 @@ void setClock() { #ifdef LOG_LEVEL Serial.println(); #endif - Log.verbose(F("Re-requesting time hack." CR)); + Log.verbose(F("Re-requesting time hack.")); configTime(GMT, 0, "pool.ntp.org", "time.nist.gov"); startSecs = time(nullptr); cycle++; @@ -47,7 +47,7 @@ void setClock() { #ifdef LOG_LEVEL Serial.print(F(".")); #endif - _delay(1000); + delay(1000); yield(); nowSecs = time(nullptr); } diff --git a/src/pushhelper.cpp b/src/pushhelper.cpp index 61b6454..0f7feb6 100644 --- a/src/pushhelper.cpp +++ b/src/pushhelper.cpp @@ -143,66 +143,3 @@ bool pushToTarget(PushTarget *target, IPAddress targetIP, int port) { return false; } } - -void setDoURLTarget() { - doURLTarget = true; // Semaphore required for Ticker + radio event -} - -void setDoBFTarget() { - doBFTarget = true; // Semaphore required for Ticker + radio event -} - -void setDoBrewfTarget() { - doBrewfTarget = true; // Semaphore required for Ticker + radio event -} - -void setDoReset() { - doReset = true; // Semaphore required for reset in callback -} - -void tickerLoop() { - Target *target = Target::getInstance(); - BFTarget *bfTarget = BFTarget::getInstance(); - BrewfTarget *brewfTarget = BrewfTarget::getInstance(); - - // Trigger Bubble check - // - if (doBubble) { - doBubble = false; - if (bubbles.update()) - Log.verbose(F("Current BPM is %D. Averages (%l in sample): BPM = %D, Ambient = %D, Vessel = %D." CR), - bubbles.lastBpm, - bubbles.sampleSize, - bubbles.getAvgBpm(), - bubbles.getAvgAmbient(), - bubbles.getAvgVessel() - ); - } - - // Handle JSON posts - // - // Do URL Target post - if (doURLTarget) { - doURLTarget = false; - target->push(); - } - // - // Do Brewer's Friend Post - if (doBFTarget) { // Do BF post - doBFTarget = false; - bfTarget->push(); - } - // - // Do Brewfather Post - if (doBrewfTarget) { // Do BF post - doBrewfTarget = false; - brewfTarget->push(); - } - - // Check for Reset Pending - // Necessary because we cannot delay in a callback - if (doReset) { - doReset = false; - resetController(); - } -} diff --git a/src/pushhelper.h b/src/pushhelper.h index acc77d8..3a7a469 100644 --- a/src/pushhelper.h +++ b/src/pushhelper.h @@ -28,11 +28,11 @@ SOFTWARE. */ #include "target.h" #include "brewfather.h" #include "brewersfriend.h" +#include "execota.h" #include IPAddress resolveHost(const char hostname[129]); bool pushToTarget(PushTarget*, IPAddress, int); -void tickerLoop(); void updateLoop(); void setDoURLTarget(); void setDoBFTarget(); @@ -41,9 +41,4 @@ void setDoReset(); extern volatile bool doBubble; extern struct Bubbles bubbles; -static bool __attribute__((unused)) doURLTarget = false; // Semaphore for Target timer -static bool __attribute__((unused)) doBFTarget = false; // Semaphore for BF timer -static bool __attribute__((unused)) doBrewfTarget = false; // Semaphore for BRF timer -static bool __attribute__((unused)) doReset = false; // Semahore for reset - #endif // _PUSHHELPER_H diff --git a/src/serial_setup.cpp b/src/serial_setup.cpp index 5f54991..824e50e 100644 --- a/src/serial_setup.cpp +++ b/src/serial_setup.cpp @@ -25,7 +25,7 @@ SOFTWARE. */ #ifndef DISABLE_LOGGING void setSerial() { // Start serial with auto-detected rate (default to BAUD) - _delay(3000); // Delay to allow monitor to start + delay(2000); // Delay to allow monitor to start Serial.begin(BAUD); // Serial.setDebugOutput(true); Serial.flush(); diff --git a/src/tools.cpp b/src/tools.cpp index ea10b01..d4e4adc 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -23,6 +23,7 @@ SOFTWARE. */ #include "tools.h" void _delay(unsigned long ulDelay) { + Log.verbose(F("DEBUG: In _delay()." CR)); // Safe semi-blocking delay #ifdef ESP32 vTaskDelay(ulDelay); // Builtin to ESP32 @@ -94,3 +95,75 @@ void saveBpm() { } } } + +void setDoURLTarget() { + doURLTarget = true; // Semaphore required for Ticker + radio event +} + +void setDoBFTarget() { + doBFTarget = true; // Semaphore required for Ticker + radio event +} + +void setDoBrewfTarget() { + doBrewfTarget = true; // Semaphore required for Ticker + radio event +} + +void setDoReset() { + doReset = true; // Semaphore required for reset in callback +} + +void setDoOTA() { + doOTA = true; // Semaphore required for OTA in callback +} + +void tickerLoop() { + Target *target = Target::getInstance(); + BFTarget *bfTarget = BFTarget::getInstance(); + BrewfTarget *brewfTarget = BrewfTarget::getInstance(); + + // Trigger Bubble check + // + if (doBubble) { + doBubble = false; + if (bubbles.update()) + Log.verbose(F("Current BPM is %D. Averages (%l in sample): BPM = %D, Ambient = %D, Vessel = %D." CR), + bubbles.lastBpm, + bubbles.sampleSize, + bubbles.getAvgBpm(), + bubbles.getAvgAmbient(), + bubbles.getAvgVessel() + ); + } + + // Handle JSON posts + // + // Do URL Target post + if (doURLTarget) { + doURLTarget = false; + target->push(); + } + // + // Do Brewer's Friend Post + if (doBFTarget) { // Do BF post + doBFTarget = false; + bfTarget->push(); + } + // + // Do Brewfather Post + if (doBrewfTarget) { // Do BF post + doBrewfTarget = false; + brewfTarget->push(); + } + + // Check for Reset Pending + // Necessary because we cannot delay in a callback + if (doReset) { + doReset = false; + resetController(); + } + + if (doOTA) { + doOTA = false; + execfw(); + } +} diff --git a/src/tools.h b/src/tools.h index 930eda3..afcc98b 100644 --- a/src/tools.h +++ b/src/tools.h @@ -24,6 +24,9 @@ SOFTWARE. */ #define _TOOLS_H #include "bubbles.h" +#include "brewersfriend.h" +#include "brewfather.h" +#include "target.h" #include #include #include @@ -36,6 +39,18 @@ void _delay(unsigned long); void resetController(); void loadBpm(); void saveBpm(); +void tickerLoop(); +void setDoURLTarget(); +void setDoBFTarget(); +void setDoBrewfTarget(); +void setDoReset(); +void setDoOTA(); + +static bool __attribute__((unused)) doURLTarget = false; // Semaphore for Target timer +static bool __attribute__((unused)) doBFTarget = false; // Semaphore for BF timer +static bool __attribute__((unused)) doBrewfTarget = false; // Semaphore for BRF timer +static bool __attribute__((unused)) doReset = false; // Semahore for reset +static bool __attribute__((unused)) doOTA = false; // Semahore for reset extern struct Bubbles bubbles; diff --git a/src/webserver.cpp b/src/webserver.cpp index 47d0aa5..7b82cd2 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -85,8 +85,8 @@ void setActionPageHandlers() server.on("/otastart/", HTTP_GET, [](AsyncWebServerRequest *request) { Log.verbose(F("Processing /otastart/." CR)); - request->send(200, F("text/plain"), F("200: OTA started.")); - execfw(); // Trigger the OTA update + request->send(200, F("text/plain"), F("200: OTA queued.")); + setDoOTA(); }); server.on("/clearupdate/", HTTP_GET, [](AsyncWebServerRequest *request) { diff --git a/src/webserver.h b/src/webserver.h index f0a2064..3165c2e 100644 --- a/src/webserver.h +++ b/src/webserver.h @@ -35,6 +35,7 @@ SOFTWARE. */ #include "config.h" #include "thatVersion.h" #include "pushhelper.h" +#include "tools.h" #include #include #include