Save 6k code from ESP32 safeboot

This commit is contained in:
Theo Arends 2024-11-11 15:17:22 +01:00
parent 0536cc87a0
commit 0744bf7f2b
6 changed files with 36 additions and 31 deletions

View File

@ -687,9 +687,11 @@ char* SettingsText(uint32_t index) {
if (index >= SET_MAX) { // Index above SET_MAX are not stored in Settings if (index >= SET_MAX) { // Index above SET_MAX are not stored in Settings
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER
#ifndef FIRMWARE_MINIMAL
if (SET_BUTTON17 <= index && index <= SET_BUTTON32) if (SET_BUTTON17 <= index && index <= SET_BUTTON32)
return (char*)GetWebButton(index-SET_BUTTON17+16); return (char*)GetWebButton(index-SET_BUTTON17+16);
#endif #endif // not FIRMWARE_MINIMAL
#endif // USE_WEBSERVER
position += settings_text_size -1; // Setting not supported - internal error - return empty string position += settings_text_size -1; // Setting not supported - internal error - return empty string
} else { } else {
SettingsUpdateFinished(); SettingsUpdateFinished();

View File

@ -582,10 +582,8 @@ const WebServerDispatch_t WebServerDispatch[] PROGMEM = {
{ "dl", HTTP_ANY, HandleBackupConfiguration }, { "dl", HTTP_ANY, HandleBackupConfiguration },
{ "rs", HTTP_ANY, HandleRestoreConfiguration }, { "rs", HTTP_ANY, HandleRestoreConfiguration },
{ "rt", HTTP_ANY, HandleResetConfiguration }, { "rt", HTTP_ANY, HandleResetConfiguration },
{ "in", HTTP_ANY, HandleInformation }
#endif // Not FIRMWARE_MINIMAL #endif // Not FIRMWARE_MINIMAL
#ifndef FIRMWARE_MINIMAL_ONLY
{ "in", HTTP_ANY, HandleInformation },
#endif // Not FIRMWARE_MINIMAL_ONLY
}; };
void WebServer_on(const char * prefix, void (*func)(void), uint8_t method = HTTP_ANY) { void WebServer_on(const char * prefix, void (*func)(void), uint8_t method = HTTP_ANY) {
@ -1521,14 +1519,7 @@ void HandleRoot(void) {
if (HTTP_ADMIN == Web.state) { if (HTTP_ADMIN == Web.state) {
#ifdef FIRMWARE_MINIMAL #ifdef FIRMWARE_MINIMAL
#ifdef ESP32
#ifndef FIRMWARE_MINIMAL_ONLY
WSContentSpaceButton(BUTTON_INFORMATION);
WSContentButton(BUTTON_FIRMWARE_UPGRADE);
#endif // FIRMWARE_MINIMAL_ONLY
#else // ESP8266
WSContentSpaceButton(BUTTON_FIRMWARE_UPGRADE); WSContentSpaceButton(BUTTON_FIRMWARE_UPGRADE);
#endif // ESP32
WSContentButton(BUTTON_CONSOLE); WSContentButton(BUTTON_CONSOLE);
#else // Not FIRMWARE_MINIMAL #else // Not FIRMWARE_MINIMAL
WSContentSpaceButton(BUTTON_CONFIGURATION); WSContentSpaceButton(BUTTON_CONFIGURATION);
@ -1912,7 +1903,7 @@ void HandleTemplateConfiguration(void) {
if (!FlashPin(i)) { if (!FlashPin(i)) {
WSContentSend_P(PSTR("%s%d"), (i>0)?",":"", template_gp.io[i]); WSContentSend_P(PSTR("%s%d"), (i>0)?",":"", template_gp.io[i]);
} }
#endif #endif // CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6
} }
WSContentSend_P(PSTR("}1%d}1%d"), flag, Settings->user_template_base); // FLAG: 1 BASE: 17 WSContentSend_P(PSTR("}1%d}1%d"), flag, Settings->user_template_base); // FLAG: 1 BASE: 17
WSContentEnd(); WSContentEnd();
@ -1966,7 +1957,7 @@ void HandleTemplateConfiguration(void) {
RedPin(i) ? WebColor(COL_TEXT_WARNING) : WebColor(COL_TEXT), i, (0==i) ? PSTR(" style='width:146px'") : "", i, i); RedPin(i) ? WebColor(COL_TEXT_WARNING) : WebColor(COL_TEXT), i, (0==i) ? PSTR(" style='width:146px'") : "", i, i);
WSContentSend_P(PSTR("<td style='width:54px'><select id='h%d'></select></td></tr>"), i); WSContentSend_P(PSTR("<td style='width:54px'><select id='h%d'></select></td></tr>"), i);
} }
#endif #endif // CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6
} }
WSContentSend_P(PSTR("</table>")); WSContentSend_P(PSTR("</table>"));
@ -2202,7 +2193,7 @@ void HandleWifiConfiguration(void) {
WebRestart(3); WebRestart(3);
#else #else
HandleRoot(); HandleRoot();
#endif #endif // RESTART_AFTER_INITIAL_WIFI_CONFIG
} }
} }
@ -2365,7 +2356,7 @@ void HandleWifiConfiguration(void) {
WSContentSend_P(HTTP_FORM_WIFI_PART2, SettingsTextEscaped(SET_STASSID2).c_str(), WIFI_HOSTNAME, WIFI_HOSTNAME, SettingsTextEscaped(SET_HOSTNAME).c_str(), SettingsTextEscaped(SET_CORS).c_str()); WSContentSend_P(HTTP_FORM_WIFI_PART2, SettingsTextEscaped(SET_STASSID2).c_str(), WIFI_HOSTNAME, WIFI_HOSTNAME, SettingsTextEscaped(SET_HOSTNAME).c_str(), SettingsTextEscaped(SET_CORS).c_str());
#else #else
WSContentSend_P(HTTP_FORM_WIFI_PART2, SettingsTextEscaped(SET_STASSID2).c_str(), WIFI_HOSTNAME, WIFI_HOSTNAME, SettingsTextEscaped(SET_HOSTNAME).c_str()); WSContentSend_P(HTTP_FORM_WIFI_PART2, SettingsTextEscaped(SET_STASSID2).c_str(), WIFI_HOSTNAME, WIFI_HOSTNAME, SettingsTextEscaped(SET_HOSTNAME).c_str());
#endif #endif // USE_CORS
} }
WSContentSend_P(HTTP_FORM_END); WSContentSend_P(HTTP_FORM_END);
@ -2400,7 +2391,7 @@ void WifiSaveSettings(void) {
cmnd += AddWebCommand(PSTR(D_CMND_HOSTNAME), PSTR("h"), PSTR("1")); cmnd += AddWebCommand(PSTR(D_CMND_HOSTNAME), PSTR("h"), PSTR("1"));
#ifdef USE_CORS #ifdef USE_CORS
cmnd += AddWebCommand(PSTR(D_CMND_CORS), PSTR("c"), PSTR("1")); cmnd += AddWebCommand(PSTR(D_CMND_CORS), PSTR("c"), PSTR("1"));
#endif #endif // USE_CORS
cmnd += AddWebCommand(PSTR(D_CMND_SSID "1"), PSTR("s1"), PSTR("1")); cmnd += AddWebCommand(PSTR(D_CMND_SSID "1"), PSTR("s1"), PSTR("1"));
cmnd += AddWebCommand(PSTR(D_CMND_SSID "2"), PSTR("s2"), PSTR("1")); cmnd += AddWebCommand(PSTR(D_CMND_SSID "2"), PSTR("s2"), PSTR("1"));
cmnd += AddWebCommand(PSTR(D_CMND_PASSWORD "3"), PSTR("p1"), PSTR("\"")); cmnd += AddWebCommand(PSTR(D_CMND_PASSWORD "3"), PSTR("p1"), PSTR("\""));
@ -2617,12 +2608,6 @@ void HandleRestoreConfiguration(void)
Web.upload_file_type = UPL_SETTINGS; Web.upload_file_type = UPL_SETTINGS;
} }
#endif // Not FIRMWARE_MINIMAL
/*-------------------------------------------------------------------------------------------*/
#ifndef FIRMWARE_MINIMAL_ONLY
void WSContentSeparatorI(uint32_t size) { void WSContentSeparatorI(uint32_t size) {
WSContentSend_P(PSTR("</td></tr><tr><td colspan=2><hr style='font-size:2px'%s/>"), (1 == size)?" size=1":""); WSContentSend_P(PSTR("</td></tr><tr><td colspan=2><hr style='font-size:2px'%s/>"), (1 == size)?" size=1":"");
// WSContentSend_P(PSTR("</td></tr><tr><td colspan=2><hr style='font-size:%dpx'/>"), size); // WSContentSend_P(PSTR("</td></tr><tr><td colspan=2><hr style='font-size:%dpx'/>"), size);
@ -2873,7 +2858,8 @@ void HandleInformation(void) {
WSContentSpaceButton(BUTTON_MAIN); WSContentSpaceButton(BUTTON_MAIN);
WSContentStop(); WSContentStop();
} }
#endif // Not FIRMWARE_MINIMAL_ONLY
#endif // Not FIRMWARE_MINIMAL
/*-------------------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------------------*/
@ -2939,7 +2925,7 @@ void HandleUpgradeFirmware(void) {
} }
#else #else
WSContentSend_P(HTTP_FORM_RST_UPG, PSTR(D_START_UPGRADE)); WSContentSend_P(HTTP_FORM_RST_UPG, PSTR(D_START_UPGRADE));
#endif #endif // ESP32
WSContentSpaceButton(BUTTON_MAIN); WSContentSpaceButton(BUTTON_MAIN);
WSContentStop(); WSContentStop();
@ -3169,7 +3155,7 @@ void HandleUploadLoop(void) {
uint32_t upload_size = (!strlen(tmp)) ? 0 : atoi(tmp); uint32_t upload_size = (!strlen(tmp)) ? 0 : atoi(tmp);
AddLog(LOG_LEVEL_DEBUG, D_LOG_UPLOAD "Freespace %i Filesize %i", ESP.getFreeSketchSpace(), upload_size); AddLog(LOG_LEVEL_DEBUG, D_LOG_UPLOAD "Freespace %i Filesize %i", ESP.getFreeSketchSpace(), upload_size);
if (upload_size > ESP.getFreeSketchSpace()) { // TODO revisit this test if (upload_size > ESP.getFreeSketchSpace()) { // TODO revisit this test
#endif #endif // ESP8266
Web.upload_error = 4; // Program flash size is larger than real flash size Web.upload_error = 4; // Program flash size is larger than real flash size
return; return;
} }
@ -3565,6 +3551,8 @@ bool CaptivePortal(void)
/*********************************************************************************************/ /*********************************************************************************************/
#ifndef FIRMWARE_MINIMAL
enum {QUERY_DEFAULT=0, QUERY_RUN}; enum {QUERY_DEFAULT=0, QUERY_RUN};
int WebQuery(char *buffer, int query_function); int WebQuery(char *buffer, int query_function);
@ -3727,7 +3715,6 @@ int WebQuery(char *buffer, int query_function = 0)
return status; return status;
} }
int WebSend(char *buffer) int WebSend(char *buffer)
{ {
// [tasmota] POWER1 ON --> Sends http://tasmota/cm?cmnd=POWER1 ON // [tasmota] POWER1 ON --> Sends http://tasmota/cm?cmnd=POWER1 ON
@ -3878,7 +3865,6 @@ const char kWebCmndStatus[] PROGMEM = D_JSON_DONE "|" D_JSON_WRONG_PARAMETERS "|
const char kWebCommands[] PROGMEM = "|" // No prefix const char kWebCommands[] PROGMEM = "|" // No prefix
D_CMND_WEBLOG "|" D_CMND_WEBLOG "|"
#ifndef FIRMWARE_MINIMAL_ONLY
D_CMND_WEBTIME "|" D_CMND_WEBTIME "|"
#ifdef USE_EMULATION #ifdef USE_EMULATION
D_CMND_EMULATION "|" D_CMND_EMULATION "|"
@ -3897,12 +3883,10 @@ const char kWebCommands[] PROGMEM = "|" // No prefix
#ifdef USE_CORS #ifdef USE_CORS
"|" D_CMND_CORS "|" D_CMND_CORS
#endif #endif
#endif // FIRMWARE_MINIMAL_ONLY
; ;
void (* const WebCommand[])(void) PROGMEM = { void (* const WebCommand[])(void) PROGMEM = {
&CmndWeblog, &CmndWeblog,
#ifndef FIRMWARE_MINIMAL_ONLY
&CmndWebTime, &CmndWebTime,
#ifdef USE_EMULATION #ifdef USE_EMULATION
&CmndEmulation, &CmndEmulation,
@ -3921,7 +3905,6 @@ void (* const WebCommand[])(void) PROGMEM = {
#ifdef USE_CORS #ifdef USE_CORS
, &CmndCors , &CmndCors
#endif #endif
#endif // FIRMWARE_MINIMAL_ONLY
}; };
/*********************************************************************************************/ /*********************************************************************************************/
@ -4174,7 +4157,9 @@ void CmndCors(void)
} }
ResponseCmndChar(SettingsText(SET_CORS)); ResponseCmndChar(SettingsText(SET_CORS));
} }
#endif #endif // USE_CORS
#endif // not FIRMWARE_MINIMAL
/*********************************************************************************************\ /*********************************************************************************************\
* Interface * Interface
@ -4263,9 +4248,11 @@ bool Xdrv01(uint32_t function)
} }
} }
break; break;
#ifndef FIRMWARE_MINIMAL
case FUNC_COMMAND: case FUNC_COMMAND:
result = DecodeCommand(kWebCommands, WebCommand); result = DecodeCommand(kWebCommands, WebCommand);
break; break;
#endif // FIRMWARE_MINIMAL
case FUNC_ACTIVE: case FUNC_ACTIVE:
result = true; result = true;
break; break;

View File

@ -512,6 +512,7 @@ void CmndRfTimeout(void) {
} }
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER
#ifndef FIRMWARE_MINIMAL
void SonoffBridgeAddButton(void) { void SonoffBridgeAddButton(void) {
WSContentSend_P(HTTP_TABLE100); WSContentSend_P(HTTP_TABLE100);
@ -539,6 +540,7 @@ void SonoffBridgeWebGetArg(void) {
} }
} }
#endif // not FIRMWARE_MINIMAL
#endif // USE_WEBSERVER #endif // USE_WEBSERVER
/*********************************************************************************************\ /*********************************************************************************************\
@ -559,12 +561,14 @@ bool Xdrv06(uint32_t function)
result = DecodeCommand(kSonoffBridgeCommands, SonoffBridgeCommand); result = DecodeCommand(kSonoffBridgeCommands, SonoffBridgeCommand);
break; break;
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER
#ifndef FIRMWARE_MINIMAL
case FUNC_WEB_ADD_MAIN_BUTTON: case FUNC_WEB_ADD_MAIN_BUTTON:
SonoffBridgeAddButton(); SonoffBridgeAddButton();
break; break;
case FUNC_WEB_GET_ARG: case FUNC_WEB_GET_ARG:
SonoffBridgeWebGetArg(); SonoffBridgeWebGetArg();
break; break;
#endif // not FIRMWARE_MINIMAL
#endif // USE_WEBSERVER #endif // USE_WEBSERVER
case FUNC_INIT: case FUNC_INIT:
if (Settings->rf_duplicate_time < 10) { if (Settings->rf_duplicate_time < 10) {

View File

@ -1619,6 +1619,7 @@ void TuyaSensorsShow(bool json)
} }
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER
#ifndef FIRMWARE_MINIMAL
#define WEB_HANDLE_TUYA "d16" #define WEB_HANDLE_TUYA "d16"
@ -1646,6 +1647,7 @@ void TuyaWebGetArg(void) {
} }
} }
#endif // not FIRMWARE_MINIMAL
#endif // USE_WEBSERVER #endif // USE_WEBSERVER
/*********************************************************************************************\ /*********************************************************************************************\
@ -1735,6 +1737,7 @@ bool Xdrv16(uint32_t function) {
TuyaSensorsShow(1); TuyaSensorsShow(1);
break; break;
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER
#ifndef FIRMWARE_MINIMAL
case FUNC_WEB_ADD_MAIN_BUTTON: case FUNC_WEB_ADD_MAIN_BUTTON:
TuyaAddButton(); TuyaAddButton();
break; break;
@ -1744,6 +1747,7 @@ bool Xdrv16(uint32_t function) {
case FUNC_WEB_SENSOR: case FUNC_WEB_SENSOR:
TuyaSensorsShow(0); TuyaSensorsShow(0);
break; break;
#endif // not FIRMWARE_MINIMAL
#endif // USE_WEBSERVER #endif // USE_WEBSERVER
case FUNC_ACTIVE: case FUNC_ACTIVE:
result = true; result = true;

View File

@ -2412,6 +2412,7 @@ void TuyaSensorsShow(bool json)
} }
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER
#ifndef FIRMWARE_MINIMAL
#define WEB_HANDLE_TUYA "d16" #define WEB_HANDLE_TUYA "d16"
@ -2439,6 +2440,7 @@ void TuyaWebGetArg(void) {
} }
} }
#endif // not FIRMWARE_MINIMAL
#endif // USE_WEBSERVER #endif // USE_WEBSERVER
/*********************************************************************************************\ /*********************************************************************************************\
@ -2570,6 +2572,7 @@ bool Xdrv16(uint32_t function) {
TuyaSensorsShow(1); TuyaSensorsShow(1);
break; break;
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER
#ifndef FIRMWARE_MINIMAL
case FUNC_WEB_ADD_MAIN_BUTTON: case FUNC_WEB_ADD_MAIN_BUTTON:
TuyaAddButton(); TuyaAddButton();
break; break;
@ -2579,6 +2582,7 @@ bool Xdrv16(uint32_t function) {
case FUNC_WEB_SENSOR: case FUNC_WEB_SENSOR:
TuyaSensorsShow(0); TuyaSensorsShow(0);
break; break;
#endif // not FIRMWARE_MINIMAL
#endif // USE_WEBSERVER #endif // USE_WEBSERVER
case FUNC_ACTIVE: case FUNC_ACTIVE:
result = true; result = true;

View File

@ -246,6 +246,7 @@ void LscMcModuleSelected(void) {
} }
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER
#ifndef FIRMWARE_MINIMAL
#ifdef USE_LSC_MCSL_GUI #ifdef USE_LSC_MCSL_GUI
void LscMcAddFuctionButtons(void) { void LscMcAddFuctionButtons(void) {
@ -287,6 +288,7 @@ void LscMcWebGetArg(void) {
} }
#endif // USE_LSC_MCSL_GUI #endif // USE_LSC_MCSL_GUI
#endif // not FIRMWARE_MINIMAL
#endif // USE_WEBSERVER #endif // USE_WEBSERVER
@ -306,6 +308,7 @@ bool Xlgt07(uint32_t function)
result = LscMcMultiButtonPressed(); result = LscMcMultiButtonPressed();
break; break;
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER
#ifndef FIRMWARE_MINIMAL
#ifdef USE_LSC_MCSL_GUI #ifdef USE_LSC_MCSL_GUI
case FUNC_WEB_ADD_MAIN_BUTTON: case FUNC_WEB_ADD_MAIN_BUTTON:
LscMcAddFuctionButtons(); LscMcAddFuctionButtons();
@ -314,6 +317,7 @@ bool Xlgt07(uint32_t function)
LscMcWebGetArg(); LscMcWebGetArg();
break; break;
#endif // USE_LSC_MCSL_GUI #endif // USE_LSC_MCSL_GUI
#endif // not FIRMWARE_MINIMAL
#endif // USE_WEBSERVER #endif // USE_WEBSERVER
case FUNC_MODULE_INIT: case FUNC_MODULE_INIT:
LscMcModuleSelected(); LscMcModuleSelected();