From 38efc73ca42cd62729d0f80bab20323faf658736 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Fri, 10 Nov 2023 23:18:14 +0100 Subject: [PATCH] Changed partition table to allow for OTA updates --- .github/workflows/workflow.yml | 2 +- dependencies.lock | 11 ++++---- partition.csv | 6 ++-- src/lib/block_notify.cpp | 5 ++++ src/lib/block_notify.hpp | 1 + src/lib/config.cpp | 3 +- src/lib/config.hpp | 1 + src/lib/ota.cpp | 51 ++++++++++++++++++++++++++++++++++ src/lib/ota.hpp | 8 ++++++ src/lib/price_notify.cpp | 5 ++++ src/lib/price_notify.hpp | 3 +- src/lib/screen_handler.hpp | 4 +++ src/lib/webserver.cpp | 4 +++ src/lib/webserver.hpp | 1 + 14 files changed, 92 insertions(+), 13 deletions(-) create mode 100644 src/lib/ota.cpp create mode 100644 src/lib/ota.hpp diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 548454e..18f9f61 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -44,7 +44,7 @@ jobs: run: pip install --upgrade esptool - name: Create merged firmware binary - run: mkdir -p output && esptool.py --chip esp32s3 merge_bin -o output/full-firmware.bin --flash_mode dio 0x0000 .pio/build/lolin_s3_mini_qr/bootloader.bin 0x8000 .pio/build/lolin_s3_mini_qr/partitions.bin 0xe000 ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin 0x10000 .pio/build/lolin_s3_mini_qr/firmware.bin 0x330000 .pio/build/lolin_s3_mini_qr/littlefs.bin + run: mkdir -p output && esptool.py --chip esp32s3 merge_bin -o output/full-firmware.bin --flash_mode dio 0x0000 .pio/build/lolin_s3_mini_qr/bootloader.bin 0x8000 .pio/build/lolin_s3_mini_qr/partitions.bin 0xe000 ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin 0x10000 .pio/build/lolin_s3_mini_qr/firmware.bin 0x369000 .pio/build/lolin_s3_mini_qr/littlefs.bin - name: Create checksum for merged binary run: shasum -a 256 output/full-firmware.bin | awk '{print $1}' > output/full-firmware.sha256 diff --git a/dependencies.lock b/dependencies.lock index 9c7b06b..d288419 100644 --- a/dependencies.lock +++ b/dependencies.lock @@ -1,16 +1,15 @@ dependencies: esp_littlefs: - component_hash: afa6d4544fadca368a35eb712d427cbb8334bc4f35a8f8299261b959a443c832 + component_hash: null source: - git: https://github.com/joltwallet/esp_littlefs.git - path: . - type: git - version: b671069b1e9e279f357736e7b51402f46e39d1b5 + path: /Users/padjuri/src/btclock_espidf/btclock_espidf/managed_components/esp_littlefs + type: local + version: 1.10.2 idf: component_hash: null source: type: idf version: 4.4.5 -manifest_hash: 4b13ff241ec4d36ca2303b885c7088c32d74d090ef8e0ca6ea4c7d53047011d6 +manifest_hash: 4796491ac0ef21bc9e7da581f1db6c59f92d6096be0ffd2d5fa4f2645943c54a target: esp32s3 version: 1.0.0 diff --git a/partition.csv b/partition.csv index af93e83..4ca1357 100644 --- a/partition.csv +++ b/partition.csv @@ -1,7 +1,7 @@ # Name, Type, SubType, Offset, Size, Flags nvs, data, nvs, 36K, 20K, otadata, data, ota, 56K, 8K, -app0, app, ota_0, 64K, 3200K, -#app1, app, ota_1, , 1600K, -spiffs, data, spiffs, , 600K, +app0, app, ota_0, 64K, 1700K, +app1, app, ota_1, , 1700K, +spiffs, data, spiffs, , 400K, coredump, data, coredump,, 64K, diff --git a/src/lib/block_notify.cpp b/src/lib/block_notify.cpp index 201b2ba..ffbc15f 100644 --- a/src/lib/block_notify.cpp +++ b/src/lib/block_notify.cpp @@ -118,4 +118,9 @@ bool isBlockNotifyConnected() { if (blockNotifyClient == NULL) return false; return esp_websocket_client_is_connected(blockNotifyClient); +} + +void stopBlockNotify() { + esp_websocket_client_stop(blockNotifyClient); + esp_websocket_client_destroy(blockNotifyClient); } \ No newline at end of file diff --git a/src/lib/block_notify.hpp b/src/lib/block_notify.hpp index ebbcfc7..fc41d1c 100644 --- a/src/lib/block_notify.hpp +++ b/src/lib/block_notify.hpp @@ -20,3 +20,4 @@ void onWebsocketMessage(esp_websocket_event_data_t* event_data); unsigned long getBlockHeight(); bool isBlockNotifyConnected(); +void stopBlockNotify(); \ No newline at end of file diff --git a/src/lib/config.cpp b/src/lib/config.cpp index f0250b2..e4e5c1d 100644 --- a/src/lib/config.cpp +++ b/src/lib/config.cpp @@ -37,8 +37,7 @@ void setup() xTaskCreate(setupWebsocketClients, "setupWebsocketClients", 4096, NULL, tskIDLE_PRIORITY, NULL); setupButtonTask(); - Serial.printf("Number of free Preferences entries %d", preferences.freeEntries()); - + setupOTA(); } void tryImprovSetup() diff --git a/src/lib/config.hpp b/src/lib/config.hpp index 81ace25..6537bfc 100644 --- a/src/lib/config.hpp +++ b/src/lib/config.hpp @@ -14,6 +14,7 @@ #include +#include "ota.hpp" #include "lib/screen_handler.hpp" #include "lib/webserver.hpp" #include "lib/block_notify.hpp" diff --git a/src/lib/ota.cpp b/src/lib/ota.cpp new file mode 100644 index 0000000..e943be5 --- /dev/null +++ b/src/lib/ota.cpp @@ -0,0 +1,51 @@ +#include "ota.hpp" + +TaskHandle_t taskOtaHandle = NULL; + + +void setupOTA() +{ + ArduinoOTA.onStart(onOTAStart); + + ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) + { Serial.printf("OTA Progress: %u%%\r", (progress / (total / 100))); }); + + ArduinoOTA.onEnd([]() + { Serial.println("\nOTA update finished"); }); + + + ArduinoOTA.setHostname(getMyHostname().c_str()); + ArduinoOTA.setMdnsEnabled(false); + ArduinoOTA.begin(); + + xTaskCreate(handleOTATask, "handleOTA", 4096, NULL, tskIDLE_PRIORITY, &taskOtaHandle); + +} + +void onOTAStart() +{ + // Stop all timers + esp_timer_stop(screenRotateTimer); + esp_timer_stop(minuteTimer); + + // Stop or suspend all tasks + vTaskSuspend(priceUpdateTaskHandle); + vTaskSuspend(blockUpdateTaskHandle); + vTaskSuspend(timeUpdateTaskHandle); + vTaskSuspend(taskScreenRotateTaskHandle); + + vTaskSuspend(ledTaskHandle); + vTaskSuspend(buttonTaskHandle); + + stopWebServer(); + stopBlockNotify(); + stopPriceNotify(); +} + +void handleOTATask(void *parameter) { + for (;;) { + // Task 1 code + ArduinoOTA.handle(); // Allow OTA updates to occur + vTaskDelay(pdMS_TO_TICKS(1000)); + } +} \ No newline at end of file diff --git a/src/lib/ota.hpp b/src/lib/ota.hpp new file mode 100644 index 0000000..4ecdf5d --- /dev/null +++ b/src/lib/ota.hpp @@ -0,0 +1,8 @@ +#include +#include +#include "config.hpp" +#include "shared.hpp" + +void setupOTA(); +void onOTAStart(); +void handleOTATask(void *parameter); \ No newline at end of file diff --git a/src/lib/price_notify.cpp b/src/lib/price_notify.cpp index f6577c5..0cf6129 100644 --- a/src/lib/price_notify.cpp +++ b/src/lib/price_notify.cpp @@ -73,4 +73,9 @@ bool isPriceNotifyConnected() { if (clientPrice == NULL) return false; return esp_websocket_client_is_connected(clientPrice); +} + +void stopPriceNotify() { + esp_websocket_client_stop(clientPrice); + esp_websocket_client_destroy(clientPrice); } \ No newline at end of file diff --git a/src/lib/price_notify.hpp b/src/lib/price_notify.hpp index e6f7ad2..0694cce 100644 --- a/src/lib/price_notify.hpp +++ b/src/lib/price_notify.hpp @@ -15,4 +15,5 @@ void onWebsocketPriceEvent(void *handler_args, esp_event_base_t base, int32_t ev void onWebsocketPriceMessage(esp_websocket_event_data_t* event_data); unsigned long getPrice(); -bool isPriceNotifyConnected(); \ No newline at end of file +bool isPriceNotifyConnected(); +void stopPriceNotify(); \ No newline at end of file diff --git a/src/lib/screen_handler.hpp b/src/lib/screen_handler.hpp index eda91c0..3437597 100644 --- a/src/lib/screen_handler.hpp +++ b/src/lib/screen_handler.hpp @@ -13,6 +13,10 @@ extern TaskHandle_t blockUpdateTaskHandle; extern TaskHandle_t timeUpdateTaskHandle; extern TaskHandle_t taskScreenRotateTaskHandle; +extern esp_timer_handle_t screenRotateTimer; +extern esp_timer_handle_t minuteTimer; + + uint getCurrentScreen(); void setCurrentScreen(uint newScreen); void nextScreen(); diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp index 12a3f00..1341450 100644 --- a/src/lib/webserver.cpp +++ b/src/lib/webserver.cpp @@ -70,6 +70,10 @@ void setupWebserver() xTaskCreate(eventSourceTask, "eventSourceTask", 4096, NULL, tskIDLE_PRIORITY, &eventSourceTaskHandle); } +void stopWebServer() { + server.end(); +} + StaticJsonDocument<768> getStatusObject() { StaticJsonDocument<768> root; diff --git a/src/lib/webserver.hpp b/src/lib/webserver.hpp index 6b0f879..7af562e 100644 --- a/src/lib/webserver.hpp +++ b/src/lib/webserver.hpp @@ -14,6 +14,7 @@ extern TaskHandle_t eventSourceTaskHandle; +void stopWebServer(); void setupWebserver(); bool processEpdColorSettings(AsyncWebServerRequest *request);