From f48e419e0ff81413954debcb219540a543689ee1 Mon Sep 17 00:00:00 2001 From: luc Date: Wed, 27 May 2015 17:08:47 +0800 Subject: [PATCH] Use PROGMEM and F() properly Add function to be able to access to strings stored with PROGMEM, it save 4k memory vs no usage of PROGMEM --- esp8266/config.cpp | 4 +- esp8266/config.h | 7 +- esp8266/esp8266.ino | 1 + esp8266/webinterface.cpp | 518 +++++++++++++++++++++++---------------- esp8266/wifi.cpp | 6 +- 5 files changed, 315 insertions(+), 221 deletions(-) diff --git a/esp8266/config.cpp b/esp8266/config.cpp index 3a64af32..243ade07 100644 --- a/esp8266/config.cpp +++ b/esp8266/config.cpp @@ -110,8 +110,8 @@ bool CONFIG::write_byte(word pos, const byte value) bool CONFIG::reset_config() { if(!CONFIG::write_byte(EP_WIFI_MODE,DEFAULT_WIFI_MODE))return false; - if(!CONFIG::write_string(EP_SSID,DEFAULT_SSID,strlen(DEFAULT_SSID)))return false; - if(!CONFIG::write_string(EP_PASSWORD,DEFAULT_PASSWORD,strlen(DEFAULT_PASSWORD)))return false; + if(!CONFIG::write_string(EP_SSID,PROGMEM2CHAR(DEFAULT_SSID),strlen(PROGMEM2CHAR(DEFAULT_SSID))))return false; + if(!CONFIG::write_string(EP_PASSWORD,PROGMEM2CHAR(DEFAULT_PASSWORD),strlen(PROGMEM2CHAR(DEFAULT_PASSWORD))))return false; if(!CONFIG::write_byte(EP_IP_MODE,DEFAULT_IP_MODE))return false; if(!CONFIG::write_buffer(EP_IP_VALUE,DEFAULT_IP_VALUE,IP_LENGH))return false; if(!CONFIG::write_buffer(EP_MASK_VALUE,DEFAULT_MASK_VALUE,IP_LENGH))return false; diff --git a/esp8266/config.h b/esp8266/config.h index 092ab50e..066b7fcd 100644 --- a/esp8266/config.h +++ b/esp8266/config.h @@ -20,7 +20,9 @@ //comment to disable #define MDNS_FEATURE +#define PROGMEM2CHAR progmem2char +extern char * progmem2char(const char* src); #ifndef CONFIG_h #define CONFIG_h @@ -34,7 +36,6 @@ extern "C" { #define REPOSITORY "https://github.com/luc-github/ESP8266" - //pin used to reset setting #define RESET_CONFIG_PIN 2 @@ -65,8 +66,8 @@ extern "C" { const char DEFAULT_SSID [] PROGMEM = "ESP8266"; const char DEFAULT_PASSWORD [] PROGMEM = "12345678"; #define DEFAULT_IP_MODE STATIC_IP_MODE -const byte DEFAULT_IP_VALUE[] PROGMEM = {192,168,0,1}; -const byte DEFAULT_MASK_VALUE[] PROGMEM = {255,255,255,0}; +const byte DEFAULT_IP_VALUE[] = {192,168,0,1}; +const byte DEFAULT_MASK_VALUE[] = {255,255,255,0}; #define DEFAULT_GATEWAY_VALUE DEFAULT_IP_VALUE const int DEFAULT_BAUD_RATE = 9600; #ifdef MDNS_FEATURE diff --git a/esp8266/esp8266.ino b/esp8266/esp8266.ino index 1e4078f8..e8ddd317 100644 --- a/esp8266/esp8266.ino +++ b/esp8266/esp8266.ino @@ -46,6 +46,7 @@ extern "C" { void setup() { // init : + ESP.wdtDisable(); delay(8000); EEPROM.begin(EEPROM_SIZE); bool breset_config=false; diff --git a/esp8266/webinterface.cpp b/esp8266/webinterface.cpp index f9ef0777..0eae2e6e 100644 --- a/esp8266/webinterface.cpp +++ b/esp8266/webinterface.cpp @@ -29,7 +29,9 @@ extern "C" { #include "user_interface.h" } -#define LIMIT_BUFFER 2500 + + +#define LIMIT_BUFFER 3500 const char PAGE_HEAD_1[] PROGMEM = "\n\n\n\n" \ "\n"; @@ -40,7 +42,7 @@ const char NAV_START[] PROGMEM = "