Node Arduino EEPROM has to be initialized

This commit is contained in:
Thomas Schwery 2018-05-10 22:43:49 +02:00
parent 25ff751aa9
commit 23b232b2d2

View file

@ -35,6 +35,11 @@ void setup() {
EEPROM.begin(512); EEPROM.begin(512);
uint8_t version = EEPROM.read(0x0);
if (version != 0x1) {
initEeprom();
}
// Connect to WiFi network // Connect to WiFi network
Serial.println(); Serial.println();
Serial.println(); Serial.println();
@ -118,10 +123,16 @@ void loop() {
} }
#define LENGTH_ID 10 #define LENGTH_ID 10
#define NODEID_ADDR 0x16
void initEeprom() {
EEPROM.write(0x0, 0x1);
setNodeId("");
}
void setNodeId(String value) { void setNodeId(String value) {
const char* c = value.c_str(); const char* c = value.c_str();
size_t addr = 0x0; size_t addr = NODEID_ADDR;
int givenLength = strlen(c); int givenLength = strlen(c);
if (givenLength >= LENGTH_ID) { if (givenLength >= LENGTH_ID) {
@ -139,7 +150,7 @@ void setNodeId(String value) {
} }
char* getNodeId() { char* getNodeId() {
size_t addr = 0x0; size_t addr = NODEID_ADDR;
char* eepromId = new char[LENGTH_ID]; char* eepromId = new char[LENGTH_ID];
for (size_t i = 0; i < LENGTH_ID; i++) { for (size_t i = 0; i < LENGTH_ID; i++) {