implement display for OTA progress

This commit is contained in:
Jonas Leder 2025-06-28 17:31:49 +02:00
commit 6460cd4802
3 changed files with 36 additions and 2 deletions

View file

@ -15,4 +15,5 @@ framework = arduino
lib_deps =
jgromes/RadioLib@7.1.2
jgromes/RadioBoards@^1.0.0
tzapu/WiFiManager@^2.0.17
tzapu/WiFiManager@^2.0.17
thingpulse/ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.6.1

View file

@ -6,6 +6,8 @@
#include <HTTPClient.h>
#include <RadioLib.h>
#include "buildinfo.h"
#include <Wire.h>
#include "SSD1306Wire.h"
// first you have to set your radio model and pin configuration
// this is provided just as a default example

View file

@ -302,15 +302,37 @@ uint16_t getCurrentSensorMv(int gpio)
// why it is empty.
void loop() {}
void runOtaUpdate()
{
Serial.println("Received OTA request");
pinMode(Vext, OUTPUT);
pinMode(RST_OLED, OUTPUT);
digitalWrite(RST_OLED, HIGH);
delay(1);
digitalWrite(RST_OLED, LOW);
delay(20);
digitalWrite(RST_OLED, HIGH);
digitalWrite(Vext, LOW); // enable external power
SSD1306Wire display(0x3c, SDA_OLED, SCL_OLED, GEOMETRY_128_64);
display.init();
display.setContrast(255);
display.flipScreenVertically();
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_10);
display.clear();
display.println("OTA Update");
display.println("Connecting to WiFi");
display.display();
if (!wm.autoConnect())
{
Serial.println("Failed to connect to wifi");
display.println("Failed to connect to wifi");
display.display();
return;
}
display.println("Starting OTA");
display.display();
HTTPClient http;
String otaurl = OTAURL;
@ -321,6 +343,8 @@ void runOtaUpdate()
int httpCode = http.GET();
if (httpCode != HTTP_CODE_OK)
{
display.println("Failed downloading firmware");
display.display();
Serial.print("Failed downloading OTA firmware: ");
Serial.println(httpCode);
return;
@ -350,15 +374,22 @@ void runOtaUpdate()
if(lastprogress != progress) {
lastprogress = progress;
Serial.println(("Progress: " + String(progress) + "%").c_str());
display.clear();
display.println(("Progress: " + String(progress) + "%").c_str());
display.display();
}
}
if (len > 0)
{
Serial.println("Failed downloading OTA");
display.println("Failed downloading OTA");
display.display();
return;
}
Update.end(true);
Serial.println("OTA update done");
display.println("OTA successfull, rebooting");
display.display();
Serial.flush();
ESP.restart();
}