mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-27 19:57:38 +00:00
Merge pull request #1981 from TD-er/feature/ota_warning
[OTA] Add OTA info and disable when not enough space
This commit is contained in:
@@ -519,6 +519,8 @@ bool showSettingsFileLayout = false;
|
||||
#ifdef FEATURE_MDNS
|
||||
#include <ESP8266mDNS.h>
|
||||
#endif
|
||||
#define SMALLEST_OTA_IMAGE 272*1024 // smallest known 2-step OTA image
|
||||
#define MAX_SKETCH_SIZE 1044464
|
||||
#ifdef FEATURE_ARDUINO_OTA
|
||||
#include <ArduinoOTA.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
|
||||
@@ -3398,6 +3398,21 @@ void play_rtttl(uint8_t _pin, const char *p )
|
||||
|
||||
//#endif
|
||||
|
||||
bool OTA_possible(uint32_t& maxSketchSize, bool& use2step) {
|
||||
#if defined(ESP8266)
|
||||
maxSketchSize = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
|
||||
const bool otaPossible = maxSketchSize > SMALLEST_OTA_IMAGE;
|
||||
use2step = maxSketchSize < ESP.getSketchSize();
|
||||
if (use2step) {
|
||||
const uint32_t totalSketchSpace = ESP.getFreeSketchSpace() + ESP.getSketchSize();
|
||||
maxSketchSize = totalSketchSpace - SMALLEST_OTA_IMAGE;
|
||||
}
|
||||
if (maxSketchSize > MAX_SKETCH_SIZE) maxSketchSize = MAX_SKETCH_SIZE;
|
||||
return otaPossible;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef FEATURE_ARDUINO_OTA
|
||||
/********************************************************************************************\
|
||||
|
||||
+22
-11
@@ -493,8 +493,13 @@ void WebServerInit()
|
||||
WebServer.on(F("/favicon.ico"), handle_favicon);
|
||||
|
||||
#if defined(ESP8266)
|
||||
if (getFlashRealSizeInBytes() > 524288)
|
||||
{
|
||||
uint32_t maxSketchSize;
|
||||
bool use2step;
|
||||
if (OTA_possible(maxSketchSize, use2step)) {
|
||||
httpUpdater.setup(&WebServer);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(ESP8266)
|
||||
@@ -3355,17 +3360,23 @@ void handle_tools() {
|
||||
|
||||
#if defined(ESP8266)
|
||||
{
|
||||
const uint32_t flashSize = getFlashRealSizeInBytes();
|
||||
if (flashSize > 524288)
|
||||
{
|
||||
addFormSubHeader(F("Firmware"));
|
||||
html_TR_TD_height(30);
|
||||
addWideButton(F("update"), F("Load"), F(""));
|
||||
addHelpButton(F("EasyOTA"));
|
||||
html_TD();
|
||||
TXBuffer += F("Load a new firmware");
|
||||
if (flashSize <= 1048576) {
|
||||
TXBuffer += F(" <b>WARNING</b> only use 2-step OTA update and sketch < 604 kB");
|
||||
uint32_t maxSketchSize;
|
||||
bool use2step;
|
||||
if (OTA_possible(maxSketchSize, use2step)) {
|
||||
addFormSubHeader(F("Firmware"));
|
||||
html_TR_TD_height(30);
|
||||
addWideButton(F("update"), F("Load"), F(""));
|
||||
addHelpButton(F("EasyOTA"));
|
||||
html_TD();
|
||||
TXBuffer += F("Load a new firmware");
|
||||
if (use2step) {
|
||||
TXBuffer += F(" <b>WARNING</b> only use 2-step OTA update and sketch < ");
|
||||
} else {
|
||||
TXBuffer += F(" Max sketch size: ");
|
||||
}
|
||||
TXBuffer += maxSketchSize / 1024;
|
||||
TXBuffer += F(" kB");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user