diff --git a/lib/App/App.cpp b/lib/App/App.cpp index 7f13cd2..2855420 100644 --- a/lib/App/App.cpp +++ b/lib/App/App.cpp @@ -16,11 +16,30 @@ AppConfig appcfg; AppConfig appcfgWR; AppConfig appcfgRD; -char *formatChipId( char *attribute ) +char *buffer; +char *buffer2; + +void appMemoryInit() +{ + if (buffer == NULL) + buffer = (char *)malloc(BUFFER_LENGTH + 1); + if (buffer2 == NULL) + buffer2 = (char *)malloc(BUFFER2_LENGTH + 1); +} + +void appMemoryFree() { - snprintf( buffer, 63, attribute, ESP.getChipId()); - buffer[63]= 0; - strncpy(attribute,buffer,63); + free(buffer); + free(buffer2); + buffer = buffer2 = NULL; + delay(250); +} + +char *formatChipId(char *attribute) +{ + snprintf(buffer, (ATTRIBUTE_SIZE-1), attribute, ESP.getChipId()); + buffer[(ATTRIBUTE_SIZE-1)] = 0; + strncpy(attribute, buffer, (ATTRIBUTE_SIZE-1)); return attribute; } @@ -38,18 +57,20 @@ const char *appUptime() void appShowHeader(Stream &out) { - out.println("\n\n" APP_NAME " - " APP_VERSION " - " APP_AUTHOR); - out.println("BUILD: " __DATE__ " " __TIME__); - out.println("PIOENV: " PIOENV); - out.println("PIOPLATFORM: " PIOPLATFORM); - out.println("PIOFRAMEWORK: " PIOFRAMEWORK); - out.printf("ESP SDK Version: %s\n", ESP.getSdkVersion()); - out.printf("ESP Core Version: %s\n\n", ESP.getCoreVersion().c_str()); + out.println(PSTR("\n\n" APP_NAME " - " APP_VERSION " - " APP_AUTHOR)); + out.println(PSTR("BUILD: " __DATE__ " " __TIME__)); + out.println(PSTR("PIOENV: " PIOENV)); + out.println(PSTR("PIOPLATFORM: " PIOPLATFORM)); + out.println(PSTR("PIOFRAMEWORK: " PIOFRAMEWORK)); + out.printf_P(PSTR("ESP SDK Version: %s\n"), ESP.getSdkVersion()); + out.printf_P(PSTR("ESP Core Version: %s\n\n"), ESP.getCoreVersion().c_str()); } App::App() { - sprintf(initFilename, "/%08X.ini", ESP.getChipId()); + buffer = buffer2 = NULL; + appMemoryInit(); + sprintf_P(initFilename, PSTR("/%08X.ini"), ESP.getChipId()); defaultConfig(); initSPIFFS = false; initialized = true; @@ -60,58 +81,60 @@ App::App() void App::defaultConfig() { - strncpy(appcfg.wifi_ssid, DEFAULT_WIFI_SSID, 63); - strncpy(appcfg.wifi_password, DEFAULT_WIFI_PASSWORD, 63); + strncpy(appcfg.wifi_ssid, DEFAULT_WIFI_SSID, (ATTRIBUTE_SIZE-1)); + strncpy(appcfg.wifi_password, DEFAULT_WIFI_PASSWORD, (ATTRIBUTE_SIZE-1)); appcfg.wifi_mode = DEFAULT_WIFI_MODE; appcfg.net_mode = DEFAULT_NET_MODE; - strncpy(appcfg.net_host, DEFAULT_NET_HOST, 63); - strncpy(appcfg.net_mask, DEFAULT_NET_MASK, 63); - strncpy(appcfg.net_gateway, DEFAULT_NET_GATEWAY, 63); - strncpy(appcfg.net_dns, DEFAULT_NET_DNS, 63); + strncpy(appcfg.net_host, DEFAULT_NET_HOST, (ATTRIBUTE_SIZE-1)); + strncpy(appcfg.net_mask, DEFAULT_NET_MASK, (ATTRIBUTE_SIZE-1)); + strncpy(appcfg.net_gateway, DEFAULT_NET_GATEWAY, (ATTRIBUTE_SIZE-1)); + strncpy(appcfg.net_dns, DEFAULT_NET_DNS, (ATTRIBUTE_SIZE-1)); - strncpy(appcfg.ota_hostname, DEFAULT_OTA_HOSTNAME, 63); - strncpy(appcfg.ota_password, DEFAULT_OTA_PASSWORD, 63); + strncpy(appcfg.ota_hostname, DEFAULT_OTA_HOSTNAME, (ATTRIBUTE_SIZE-1)); + strncpy(appcfg.ota_password, DEFAULT_OTA_PASSWORD, (ATTRIBUTE_SIZE-1)); - strncpy(appcfg.admin_password, DEFAULT_ADMIN_PASSWORD, 63); + strncpy(appcfg.admin_password, DEFAULT_ADMIN_PASSWORD, (ATTRIBUTE_SIZE-1)); appcfg.ohab_enabled = DEFAULT_OHAB_ENABLED; appcfg.ohab_version = DEFAULT_OHAB_VERSION; - strncpy(appcfg.ohab_host, DEFAULT_OHAB_HOST, 63); + strncpy(appcfg.ohab_host, DEFAULT_OHAB_HOST, (ATTRIBUTE_SIZE-1)); appcfg.ohab_port = DEFAULT_OHAB_PORT; appcfg.ohab_useauth = DEFAULT_OHAB_USEAUTH; - strncpy(appcfg.ohab_user, DEFAULT_OHAB_USER, 63); - strncpy(appcfg.ohab_password, DEFAULT_OHAB_PASSWORD, 63); - strncpy(appcfg.ohab_itemname, DEFAULT_OHAB_ITEMNAME, 63); + strncpy(appcfg.ohab_user, DEFAULT_OHAB_USER, (ATTRIBUTE_SIZE-1)); + strncpy(appcfg.ohab_password, DEFAULT_OHAB_PASSWORD, (ATTRIBUTE_SIZE-1)); + strncpy(appcfg.ohab_itemname, DEFAULT_OHAB_ITEMNAME, (ATTRIBUTE_SIZE-1)); appcfg.alexa_enabled = DEFAULT_ALEXA_ENABLED; - strncpy(appcfg.alexa_devicename, DEFAULT_ALEXA_DEVICENAME, 63); + strncpy(appcfg.alexa_devicename, DEFAULT_ALEXA_DEVICENAME, (ATTRIBUTE_SIZE-1)); appcfg.mqtt_enabled = DEFAULT_MQTT_ENABLED; - strncpy(appcfg.mqtt_clientid, DEFAULT_MQTT_CLIENTID, 63); - strncpy(appcfg.mqtt_host, DEFAULT_MQTT_HOST, 63); + strncpy(appcfg.mqtt_clientid, DEFAULT_MQTT_CLIENTID, (ATTRIBUTE_SIZE-1)); + strncpy(appcfg.mqtt_host, DEFAULT_MQTT_HOST, (ATTRIBUTE_SIZE-1)); appcfg.mqtt_port = DEFAULT_MQTT_PORT; appcfg.mqtt_useauth = DEFAULT_MQTT_USEAUTH; - strncpy(appcfg.mqtt_user, DEFAULT_MQTT_USER, 63); - strncpy(appcfg.mqtt_password, DEFAULT_MQTT_PASSWORD, 63); - strncpy(appcfg.mqtt_intopic, DEFAULT_MQTT_INTOPIC, 63); - strncpy(appcfg.mqtt_outtopic, DEFAULT_MQTT_OUTTOPIC, 63); + strncpy(appcfg.mqtt_user, DEFAULT_MQTT_USER, (ATTRIBUTE_SIZE-1)); + strncpy(appcfg.mqtt_password, DEFAULT_MQTT_PASSWORD, (ATTRIBUTE_SIZE-1)); + strncpy(appcfg.mqtt_intopic, DEFAULT_MQTT_INTOPIC, (ATTRIBUTE_SIZE-1)); + strncpy(appcfg.mqtt_outtopic, DEFAULT_MQTT_OUTTOPIC, (ATTRIBUTE_SIZE-1)); +/* appcfg.syslog_enabled = DEFAULT_SYSLOG_ENABLED; - strncpy(appcfg.syslog_host, DEFAULT_SYSLOG_HOST, 63); + strncpy(appcfg.syslog_host, DEFAULT_SYSLOG_HOST, (ATTRIBUTE_SIZE-1)); appcfg.syslog_port = DEFAULT_SYSLOG_PORT; - strncpy(appcfg.syslog_app_name, DEFAULT_SYSLOG_APP_NAME, 63); + strncpy(appcfg.syslog_app_name, DEFAULT_SYSLOG_APP_NAME, (ATTRIBUTE_SIZE-1)); +*/ #ifdef HAVE_ENERGY_SENSOR - strncpy(appcfg.ohab_item_voltage, DEFAULT_OHAB_ITEM_VOLTAGE, 63); - strncpy(appcfg.ohab_item_current, DEFAULT_OHAB_ITEM_CURRENT, 63); - strncpy(appcfg.ohab_item_power, DEFAULT_OHAB_ITEM_POWER, 63); + strncpy(appcfg.ohab_item_voltage, DEFAULT_OHAB_ITEM_VOLTAGE, (ATTRIBUTE_SIZE-1)); + strncpy(appcfg.ohab_item_current, DEFAULT_OHAB_ITEM_CURRENT, (ATTRIBUTE_SIZE-1)); + strncpy(appcfg.ohab_item_power, DEFAULT_OHAB_ITEM_POWER, (ATTRIBUTE_SIZE-1)); appcfg.ohab_sending_interval = DEFAULT_OHAB_SENDING_INTERVAL; - strncpy(appcfg.mqtt_topic_voltage, DEFAULT_MQTT_TOPIC_VOLTAGE, 63); - strncpy(appcfg.mqtt_topic_current, DEFAULT_MQTT_TOPIC_CURRENT, 63); - strncpy(appcfg.mqtt_topic_power, DEFAULT_MQTT_TOPIC_POWER, 63); - strncpy(appcfg.mqtt_topic_json, DEFAULT_MQTT_TOPIC_JSON, 63); + strncpy(appcfg.mqtt_topic_voltage, DEFAULT_MQTT_TOPIC_VOLTAGE, (ATTRIBUTE_SIZE-1)); + strncpy(appcfg.mqtt_topic_current, DEFAULT_MQTT_TOPIC_CURRENT, (ATTRIBUTE_SIZE-1)); + strncpy(appcfg.mqtt_topic_power, DEFAULT_MQTT_TOPIC_POWER, (ATTRIBUTE_SIZE-1)); + strncpy(appcfg.mqtt_topic_json, DEFAULT_MQTT_TOPIC_JSON, (ATTRIBUTE_SIZE-1)); #endif appcfg.mqtt_sending_interval = DEFAULT_MQTT_SENDING_INTERVAL; @@ -201,7 +224,7 @@ void App::setup() #if defined(BOARD_TYPE_OBI_V2) || defined(BOARD_TYPE_DEV1) || \ defined(BOARD_TYPE_BW_SHP6) || defined(BOARD_TYPE_BW_SHP6_V11) || \ - defined(BOARD_TYPE_SHELLY1) || defined(BOARD_TYPE_GEBA_01SWP) || \ + defined(BOARD_TYPE_SHELLY1) || defined(BOARD_TYPE_GEBA_01SWP) || \ defined(BOARD_TYPE_SONOFF_BASIC) #ifdef POWER_LED @@ -222,12 +245,8 @@ void App::setup() Serial.println(); } - Serial.println("\n\n"); - Serial.println("\n\n"); - Serial.println(F(APP_NAME ", Version " APP_VERSION ", by " APP_AUTHOR)); - Serial.println("Build date: " __DATE__ " " __TIME__); - Serial.printf("appcfg file size: %d bytes\n\n", sizeof(appcfg)); - + appShowHeader(Serial); + Serial.printf("appcfg size: %d bytes\n\n", sizeof(appcfg)); showChipInfo(); if (LittleFS.begin()) @@ -292,16 +311,16 @@ void App::setup() /////////////////////////////////////////////////////////////// #ifdef OVERRIDE_WIFI_SETTINGS appcfg.wifi_mode = OVERRIDE_WIFI_MODE; - strcpy( appcfg.wifi_ssid, OVERRIDE_WIFI_SSID ); - strcpy( appcfg.wifi_password, OVERRIDE_WIFI_PASSWORD ); + strcpy(appcfg.wifi_ssid, OVERRIDE_WIFI_SSID); + strcpy(appcfg.wifi_password, OVERRIDE_WIFI_PASSWORD); appcfg.ota_enabled = OVERRIDE_OTA_ENABLED; #endif -/////////////////////////////////////////////////////////////// - - formatChipId( appcfg.ota_hostname ); - formatChipId( appcfg.mqtt_clientid ); - formatChipId( appcfg.mqtt_intopic ); - formatChipId( appcfg.mqtt_outtopic ); + /////////////////////////////////////////////////////////////// + + formatChipId(appcfg.ota_hostname); + formatChipId(appcfg.mqtt_clientid); + formatChipId(appcfg.mqtt_intopic); + formatChipId(appcfg.mqtt_outtopic); memcpy(&appcfgWR, &appcfg, sizeof(appcfg)); } @@ -398,11 +417,12 @@ void App::writeConfig() #endif j.writeEntry(A_mqtt_sending_interval, appcfgWR.mqtt_sending_interval); +/* j.writeEntry(A_syslog_enabled, appcfgWR.syslog_enabled); j.writeEntry(A_syslog_host, appcfgWR.syslog_host); j.writeEntry(A_syslog_port, appcfgWR.syslog_port); j.writeEntry(A_syslog_app_name, appcfgWR.syslog_app_name); - +*/ #ifdef POWER_BUTTON_IS_MULTIMODE j.writeEntry(A_power_button_mode, appcfgWR.power_button_mode); #endif @@ -495,12 +515,14 @@ void App::printConfig(AppConfig ac) #endif Serial.printf(" Sending Interval: %ld\n", ac.mqtt_sending_interval); +/* Serial.println("\n Syslog:"); Serial.printf(" Enabled: %s\n", (ac.syslog_enabled ? "true" : "false")); Serial.printf(" Host: %s\n", ac.syslog_host); Serial.printf(" Port: %d\n", ac.syslog_port); Serial.printf(" App Name: %s\n", ac.syslog_app_name); +*/ #ifdef POWER_BUTTON_IS_MULTIMODE Serial.println("\n Power button:"); Serial.printf(" Mode: %d\n", ac.power_button_mode); @@ -621,10 +643,12 @@ bool App::loadJsonConfig(const char *filename) #endif readError |= j.readEntryULong(attributeName, A_mqtt_sending_interval, &appcfgRD.mqtt_sending_interval); +/* readError |= j.readEntryBoolean(attributeName, A_syslog_enabled, &appcfgRD.syslog_enabled); readError |= j.readEntryChars(attributeName, A_syslog_host, appcfgRD.syslog_host); readError |= j.readEntryInteger(attributeName, A_syslog_port, &appcfgRD.syslog_port); readError |= j.readEntryChars(attributeName, A_syslog_app_name, appcfgRD.syslog_app_name); +*/ #ifdef POWER_BUTTON_IS_MULTIMODE readError |= j.readEntryInteger(attributeName, A_power_button_mode, &appcfgRD.power_button_mode); diff --git a/lib/App/App.hpp b/lib/App/App.hpp index 81133a3..b1231a8 100644 --- a/lib/App/App.hpp +++ b/lib/App/App.hpp @@ -32,62 +32,74 @@ extern const char *appUptime(); +#define BUFFER_LENGTH 4096 +#define BUFFER2_LENGTH 256 + +extern char *buffer; +extern char *buffer2; +extern void appMemoryInit(); +extern void appMemoryFree(); + +#define ATTRIBUTE_SIZE 40 + typedef struct appconfig { - char wifi_ssid[64]; - char wifi_password[64]; + char wifi_ssid[ATTRIBUTE_SIZE]; + char wifi_password[ATTRIBUTE_SIZE]; int wifi_mode; int net_mode; - char net_host[64]; - char net_mask[64]; - char net_gateway[64]; - char net_dns[64]; + char net_host[ATTRIBUTE_SIZE]; + char net_mask[ATTRIBUTE_SIZE]; + char net_gateway[ATTRIBUTE_SIZE]; + char net_dns[ATTRIBUTE_SIZE]; bool ota_enabled; - char ota_hostname[64]; - char ota_password[64]; + char ota_hostname[ATTRIBUTE_SIZE]; + char ota_password[ATTRIBUTE_SIZE]; - char admin_password[64]; + char admin_password[ATTRIBUTE_SIZE]; bool ohab_enabled; int ohab_version; - char ohab_host[64]; + char ohab_host[ATTRIBUTE_SIZE]; int ohab_port; bool ohab_useauth; - char ohab_user[64]; - char ohab_password[64]; - char ohab_itemname[64]; + char ohab_user[ATTRIBUTE_SIZE]; + char ohab_password[ATTRIBUTE_SIZE]; + char ohab_itemname[ATTRIBUTE_SIZE]; #ifdef HAVE_ENERGY_SENSOR - char ohab_item_voltage[64]; - char ohab_item_current[64]; - char ohab_item_power[64]; + char ohab_item_voltage[ATTRIBUTE_SIZE]; + char ohab_item_current[ATTRIBUTE_SIZE]; + char ohab_item_power[ATTRIBUTE_SIZE]; unsigned long ohab_sending_interval; #endif bool alexa_enabled; - char alexa_devicename[64]; + char alexa_devicename[ATTRIBUTE_SIZE]; bool mqtt_enabled; - char mqtt_clientid[64]; - char mqtt_host[64]; + char mqtt_clientid[ATTRIBUTE_SIZE]; + char mqtt_host[ATTRIBUTE_SIZE]; int mqtt_port; bool mqtt_useauth; - char mqtt_user[64]; - char mqtt_password[64]; - char mqtt_intopic[64]; - char mqtt_outtopic[64]; + char mqtt_user[ATTRIBUTE_SIZE]; + char mqtt_password[ATTRIBUTE_SIZE]; + char mqtt_intopic[ATTRIBUTE_SIZE]; + char mqtt_outtopic[ATTRIBUTE_SIZE]; #ifdef HAVE_ENERGY_SENSOR - char mqtt_topic_voltage[64]; - char mqtt_topic_current[64]; - char mqtt_topic_power[64]; - char mqtt_topic_json[64]; + char mqtt_topic_voltage[ATTRIBUTE_SIZE]; + char mqtt_topic_current[ATTRIBUTE_SIZE]; + char mqtt_topic_power[ATTRIBUTE_SIZE]; + char mqtt_topic_json[ATTRIBUTE_SIZE]; #endif unsigned long mqtt_sending_interval; +/* bool syslog_enabled; - char syslog_host[64]; + char syslog_host[ATTRIBUTE_SIZE]; int syslog_port; - char syslog_app_name[64]; + char syslog_app_name[ATTRIBUTE_SIZE]; +*/ #ifdef POWER_BUTTON_IS_MULTIMODE int power_button_mode; diff --git a/lib/MicroJson/MicroJson.cpp b/lib/MicroJson/MicroJson.cpp index 35252ce..3d96e7a 100644 --- a/lib/MicroJson/MicroJson.cpp +++ b/lib/MicroJson/MicroJson.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -178,11 +179,11 @@ bool uJson::readEntryChars(const char *n1, const char *n2, char *value) { int i = 0; int r; - while ((r = file.read()) >= 0 && r != '"' && i < 64) + while ((r = file.read()) >= 0 && r != '"' && i < ATTRIBUTE_SIZE) { value[i++] = r; } - if (r == '"' && i < 64) + if (r == '"' && i < ATTRIBUTE_SIZE) { value[i] = 0; return false; diff --git a/lib/Util/Util.cpp b/lib/Util/Util.cpp index a34cb1a..dc53cdf 100644 --- a/lib/Util/Util.cpp +++ b/lib/Util/Util.cpp @@ -3,15 +3,6 @@ extern void sendPrint(const char *message); -char buffer[BUFFER_LENGTH+1]; -char buffer2[BUFFER2_LENGTH+1]; - -#define MAX_MESSAGE_LENGTH 200 -#define MESSAGE_BUFFER_LINES 11 -char messageBuffer[(MAX_MESSAGE_LENGTH + 1) * MESSAGE_BUFFER_LINES]; -int messageStartIndex = 0; -int messageEndIndex = 0; - /* Find the description about the boot device code here: https://www.sigmdel.ca/michel/program/esp8266/arduino/watchdogs2_en.html diff --git a/lib/Util/Util.hpp b/lib/Util/Util.hpp index 9f362da..584c888 100644 --- a/lib/Util/Util.hpp +++ b/lib/Util/Util.hpp @@ -3,15 +3,6 @@ #include -#define MAX_MESSAGE_LENGTH 200 -#define MESSAGE_BUFFER_LINES 11 -#define BUFFER_LENGTH 4096 -#define BUFFER2_LENGTH 256 - -extern char messageBuffer[]; -extern int messageStartIndex; -extern int messageEndIndex; - extern int getBootDevice(void); extern void alterPin(int pin); extern void showChipInfo(); @@ -19,7 +10,4 @@ extern void fillBuffer(const char *message); extern void sendHtmlTemplate(const char *htmlTemplate, const char *(*setupProcessor)(const char *)); -extern char buffer[]; -extern char buffer2[]; - #endif diff --git a/lib/WebHandler/WebHandler.cpp b/lib/WebHandler/WebHandler.cpp index 0b73491..5261222 100644 --- a/lib/WebHandler/WebHandler.cpp +++ b/lib/WebHandler/WebHandler.cpp @@ -21,13 +21,11 @@ #include #include #include +#include const char META_REFRESH30[] PROGMEM = ""; -static struct uzlib_uncomp uzLibDecompressor; -static uint32_t uzlib_bytesleft; - size_t fsTotalBytes; size_t fsUsedBytes; @@ -54,8 +52,8 @@ const char *getJsonStatus(WiFiClient *client) int wifi_signal = (wifi_rssi < -100) ? -100 : wifi_rssi; wifi_signal = (wifi_signal > -50) ? 100 : 2 * (wifi_signal+100); - sprintf(buffer, - "{" + sprintf_P(buffer, + PSTR("{" "\"millis\":%lu," "\"uptime\":\"%s\"," "\"host_name\":\"%s.local\"," @@ -94,7 +92,7 @@ const char *getJsonStatus(WiFiClient *client) "\"free_sketch_space\":%u," "\"remote_client_ip\":\"%s\"," "\"remote_client_port\":%u" - "}", + "}"), millis(), appUptime(), wifiHandler.getHostname(), ESP.getFullVersion().c_str(), ESP.getCoreVersion().c_str(), ESP.getSdkVersion(), PIOENV, PIOPLATFORM, PIOFRAMEWORK, @@ -116,8 +114,11 @@ const char *getJsonStatus(WiFiClient *client) int sendUncompressed( const uint8_t *compressedData, const uint32_t compressedDataLength) { uzlib_init(); - uzLibDecompressor.source = compressedData; - uzLibDecompressor.source_limit = compressedData + compressedDataLength; + struct uzlib_uncomp *uzLibDecompressor = (struct uzlib_uncomp *)malloc(sizeof(struct uzlib_uncomp)); + uint32_t uzlib_bytesleft; + + uzLibDecompressor->source = compressedData; + uzLibDecompressor->source_limit = compressedData + compressedDataLength; uzlib_bytesleft = 0; for( int i=1; i<5; i++ ) @@ -127,25 +128,28 @@ int sendUncompressed( const uint8_t *compressedData, const uint32_t compressedDa } // Serial.printf("decompressed file length = %u\n", uzlib_bytesleft ); - uzlib_uncompress_init(&uzLibDecompressor, buffer, BUFFER_LENGTH ); + uzlib_uncompress_init(uzLibDecompressor, buffer, BUFFER_LENGTH ); - int res = uzlib_gzip_parse_header(&uzLibDecompressor); + int res = uzlib_gzip_parse_header(uzLibDecompressor); if (res != 0) { Serial.println("[ERROR] in gzUncompress: uzlib_gzip_parse_header failed!"); + free(uzLibDecompressor); return res; } while( uzlib_bytesleft > 0 ) { - uzLibDecompressor.dest_start = (unsigned char *)buffer2; - uzLibDecompressor.dest = (unsigned char *)buffer2; + uzLibDecompressor->dest_start = (unsigned char *)buffer2; + uzLibDecompressor->dest = (unsigned char *)buffer2; int to_read = ( uzlib_bytesleft > BUFFER2_LENGTH) ? BUFFER2_LENGTH : uzlib_bytesleft; - uzLibDecompressor.dest_limit = (unsigned char *)buffer2 + to_read; - uzlib_uncompress(&uzLibDecompressor); + uzLibDecompressor->dest_limit = (unsigned char *)buffer2 + to_read; + uzlib_uncompress(uzLibDecompressor); buffer2[to_read] = 0; server.sendContent(buffer2); uzlib_bytesleft -= to_read; } + + free(uzLibDecompressor); return 0; } @@ -161,6 +165,10 @@ void sendHeader(const char *title, bool sendMetaRefresh, const char *style) server.sendContent_P(META_REFRESH30); } + server.sendContent_P(PSTR("\n")); + if (style != nullptr) { server.sendContent_P(style); @@ -220,9 +228,16 @@ void sendPrint(const char *message) server.sendContent(message); } -void sendLegend(const char *name) +void sendPrint_P(PGM_P message) +{ + server.sendContent_P(message); +} + +void sendLegend_P(PGM_P name) { - sendPrintf("%s", name); + server.sendContent_P(PSTR("")); + server.sendContent_P(name); + server.sendContent_P(PSTR("")); } void sendGroupLabel( int id, const char *label ) diff --git a/lib/WebPages/FirmwareUpload.cpp b/lib/WebPages/FirmwareUpload.cpp index 124575d..9c922e4 100644 --- a/lib/WebPages/FirmwareUpload.cpp +++ b/lib/WebPages/FirmwareUpload.cpp @@ -3,13 +3,13 @@ #include "WebPages.h" bool firmwareUploadFailed; -const char *firmwareUploadErrorMessage; +PGM_P firmwareUploadErrorMessage; -static const char ERROR_UNDEFINED[] = "Undefined"; -static const char ERROR_FILE_SIZE_ZERO[] = "Firmware file size is zero"; -static const char ERROR_INVALID_FILENAME[] = "Invalid firmware filename"; -static const char ERROR_NOT_ENOUGH_MEMORY[] = "Not enough memory"; -static const char ERROR_WRONG_FILE_FORMAT[] = "Wrong file format"; +PGM_P ERROR_UNDEFINED PROGMEM = "Undefined"; +PGM_P ERROR_FILE_SIZE_ZERO PROGMEM = "Firmware file size is zero"; +PGM_P ERROR_INVALID_FILENAME PROGMEM = "Invalid firmware filename"; +PGM_P ERROR_NOT_ENOUGH_MEMORY PROGMEM = "Not enough memory"; +PGM_P ERROR_WRONG_FILE_FORMAT PROGMEM = "Wrong file format"; static bool uploadError; diff --git a/lib/WebPages/FirmwareUploadSuccess.cpp b/lib/WebPages/FirmwareUploadSuccess.cpp index 66b077d..5c88349 100644 --- a/lib/WebPages/FirmwareUploadSuccess.cpp +++ b/lib/WebPages/FirmwareUploadSuccess.cpp @@ -1,26 +1,26 @@ #include "WebPages.h" extern bool firmwareUploadFailed; -extern char *firmwareUploadErrorMessage; +extern PGM_P firmwareUploadErrorMessage; void handleFirmwareUploadSuccess() { sendAuthentication(); sendHeader(APP_NAME " - Firmware upload", true); - sendPrint("
"); + sendPrint_P(""); if (firmwareUploadFailed) { - sendLegend("Firmware upload FAILED!"); - sendPrint("

ERROR: "); - sendPrint(firmwareUploadErrorMessage); - sendPrint(".

"); + sendLegend_P(PSTR("Firmware upload FAILED!")); + sendPrint_P(PSTR("

ERROR: ")); + sendPrint_P(firmwareUploadErrorMessage); + sendPrint_P(PSTR(".

")); sendFooter(); } else { - sendLegend("Firmware successfully uploaded."); - sendPrint("

Restarting System ... takes about 30s

"); + sendLegend_P(PSTR("Firmware successfully uploaded.")); + sendPrint_P(PSTR("

Restarting System ... takes about 30s

")); sendFooter(); delay(1000); ESP.restart(); diff --git a/lib/WebPages/InfoPage.cpp b/lib/WebPages/InfoPage.cpp index 629dab4..1420d9a 100644 --- a/lib/WebPages/InfoPage.cpp +++ b/lib/WebPages/InfoPage.cpp @@ -3,21 +3,21 @@ void handleInfoPage() { sendHeader(APP_NAME " - Info"); - sendPrint("
"); - sendLegend("Application"); - sendPrint( + sendPrint_P(PSTR("")); + sendLegend_P(PSTR("Application")); + sendPrint_P(PSTR( "

Name: " APP_NAME "

" "

Version: " APP_VERSION "

" "

PlatformIO Environment: " PIOENV "

" - "

Author: Dr. Thorsten Ludewig <t.ludewig@gmail.com>

"); + "

Author: Dr. Thorsten Ludewig <t.ludewig@gmail.com>

")); - sendLegend("Build"); - sendPrint("

Date: " __DATE__ "

" - "

Time: " __TIME__ "

"); + sendLegend_P(PSTR("Build")); + sendPrint_P(PSTR("

Date: " __DATE__ "

" + "

Time: " __TIME__ "

")); - sendLegend("RESTful API"); + sendLegend_P(PSTR("RESTful API")); - sendPrint("

Legacy API - Returns in JSON format

"); + sendPrint_P(PSTR("

Legacy API - Returns in JSON format

")); sendPrintf( "

http://%s/info - ESP8266 Info

", @@ -35,8 +35,8 @@ void handleInfoPage() "

http://%s/state

", WiFi.localIP().toString().c_str(), WiFi.localIP().toString().c_str()); - sendPrint("

 

"); - sendPrint("

JSON API - Returns status in JSON format

"); + sendPrint_P(PSTR("

 

")); + sendPrint_P(PSTR("

JSON API - Returns status in JSON format

")); sendPrintf( "

http://%s/api/json - HTTP_POST socket (ON or OFF)

", @@ -62,8 +62,8 @@ void handleInfoPage() "

http://%s/state

", WiFi.localIP().toString().c_str(), WiFi.localIP().toString().c_str()); - sendPrint("

 

"); - sendPrint("

Plain text API - Returns status in plain text format

"); + sendPrint_P(PSTR("

 

")); + sendPrint_P(PSTR("

Plain text API - Returns status in plain text format

")); sendPrintf( "

http://%s/api/plain - HTTP_POST socket (ON or OFF)

", @@ -89,7 +89,7 @@ void handleInfoPage() "

http://%s/plain/state

", WiFi.localIP().toString().c_str(), WiFi.localIP().toString().c_str()); - sendLegend("Services"); + sendLegend_P(PSTR("Services")); sendPrintf("

OTA Enabled: %s

", (appcfg.ota_enabled) ? "true" : "false"); @@ -102,6 +102,6 @@ void handleInfoPage() // sendPrintf("

Syslog Enabled: %s

", // (appcfg.syslog_enabled) ? "true" : "false"); - sendPrint("
"); + sendPrint_P(PSTR("")); sendFooter(); } diff --git a/lib/WebPages/ResetFirmware.cpp b/lib/WebPages/ResetFirmware.cpp index 83093a8..e82eddc 100644 --- a/lib/WebPages/ResetFirmware.cpp +++ b/lib/WebPages/ResetFirmware.cpp @@ -4,19 +4,19 @@ void handleResetFirmware() { sendAuthentication(); sendHeader(APP_NAME " - Reset Firmware", true); - sendPrint("
"); - sendLegend("Reset Firmware."); + sendPrint_P(PSTR("")); + sendLegend_P(PSTR("Reset Firmware.")); if (strcmp("true", server.arg(0).c_str()) == 0) { - sendPrint("

Resetting firmware... restart takes about 30sec.

"); + sendPrint_P(PSTR("

Resetting firmware... restart takes about 30sec.

")); app.firmwareReset(); } else { - sendPrint("If you really want to reset to system defaults, you must select 'Yes' on the maintenance page."); + sendPrint_P(PSTR("If you really want to reset to system defaults, you must select 'Yes' on the maintenance page.")); } - sendPrint("
"); + sendPrint_P(PSTR("")); sendFooter(); } diff --git a/lib/WebPages/RestoreConfiguration.cpp b/lib/WebPages/RestoreConfiguration.cpp index f1a0740..7458ecc 100644 --- a/lib/WebPages/RestoreConfiguration.cpp +++ b/lib/WebPages/RestoreConfiguration.cpp @@ -4,9 +4,9 @@ void handleRestoreConfiguration() { sendAuthentication(); sendHeader(APP_NAME " - Restore Config", true); - sendPrint("
"); - sendLegend("Configuration successfully restored."); - sendPrint("

Restarting System ... takes about 30s

"); + sendPrint_P(PSTR("
")); + sendLegend_P(PSTR("Configuration successfully restored.")); + sendPrint_P(PSTR("

Restarting System ... takes about 30s

")); sendFooter(); if (app.loadJsonConfig(APP_CONFIG_FILE_JSON) == false) diff --git a/lib/WebPages/SaveConfig.cpp b/lib/WebPages/SaveConfig.cpp index 8dff19f..ad5f8ca 100644 --- a/lib/WebPages/SaveConfig.cpp +++ b/lib/WebPages/SaveConfig.cpp @@ -6,8 +6,8 @@ void paramChars(char *dest, const char *paramName, const char *name, const char { if (strcmp(name, paramName) == 0) { - strncpy(dest, value, 63); - dest[63] = 0; + strncpy(dest, value, (ATTRIBUTE_SIZE-1)); + dest[(ATTRIBUTE_SIZE-1)] = 0; } } @@ -97,24 +97,17 @@ void storeConfigValue(const char *name, const char *value) paramChars(appcfgWR.ohab_user, A_ohab_user, name, value); paramChars(appcfgWR.ohab_password, A_ohab_password, name, value); -#ifdef HAVE_ENERGY_SENSOR -/* - paramChars(request, appcfgWR.ohab_item_voltage, A_ohab_item_voltage, DEFAULT_OHAB_ITEM_VOLTAGE); - paramChars(request, appcfgWR.ohab_item_current, A_ohab_item_current, DEFAULT_OHAB_ITEM_CURRENT); - paramChars(request, appcfgWR.ohab_item_power, A_ohab_item_power, DEFAULT_OHAB_ITEM_POWER); - appcfgWR.ohab_sending_interval = paramInt(request, A_ohab_sending_interval, DEFAULT_OHAB_SENDING_INTERVAL); -*/ -#endif - // Alexa paramBool(&appcfgWR.alexa_enabled, A_alexa_enabled, name, value); paramChars(appcfgWR.alexa_devicename, A_alexa_devicename, name, value); // Syslog + /* paramBool(&appcfgWR.syslog_enabled, A_syslog_enabled, name, value); paramChars(appcfgWR.syslog_host, A_syslog_host, name, value); paramInt(&appcfgWR.syslog_port, A_syslog_port, name, value); paramChars(appcfgWR.syslog_app_name, A_syslog_app_name, name, value); +*/ #ifdef POWER_BUTTON_IS_MULTIMODE paramInt(&appcfgWR.power_button_mode, A_power_button_mode, name, value); @@ -134,11 +127,11 @@ void handleSaveConfigPage() { sendAuthentication(); sendHeader(APP_NAME " - Save Config", true); - sendPrint("
"); - sendLegend("Configuration saved."); + sendPrint_P(PSTR("")); + sendLegend_P(PSTR("Configuration saved.")); int numberOfArguments = server.args(); - sendPrint("
");
+  sendPrint_P(PSTR("
"));
 
   memset(&appcfgWR, 0, sizeof(appcfgWR));
 
@@ -150,161 +143,7 @@ void handleSaveConfigPage()
     sendPrintf("%2d. %s = %s\n", (i + 1), argName, argValue);
   }
 
-  sendPrint("

Restarting System ... takes about 30s

"); + sendPrint_P(PSTR("

Restarting System ... takes about 30s

")); sendFooter(); app.delayedSystemRestart(); } - - - - -/* -void paramChars(AsyncWebServerRequest *request, char *dest, - const char *paramName, const char *defaultValue) -{ - const char *value = defaultValue; - - if (request->hasParam(paramName, true)) - { - AsyncWebParameter *p = request->getParam(paramName, true); - value = p->value().c_str(); - if (value == 0 || strlen(value) == 0) - { - value = defaultValue; - } - } - - strncpy(dest, value, 63); - dest[63] = 0; -} - -int paramInt(AsyncWebServerRequest *request, const char *paramName, - int defaultValue) -{ - int value = defaultValue; - - if (request->hasParam(paramName, true)) - { - AsyncWebParameter *p = request->getParam(paramName, true); - const char *pv = p->value().c_str(); - if (pv != 0 && strlen(pv) > 0) - { - value = atoi(pv); - } - } - - return value; -} - -void handleSavePage(AsyncWebServerRequest *request) -{ - if (!request->authenticate("admin", appcfg.admin_password)) - { - return request->requestAuthentication(); - } - - - // Security - paramChars(request, appcfgWR.admin_password, A_admin_password, - DEFAULT_ADMIN_PASSWORD); - - // WIFI - appcfgWR.wifi_mode = paramInt(request, A_wifi_mode, DEFAULT_WIFI_MODE); - paramChars(request, appcfgWR.wifi_ssid, A_wifi_ssid, DEFAULT_WIFI_SSID); - paramChars(request, appcfgWR.wifi_password, A_wifi_password, - DEFAULT_WIFI_PASSWORD); - - // Network - appcfgWR.net_mode = paramInt(request, A_net_mode, DEFAULT_NET_MODE); - paramChars(request, appcfgWR.net_host, A_net_host, DEFAULT_NET_HOST); - paramChars(request, appcfgWR.net_gateway, A_net_gateway, DEFAULT_NET_GATEWAY); - paramChars(request, appcfgWR.net_mask, A_net_mask, DEFAULT_NET_MASK); - paramChars(request, appcfgWR.net_dns, A_net_dns, DEFAULT_NET_DNS); - - // OTA - paramChars(request, appcfgWR.ota_hostname, A_ota_hostname, - DEFAULT_OTA_HOSTNAME); - paramChars(request, appcfgWR.ota_password, A_ota_password, - DEFAULT_OTA_PASSWORD); - - // OpenHAB - appcfgWR.ohab_enabled = paramBool(request, A_ohab_enabled); - appcfgWR.ohab_version = - paramInt(request, A_ohab_version, DEFAULT_OHAB_VERSION); - paramChars(request, appcfgWR.ohab_itemname, A_ohab_itemname, - DEFAULT_OHAB_ITEMNAME); - paramChars(request, appcfgWR.ohab_host, A_ohab_host, DEFAULT_OHAB_HOST); - appcfgWR.ohab_port = paramInt(request, A_ohab_port, DEFAULT_OHAB_PORT); - appcfgWR.ohab_useauth = paramBool(request, A_ohab_useauth); - paramChars(request, appcfgWR.ohab_user, A_ohab_user, DEFAULT_OHAB_USER); - paramChars(request, appcfgWR.ohab_password, A_ohab_password, - DEFAULT_OHAB_PASSWORD); - -#ifdef HAVE_ENERGY_SENSOR - paramChars(request, appcfgWR.ohab_item_voltage, A_ohab_item_voltage, DEFAULT_OHAB_ITEM_VOLTAGE); - paramChars(request, appcfgWR.ohab_item_current, A_ohab_item_current, DEFAULT_OHAB_ITEM_CURRENT); - paramChars(request, appcfgWR.ohab_item_power, A_ohab_item_power, DEFAULT_OHAB_ITEM_POWER); - appcfgWR.ohab_sending_interval = paramInt(request, A_ohab_sending_interval, DEFAULT_OHAB_SENDING_INTERVAL); -#endif - - // Alexa - appcfgWR.alexa_enabled = paramBool(request, A_alexa_enabled); - paramChars(request, appcfgWR.alexa_devicename, A_alexa_devicename, - DEFAULT_ALEXA_DEVICENAME); - - // MQTT - appcfgWR.mqtt_enabled = paramBool(request, A_mqtt_enabled); - paramChars(request, appcfgWR.mqtt_clientid, A_mqtt_clientid, - DEFAULT_MQTT_CLIENTID); - paramChars(request, appcfgWR.mqtt_host, A_mqtt_host, DEFAULT_MQTT_HOST); - appcfgWR.mqtt_port = paramInt(request, A_mqtt_port, DEFAULT_MQTT_PORT); - appcfgWR.mqtt_useauth = paramBool(request, A_mqtt_useauth); - paramChars(request, appcfgWR.mqtt_user, A_mqtt_user, DEFAULT_MQTT_USER); - paramChars(request, appcfgWR.mqtt_password, A_mqtt_password, - DEFAULT_MQTT_PASSWORD); - paramChars(request, appcfgWR.mqtt_intopic, A_mqtt_intopic, - DEFAULT_MQTT_INTOPIC); - paramChars(request, appcfgWR.mqtt_outtopic, A_mqtt_outtopic, - DEFAULT_MQTT_OUTTOPIC); - -#ifdef HAVE_ENERGY_SENSOR - paramChars(request, appcfgWR.mqtt_topic_voltage, A_mqtt_topic_voltage, DEFAULT_MQTT_TOPIC_VOLTAGE); - paramChars(request, appcfgWR.mqtt_topic_current, A_mqtt_topic_current, DEFAULT_MQTT_TOPIC_CURRENT); - paramChars(request, appcfgWR.mqtt_topic_power, A_mqtt_topic_power, DEFAULT_MQTT_TOPIC_POWER); - paramChars(request, appcfgWR.mqtt_topic_json, A_mqtt_topic_json, DEFAULT_MQTT_TOPIC_JSON); - appcfgWR.mqtt_sending_interval = paramInt(request, A_mqtt_sending_interval, DEFAULT_MQTT_SENDING_INTERVAL); -#endif - - // Syslog - appcfgWR.syslog_enabled = paramBool(request, A_syslog_enabled); - paramChars(request, appcfgWR.syslog_host, A_syslog_host, DEFAULT_SYSLOG_HOST); - appcfgWR.syslog_port = paramInt(request, A_syslog_port, DEFAULT_SYSLOG_PORT); - paramChars(request, appcfgWR.syslog_app_name, A_syslog_app_name, - DEFAULT_SYSLOG_APP_NAME); - -#ifdef POWER_BUTTON_IS_MULTIMODE - appcfgWR.power_button_mode = paramInt(request, A_power_button_mode, DEFAULT_POWER_BUTTON_MODE); -#endif - -#ifdef WIFI_LED - appcfgWR.led_night_mode_enabled = paramBool(request, A_led_night_mode_enabled); - appcfgWR.led_night_mode_timeout = paramInt(request, A_led_night_mode_timeout, DEFAULT_LED_NIGHT_MODE_TIMEOUT); -#endif - - appcfgWR.inet_check_enabled = paramBool(request, A_inet_check_enabled); - appcfgWR.inet_check_period = paramInt(request, A_inet_check_period, DEFAULT_INET_CHECK_PERIOD); - appcfgWR.inet_check_action = paramInt(request, A_inet_check_action, DEFAULT_INET_CHECK_ACTION); - - AsyncResponseStream *response = request->beginResponseStream("text/html"); - response->print(TEMPLATE_HEADER); - response->print(META_REFRESH); - response->printf( TEMPLATE_BODY, APP_NAME " - Save Configuration" ); - response->println("

Configuration saved.

"); - response->println("

Restarting System ... takes about 30s

"); - response->print(TEMPLATE_FOOTER); - app.delayedSystemRestart(); - LOG0( "*** save config parsed ... sending response\n" ); - request->send(response); -} - -*/ diff --git a/lib/WebPages/SetupPage.cpp b/lib/WebPages/SetupPage.cpp index af0daae..c28fc83 100644 --- a/lib/WebPages/SetupPage.cpp +++ b/lib/WebPages/SetupPage.cpp @@ -143,6 +143,7 @@ static const char *setupProcessor(const char *var) } // Syslog + /* if (strcmp(var, A_syslog_enabled) == 0 && appcfg.syslog_enabled == true) return checked; if (strcmp(var, A_syslog_host) == 0) @@ -159,7 +160,7 @@ static const char *setupProcessor(const char *var) sprintf(buffer, "%lu", millis()); return buffer; } - +*/ #ifdef WIFI_LED @@ -197,196 +198,3 @@ void handleSetupPage() sendHtmlTemplate(SETUP_HTML_TEMPLATE, setupProcessor); sendFooter(); } - - -/* -String setupProcessor(const String &var) -{ - String selected = F("selected"); - String checked = F("checked"); - - if (var == A_admin_password) - return String(appcfg.admin_password); - - // Wifi - if (var == "wifi_mode_ap" && appcfg.wifi_mode == WIFI_AP) - return selected; - if (var == "wifi_mode_station" && appcfg.wifi_mode == WIFI_STA) - return selected; - - if (var == "scanned_network_options") - { - ListNode *node = wifiHandler.getScannedNetworks(); - String options = ""; - - while (node != NULL) - { - options += F(""); - node = node->next; - } - - return options; - } - - if (var == A_wifi_ssid) - return String(appcfg.wifi_ssid); - if (var == A_wifi_password) - return String(appcfg.wifi_password); - - // Network - if (var == "net_mode_dhcp" && appcfg.net_mode == NET_MODE_DHCP) - return selected; - if (var == "net_mode_static" && appcfg.net_mode == NET_MODE_STATIC) - return selected; - if (var == A_net_host) - return String(appcfg.net_host); - if (var == A_net_gateway) - return String(appcfg.net_gateway); - if (var == A_net_mask) - return String(appcfg.net_mask); - if (var == A_net_dns) - return String(appcfg.net_dns); - - // OTA - if (var == A_ota_hostname) - return String(appcfg.ota_hostname); - if (var == A_ota_password) - return String(appcfg.ota_password); - - // OpenHAB - if (var == A_ohab_enabled && appcfg.ohab_enabled == true) - return checked; - if (var == "ohab_v1" && appcfg.ohab_version == 1) - return selected; - if (var == "ohab_v2" && appcfg.ohab_version == 2) - return selected; - if (var == A_ohab_itemname) - return String(appcfg.ohab_itemname); - if (var == A_ohab_host) - return String(appcfg.ohab_host); - if (var == A_ohab_port) - return String(appcfg.ohab_port); - if (var == A_ohab_useauth && appcfg.ohab_useauth == true) - return checked; - if (var == A_ohab_user) - return String(appcfg.ohab_user); - if (var == A_ohab_password) - return String(appcfg.ohab_password); - -#ifdef HAVE_ENERGY_SENSOR - if (var == A_ohab_item_voltage) - return String(appcfg.ohab_item_voltage); - if (var == A_ohab_item_current) - return String(appcfg.ohab_item_current); - if (var == A_ohab_item_power) - return String(appcfg.ohab_item_power); - if (var == A_ohab_sending_interval) - return String(appcfg.ohab_sending_interval); -#endif - - // Alexa - if (var == A_alexa_enabled && appcfg.alexa_enabled == true) - return checked; - if (var == A_alexa_devicename) - return String(appcfg.alexa_devicename); - - // MQTT - if (var == A_mqtt_enabled && appcfg.mqtt_enabled == true) - return checked; - if (var == A_mqtt_clientid) - return String(appcfg.mqtt_clientid); - if (var == A_mqtt_host) - return String(appcfg.mqtt_host); - if (var == A_mqtt_port) - return String(appcfg.mqtt_port); - if (var == A_mqtt_useauth && appcfg.mqtt_useauth == true) - return checked; - if (var == A_mqtt_user) - return String(appcfg.mqtt_user); - if (var == A_mqtt_password) - return String(appcfg.mqtt_password); - if (var == A_mqtt_intopic) - return String(appcfg.mqtt_intopic); - if (var == A_mqtt_outtopic) - return String(appcfg.mqtt_outtopic); -#ifdef HAVE_ENERGY_SENSOR - if (var == A_mqtt_topic_voltage) - return String(appcfg.mqtt_topic_voltage); - if (var == A_mqtt_topic_current) - return String(appcfg.mqtt_topic_current); - if (var == A_mqtt_topic_power) - return String(appcfg.mqtt_topic_power); - if (var == A_mqtt_topic_json) - return String(appcfg.mqtt_topic_json); - if (var == A_mqtt_sending_interval) - return String(appcfg.mqtt_sending_interval); -#endif - - // Syslog - if (var == A_syslog_enabled && appcfg.syslog_enabled == true) - return checked; - if (var == A_syslog_host) - return String(appcfg.syslog_host); - if (var == A_syslog_port) - return String(appcfg.syslog_port); - if (var == A_syslog_app_name) - return String(appcfg.syslog_app_name); - - if (var == "millis") - return String(millis()); - -#ifdef POWER_BUTTON_IS_MULTIMODE - // Power Button Mode - if (var == "power_button_mode_switch" && appcfg.power_button_mode == POWER_BUTTON_MODE_SWITCH) - return selected; - if (var == "power_button_mode_toggle" && appcfg.power_button_mode == POWER_BUTTON_MODE_TOGGLE) - return selected; - if (var == "power_button_mode_toggle_switch" && appcfg.power_button_mode == POWER_BUTTON_MODE_TOGGLE_SWITCH) - return selected; -#endif - -#ifdef WIFI_LED - if (var == A_led_night_mode_enabled && appcfg.led_night_mode_enabled == true) - return checked; - if (var == A_led_night_mode_timeout) - return String(appcfg.led_night_mode_timeout); -#endif - - if (var == A_inet_check_enabled && appcfg.inet_check_enabled == true) - return checked; - if (var == A_inet_check_period) - return String(appcfg.inet_check_period); - - String ica = String( A_inet_check_action ); - ica += "_"; - ica += appcfg.inet_check_action; - - if ( var == ica ) - return selected; - - return String(); -} - -void handleSetupPage(AsyncWebServerRequest *request) -{ - LOG0("handleSetupPage\n"); - if (!request->authenticate("admin", appcfg.admin_password)) - { - LOG0("authenticate\n"); - return request->requestAuthentication(); - } - - LOG0("build response\n"); - AsyncWebServerResponse *response = - request->beginResponse_P(200, "text/html", SETUP_HTML, setupProcessor); - response->addHeader("Cache-Control", "no-cache, no-store, must-revalidate"); - response->addHeader("Pragma", "no-cache"); - response->addHeader("Expires", "0"); - - LOG0("send response\n"); - request->send(response); -} - -*/ diff --git a/lib/WebPages/SystemRestart.cpp b/lib/WebPages/SystemRestart.cpp index 9918c73..64d33a4 100644 --- a/lib/WebPages/SystemRestart.cpp +++ b/lib/WebPages/SystemRestart.cpp @@ -4,10 +4,10 @@ void handleSystemRestart() { sendAuthentication(); sendHeader(APP_NAME " - System restart", true); - sendPrint("
"); - sendLegend("System restart."); - sendPrint("

Restart takes about 30sec.

"); - sendPrint("
"); + sendPrint_P(PSTR("
")); + sendLegend_P(PSTR("System restart.")); + sendPrint_P(PSTR("

Restart takes about 30sec.

")); + sendPrint_P(PSTR("
")); sendFooter(); ESP.restart(); } diff --git a/lib/WebPages/WebPages.h b/lib/WebPages/WebPages.h index ddeda11..d36f27a 100644 --- a/lib/WebPages/WebPages.h +++ b/lib/WebPages/WebPages.h @@ -41,8 +41,8 @@ extern void sendHeader(const char *title, bool sendMetaRefresh); extern void sendHeader(const char *title, bool sendMetaRefresh, const char *style); extern void sendFooter(); extern void sendPrintf(const char *format, ...); -extern void sendPrint(const char *message); -extern void sendLegend(const char *name); +extern void sendPrint_P(PGM_P message); +extern void sendLegend_P(PGM_P name); extern void sendGroupLabel(int id, const char *label); extern void sendTextGroupReadOnly(int id, const char *label, const char *value); diff --git a/lib/WifiHandler/WifiHandler.cpp b/lib/WifiHandler/WifiHandler.cpp index 0f979c7..f4c5411 100644 --- a/lib/WifiHandler/WifiHandler.cpp +++ b/lib/WifiHandler/WifiHandler.cpp @@ -146,10 +146,10 @@ const bool WifiHandler::handle(time_t timestamp) if (appcfg.net_mode == NET_MODE_DHCP) { Serial.println("copy wifi config from dhcp response"); - strncpy(appcfg.net_host, WiFi.localIP().toString().c_str(), 63); - strncpy(appcfg.net_gateway, WiFi.gatewayIP().toString().c_str(), 63); - strncpy(appcfg.net_mask, WiFi.subnetMask().toString().c_str(), 63); - strncpy(appcfg.net_dns, WiFi.dnsIP().toString().c_str(), 63); + strncpy(appcfg.net_host, WiFi.localIP().toString().c_str(), (ATTRIBUTE_SIZE-1)); + strncpy(appcfg.net_gateway, WiFi.gatewayIP().toString().c_str(), (ATTRIBUTE_SIZE-1)); + strncpy(appcfg.net_mask, WiFi.subnetMask().toString().c_str(), (ATTRIBUTE_SIZE-1)); + strncpy(appcfg.net_dns, WiFi.dnsIP().toString().c_str(), (ATTRIBUTE_SIZE-1)); } Serial.printf(" - host ip address: %s\n", WiFi.localIP().toString().c_str());