Pull OTA prototype
All checks were successful
Test compiling project / test (push) Successful in 1m50s
All checks were successful
Test compiling project / test (push) Successful in 1m50s
This commit is contained in:
@@ -10,14 +10,15 @@
|
|||||||
|
|
||||||
[env:ESP32]
|
[env:ESP32]
|
||||||
platform = espressif32
|
platform = espressif32
|
||||||
board = wemos_d1_mini32
|
board = esp32dev
|
||||||
framework = arduino
|
framework = arduino
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
lib_deps =
|
lib_deps =
|
||||||
ottowinter/ESPAsyncWebServer-esphome@^3.1.0
|
ottowinter/ESPAsyncWebServer-esphome@^3.3.0
|
||||||
robtillaart/INA226@^0.4.4
|
robtillaart/INA226@^0.4.4
|
||||||
bblanchon/ArduinoJson@^6.21.3
|
bblanchon/ArduinoJson@^6.21.3
|
||||||
ArduinoLog
|
ArduinoLog
|
||||||
|
board_build.partitions = default.csv
|
||||||
upload_protocol = espota
|
upload_protocol = espota
|
||||||
upload_port = 192.168.5.242
|
upload_port = 192.168.5.242
|
||||||
lib_extra_dirs = libs
|
lib_extra_dirs = libs
|
||||||
|
|||||||
60
src/main.cpp
60
src/main.cpp
@@ -4,6 +4,7 @@
|
|||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
#include <ETH.h>
|
#include <ETH.h>
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
#include <HTTPUpdate.h>
|
||||||
|
|
||||||
#include "AsyncJson.h"
|
#include "AsyncJson.h"
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
@@ -39,6 +40,52 @@ extern "C" int rom_phy_get_vdd33();
|
|||||||
AsyncWebServer server(80);
|
AsyncWebServer server(80);
|
||||||
#define FORMAT_LITTLEFS_IF_FAILED true
|
#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()
|
void setup()
|
||||||
{
|
{
|
||||||
prefs.begin("waterlevel", false);
|
prefs.begin("waterlevel", false);
|
||||||
@@ -150,9 +197,20 @@ void setup()
|
|||||||
request->send(SPIFFS, "/settings.html", "text/html", false); // TODO add proper return templating
|
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();
|
setup_api_endpoints();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
server.on("/chota.css", HTTP_GET, [](AsyncWebServerRequest* request) { request->send(SPIFFS, "/chota.css", "text/css", false); });
|
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); });
|
server.on("/gauge.js", HTTP_GET, [](AsyncWebServerRequest* request) { request->send(SPIFFS, "/gauge.js", "application/javascript", false); });
|
||||||
|
|
||||||
@@ -204,3 +262,5 @@ void loop()
|
|||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user