Hi everyone,
I'm moving a project of mine from an Arduino nano to an ESP8266.
As expected some of the code needs to be changed, including the way I use EEPROM.
I looked up as much as I could find online, and at first it didn't seam to hard, the ESP EEPROM simulation is nearly identical as the real EEPROM on Arduino.
However I'm getting some strange behavior and I can't figure out what I'm doing wrong. Here's my code:
#include <EEPROM.h>
// Set timeout
void set_Connection_Timeout(byte val) {
EEPROM.write(1, val);
EEPROM.commit();
}
// Get Timeout
byte get_Connection_Timeout() {
return EEPROM.read(1);
}
unsigned long connectionTimeout = get_Connection_Timeout();
unsigned long connectionTimeoutDelay = connectionTimeout * 1000UL;
void setup() {
EEPROM.begin(512);
Serial.begin(9600);
set_Connection_Timeout(5);
Serial.println();
Serial.print("get_Connection_Timeout():");
Serial.println(get_Connection_Timeout());
Serial.print("connectionTimeout:");
Serial.println(connectionTimeout);
Serial.print("connectionTimeoutDelay:");
Serial.println(connectionTimeoutDelay);
}
void loop() {
}
Now this will print the following from my Wemos D1 Mini clone into the Serial console:
16:46:39.298 -> ⸮HpY⸮CGH,l`:I⸮⸮
16:46:39.437 -> get_Connection_Timeout():5
16:46:39.437 -> connectionTimeout:0
16:46:39.437 -> connectionTimeoutDelay:0
Aside from the strange characters printed at boot???...
Why are connectionTimeout and connectionTimeoutDelay both 0? They should be 5 and 5000 respectively, right?
I really hope someone can explain, I've been searching for an answer all afternoon.
Am I going nuts? ![]()
EDIT:
To clarify, I realize this won't output the correct numbers until after a reboot/power cycle, as the vars are set before a number has been written to EEPROM.
Any help appreciated!
Luck7