Changed partition table to allow for OTA updates

This commit is contained in:
Djuri Baars 2023-11-10 23:18:14 +01:00
parent 1d2c90fd60
commit 38efc73ca4
14 changed files with 92 additions and 13 deletions

View file

@ -44,7 +44,7 @@ jobs:
run: pip install --upgrade esptool run: pip install --upgrade esptool
- name: Create merged firmware binary - 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 - name: Create checksum for merged binary
run: shasum -a 256 output/full-firmware.bin | awk '{print $1}' > output/full-firmware.sha256 run: shasum -a 256 output/full-firmware.bin | awk '{print $1}' > output/full-firmware.sha256

View file

@ -1,16 +1,15 @@
dependencies: dependencies:
esp_littlefs: esp_littlefs:
component_hash: afa6d4544fadca368a35eb712d427cbb8334bc4f35a8f8299261b959a443c832 component_hash: null
source: source:
git: https://github.com/joltwallet/esp_littlefs.git path: /Users/padjuri/src/btclock_espidf/btclock_espidf/managed_components/esp_littlefs
path: . type: local
type: git version: 1.10.2
version: b671069b1e9e279f357736e7b51402f46e39d1b5
idf: idf:
component_hash: null component_hash: null
source: source:
type: idf type: idf
version: 4.4.5 version: 4.4.5
manifest_hash: 4b13ff241ec4d36ca2303b885c7088c32d74d090ef8e0ca6ea4c7d53047011d6 manifest_hash: 4796491ac0ef21bc9e7da581f1db6c59f92d6096be0ffd2d5fa4f2645943c54a
target: esp32s3 target: esp32s3
version: 1.0.0 version: 1.0.0

View file

@ -1,7 +1,7 @@
# Name, Type, SubType, Offset, Size, Flags # Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 36K, 20K, nvs, data, nvs, 36K, 20K,
otadata, data, ota, 56K, 8K, otadata, data, ota, 56K, 8K,
app0, app, ota_0, 64K, 3200K, app0, app, ota_0, 64K, 1700K,
#app1, app, ota_1, , 1600K, app1, app, ota_1, , 1700K,
spiffs, data, spiffs, , 600K, spiffs, data, spiffs, , 400K,
coredump, data, coredump,, 64K, coredump, data, coredump,, 64K,

1 # Name Type SubType Offset Size Flags
2 nvs data nvs 36K 20K
3 otadata data ota 56K 8K
4 app0 app ota_0 64K 3200K 1700K
5 #app1 app1 app ota_1 1600K 1700K
6 spiffs data spiffs 600K 400K
7 coredump data coredump 64K

View file

@ -119,3 +119,8 @@ bool isBlockNotifyConnected() {
return false; return false;
return esp_websocket_client_is_connected(blockNotifyClient); return esp_websocket_client_is_connected(blockNotifyClient);
} }
void stopBlockNotify() {
esp_websocket_client_stop(blockNotifyClient);
esp_websocket_client_destroy(blockNotifyClient);
}

View file

@ -20,3 +20,4 @@ void onWebsocketMessage(esp_websocket_event_data_t* event_data);
unsigned long getBlockHeight(); unsigned long getBlockHeight();
bool isBlockNotifyConnected(); bool isBlockNotifyConnected();
void stopBlockNotify();

View file

@ -37,8 +37,7 @@ void setup()
xTaskCreate(setupWebsocketClients, "setupWebsocketClients", 4096, NULL, tskIDLE_PRIORITY, NULL); xTaskCreate(setupWebsocketClients, "setupWebsocketClients", 4096, NULL, tskIDLE_PRIORITY, NULL);
setupButtonTask(); setupButtonTask();
Serial.printf("Number of free Preferences entries %d", preferences.freeEntries()); setupOTA();
} }
void tryImprovSetup() void tryImprovSetup()

View file

@ -14,6 +14,7 @@
#include <map> #include <map>
#include "ota.hpp"
#include "lib/screen_handler.hpp" #include "lib/screen_handler.hpp"
#include "lib/webserver.hpp" #include "lib/webserver.hpp"
#include "lib/block_notify.hpp" #include "lib/block_notify.hpp"

51
src/lib/ota.cpp Normal file
View file

@ -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));
}
}

8
src/lib/ota.hpp Normal file
View file

@ -0,0 +1,8 @@
#include <Arduino.h>
#include <ArduinoOTA.h>
#include "config.hpp"
#include "shared.hpp"
void setupOTA();
void onOTAStart();
void handleOTATask(void *parameter);

View file

@ -74,3 +74,8 @@ bool isPriceNotifyConnected() {
return false; return false;
return esp_websocket_client_is_connected(clientPrice); return esp_websocket_client_is_connected(clientPrice);
} }
void stopPriceNotify() {
esp_websocket_client_stop(clientPrice);
esp_websocket_client_destroy(clientPrice);
}

View file

@ -16,3 +16,4 @@ void onWebsocketPriceMessage(esp_websocket_event_data_t* event_data);
unsigned long getPrice(); unsigned long getPrice();
bool isPriceNotifyConnected(); bool isPriceNotifyConnected();
void stopPriceNotify();

View file

@ -13,6 +13,10 @@ extern TaskHandle_t blockUpdateTaskHandle;
extern TaskHandle_t timeUpdateTaskHandle; extern TaskHandle_t timeUpdateTaskHandle;
extern TaskHandle_t taskScreenRotateTaskHandle; extern TaskHandle_t taskScreenRotateTaskHandle;
extern esp_timer_handle_t screenRotateTimer;
extern esp_timer_handle_t minuteTimer;
uint getCurrentScreen(); uint getCurrentScreen();
void setCurrentScreen(uint newScreen); void setCurrentScreen(uint newScreen);
void nextScreen(); void nextScreen();

View file

@ -70,6 +70,10 @@ void setupWebserver()
xTaskCreate(eventSourceTask, "eventSourceTask", 4096, NULL, tskIDLE_PRIORITY, &eventSourceTaskHandle); xTaskCreate(eventSourceTask, "eventSourceTask", 4096, NULL, tskIDLE_PRIORITY, &eventSourceTaskHandle);
} }
void stopWebServer() {
server.end();
}
StaticJsonDocument<768> getStatusObject() StaticJsonDocument<768> getStatusObject()
{ {
StaticJsonDocument<768> root; StaticJsonDocument<768> root;

View file

@ -14,6 +14,7 @@
extern TaskHandle_t eventSourceTaskHandle; extern TaskHandle_t eventSourceTaskHandle;
void stopWebServer();
void setupWebserver(); void setupWebserver();
bool processEpdColorSettings(AsyncWebServerRequest *request); bool processEpdColorSettings(AsyncWebServerRequest *request);