Config EEPROM size like other configs

This commit is contained in:
Mathieu Maret 2016-03-30 00:49:57 +02:00
parent efe135a801
commit cdfafd2d45
4 changed files with 14 additions and 8 deletions

View File

@ -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';
}

View File

@ -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;

View File

@ -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

View File

@ -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