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:
Gijs Noorlander
2018-10-30 22:56:11 +01:00
committed by GitHub
3 changed files with 39 additions and 11 deletions
+2
View File
@@ -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>
+15
View File
@@ -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
View File
@@ -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");
}
}
}