Changed partition table to allow for OTA updates

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

View file

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

View file

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

View file

@ -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()

View file

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

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

View file

@ -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();
bool isPriceNotifyConnected();
void stopPriceNotify();

View file

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

View file

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

View file

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