Pull OTA prototype
All checks were successful
Test compiling project / test (push) Successful in 1m50s

This commit is contained in:
2025-02-11 22:42:43 +01:00
parent 5171374ff3
commit 04b2aba6ca
2 changed files with 63 additions and 2 deletions

View File

@@ -10,14 +10,15 @@
[env:ESP32]
platform = espressif32
board = wemos_d1_mini32
board = esp32dev
framework = arduino
monitor_speed = 115200
lib_deps =
ottowinter/ESPAsyncWebServer-esphome@^3.1.0
ottowinter/ESPAsyncWebServer-esphome@^3.3.0
robtillaart/INA226@^0.4.4
bblanchon/ArduinoJson@^6.21.3
ArduinoLog
board_build.partitions = default.csv
upload_protocol = espota
upload_port = 192.168.5.242
lib_extra_dirs = libs

View File

@@ -4,6 +4,7 @@
#include <ESPAsyncWebServer.h>
#include <ETH.h>
#include <WiFi.h>
#include <HTTPUpdate.h>
#include "AsyncJson.h"
#include <ArduinoJson.h>
@@ -39,6 +40,52 @@ extern "C" int rom_phy_get_vdd33();
AsyncWebServer server(80);
#define FORMAT_LITTLEFS_IF_FAILED true
void update_started() {
Serial.println("CALLBACK: HTTP update process started");
}
void update_finished() {
Serial.println("CALLBACK: HTTP update process finished");
}
void update_progress(int cur, int total) {
Serial.printf("CALLBACK: HTTP update process at %d of %d bytes...\n", cur, total);
}
void update_error(int err) {
Serial.printf("CALLBACK: HTTP update fatal error code %d\n", err);
}
void run_ota(void* parameter) {
Serial.println("RUNNING OTA");
// WiFiClient client;
httpUpdate.onStart(update_started);
httpUpdate.onEnd(update_finished);
httpUpdate.onProgress(update_progress);
httpUpdate.onError(update_error);
Serial.println("RUNNING OTA");
WiFiClientSecure client;
client.setInsecure();
t_httpUpdate_return ret = httpUpdate.update(client, "https://iot.tobiasmaier.me/firmware/waterlevel/INA233/1_1_1.bin");
// t_httpUpdate_return ret = httpUpdate.update(client, "https://iot.tobiasmaier.me", 443, "/firmware/waterlevel/INA233/1_0_1.bin");
switch (ret) {
case HTTP_UPDATE_FAILED:
Serial.printf("HTTP_UPDATE_FAILED Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str());
break;
case HTTP_UPDATE_NO_UPDATES:
Serial.println("HTTP_UPDATE_NO_UPDATES");
break;
case HTTP_UPDATE_OK:
Serial.println("HTTP_UPDATE_OK");
break;
}
}
void setup()
{
prefs.begin("waterlevel", false);
@@ -150,9 +197,20 @@ void setup()
request->send(SPIFFS, "/settings.html", "text/html", false); // TODO add proper return templating
});
server.on("/ota", HTTP_GET, [](AsyncWebServerRequest* request) {
Serial.println("OTA Task start");
xTaskCreate(run_ota, "RunOTATask", 1024 * 8, NULL, 1, NULL);
request->send(200, "text/plain", "OTA done");
});
setup_api_endpoints();
server.on("/chota.css", HTTP_GET, [](AsyncWebServerRequest* request) { request->send(SPIFFS, "/chota.css", "text/css", false); });
server.on("/gauge.js", HTTP_GET, [](AsyncWebServerRequest* request) { request->send(SPIFFS, "/gauge.js", "application/javascript", false); });
@@ -204,3 +262,5 @@ void loop()
ArduinoOTA.handle();
delay(1000);
}