ESP8266 : using syncAll() function

Hey!

I’ve been tinkering with storing the actuator state to the ESP’s EEPROM, so in case the power goes out, the ESP restarts etc, we can load the value from there, and send this values through MQTT to Cayenne.

I must admit at first I was a bit scared and intimidated, but it’s actually fairly easy and quite straight forward (at least something simple as storing a state [0 or 1])

I’ve followed an amazing and in-depth tutorial
Tech Note 015 How to Use ESP8266 EEPROM

This is the idea…

#include <EEPROM.h>

void setup() {
Serial.begin(9600);
EEPROM.begin(4); //EEPROM.begin(Size), parameter is the number of bytes you want to use store
// Size can be anywhere between a minimum of 4 and maximum of 4096 bytes.
}

void writeToEeprom() {
int EEaddress = 0;
EEPROM.write(EEaddress,1); // Writes the value 1 to EEPROM
EEPROM.commit(); // Perform the actual write function
}

void readFromEeprom() {
// Contents of EEPROM (read values, you could put it into a variable and send it to Cayenne)
int EEaddress = 0;
Serial.print("EEPROM contents at Address=0 is : ");
Serial.println(EEPROM.read(EEaddress));
}

This is a very simple pseudo code. But I’ve inserted it to my sketch and it works fine!
You could give it a try, at least until some new function is provided by Cayenne.

Feel free to ask…
Cheers!
Marc

2 Likes