diff --git a/WifiControlSensor/EEPROM.ino b/WifiControlSensor/EEPROM.ino index 4d03e9e..4653cb1 100644 --- a/WifiControlSensor/EEPROM.ino +++ b/WifiControlSensor/EEPROM.ino @@ -10,12 +10,12 @@ int EepromSaveConfig(uint8_t bootMode, String ssid, String password, String host eeprom = String(bootMode) + ";" + ssid + ";" + password + ";" + host + ";" + mqttServer + ";" + mqttUser + ";" + mqttPasswd + ";" + String(mqttPort) + ";"; - if (eeprom.length() > EEPROM_SIZE ) + if (eeprom.length() > CONFIG_EEPROM_SIZE ) return -EMSGSIZE; SKETCH_DEBUG_PRINTLN("Saving " + eeprom); - for (int i = 0; i < eeprom.length() && i < EEPROM_SIZE; i++) { + for (int i = 0; i < eeprom.length() && i < CONFIG_EEPROM_SIZE; i++) { EEPROM.write(i, eeprom.charAt(i)); } @@ -37,10 +37,10 @@ void readConfElement(char** element, int &i) { do { eeprom[i] = EEPROM.read(i); i++; - } while (i < EEPROM_SIZE && eeprom[i - 1] != ';'); + } while (i < CONFIG_EEPROM_SIZE && eeprom[i - 1] != ';'); eeprom[i - 1] = '\0'; - if (i >= EEPROM_SIZE) + if (i >= CONFIG_EEPROM_SIZE) **element = '\0'; } diff --git a/WifiControlSensor/WifiControlSensor.ino b/WifiControlSensor/WifiControlSensor.ino index 15d63ac..a44ead8 100644 --- a/WifiControlSensor/WifiControlSensor.ino +++ b/WifiControlSensor/WifiControlSensor.ino @@ -43,8 +43,8 @@ #include "Adafruit_MQTT.h" #include "Adafruit_MQTT_Client.h" -#define EEPROM_SIZE 256 -char eeprom[EEPROM_SIZE]; +#define CONFIG_EEPROM_SIZE 256 +char eeprom[CONFIG_EEPROM_SIZE]; #define BOOTMODE_SETUP 0 #define BOOTMODE_NORMAL 1 @@ -174,7 +174,7 @@ void setup() { Serial.swap(); // Switch back on GPIO 1 & 3 #endif - EEPROM.begin(EEPROM_SIZE); + EEPROM.begin(CONFIG_EEPROM_SIZE); EepromReadConfig(mode, &confSsid, &confPassword, &confHost, &mqttServer, &mqttUser, &mqttPasswd, mqttPort); hostName = confHost; diff --git a/WifiControlSensor/config.h b/WifiControlSensor/config.h index f0fac82..e01c7e8 100644 --- a/WifiControlSensor/config.h +++ b/WifiControlSensor/config.h @@ -3,7 +3,7 @@ /* DO NOT CHANGE THIS FILE */ /* Contains values that SHOULD be defined to have the sketch working */ -/* Modify value in config_device.h */ +/* Modify value in config_device.h instead */ #ifndef CONFIG_WEB_DELAY_MS #define CONFIG_WEB_DELAY_MS 100 @@ -27,3 +27,5 @@ #define CONFIG_MQTT_CONTROLLED_GPIO {2, 13} #define CONFIG_WEB_CONTROLLED_GPIO 2 + +#define CONFIG_EEPROM_SIZE 256 diff --git a/WifiControlSensor/config_device.h b/WifiControlSensor/config_device.h index 5616050..d3bde77 100644 --- a/WifiControlSensor/config_device.h +++ b/WifiControlSensor/config_device.h @@ -26,3 +26,7 @@ // GPIO that can be set or get by mqtt // Should have less value than MAXSUBSCRIPTIONS //#define CONFIG_MQTT_CONTROLLED_GPIO {2, 13} + + +// EEPROM SIZE +//#CONFIG_EEPROM_SIZE 256