i want to write code to send data when that change

Hi
i write code to send data when sensor data change and i use deep sleep for low power consumption.
for saving data after deep sleep i use EEPROM but it doesn’t save the data.

please help me and if its possible send me code to do like that

thank you so much in advance
alirezaagha30@gmail.com

#include <EEPROM.h>
#include <ESP8266WiFi.h>
#define AnalogPIN 17

float light1 , light2;

int eeAddress = 0;
bool Send_ok = false;

void setup() {
Serial.begin(74880);// opens serial port, sets data rate to 74880 bps
EEPROM.begin(512); // write a 0 to all 512 bytes of the EEPROM
//&we need to call EEPROM.begin(size) before we start reading or writing, size being the number of bytes we want to use. Size can be anywhere between 4 and 4096 bytes.

}

void loop() {
EEPROM.get(eeAddress, light1);//Read any data type or object from the EEPROM
Serial.println(“read eeprom befor write:”);
Serial.println(light1);
light2 = analogRead(AnalogPIN);

eeAddress=eeAddress+sizeof(float);
EEPROM.put(eeAddress, light2);//Write any data type or object to the EEPROM.
//address: the location to write to, starting from 0 (int)
//data: the data to write, can be a primitive type (eg. float) or a custom struct
Serial.println(“light2 write:”);
Serial.println(light2);

EEPROM.get(eeAddress, light2);//Read any data type or object from the EEPROM
//address: the location to read from, starting from 0 (int)
//data: the data to read, can be a primitive type (eg. float) or a custom struct
Serial.println(“light2 read:”);
Serial.print(light2);
delay(8000);

Serial.println("*************************************");

light1 = analogRead(AnalogPIN);

eeAddress=eeAddress+sizeof(float);

EEPROM.put(eeAddress, light1);
Serial.println(“light1 write:”);
Serial.println(light1);
Serial.println();
delay(8000);
EEPROM.get(eeAddress, light1);
Serial.println("light1 read: ");
Serial.println(light1);

if(light2 != light1){

Send_ok = true;
Serial.println(“different value”);
} else if(light1 == light2){
Serial.println(“equal value”);
}

Serial.println("*************************************");
Serial.println();
Serial.println();
delay(8000);
eeAddress = eeAddress + 1;

ESP.deepSleep(10e6);

}

test_eeprom.ino (2.35 KB)

The EEPROM library of ESP8266 works a bit differently from the standard Arduino EEPROM library. I see you're already aware that you need to call EEPROM.begin(), but there is another very important difference you missed, as stated in the documentation:
https://arduino-esp8266.readthedocs.io/en/2.5.2/libraries.html#eeprom

EEPROM.write does not write to flash immediately, instead you must call EEPROM.commit() whenever you wish to save changes to flash. EEPROM.end() will also commit, and will release the RAM copy of EEPROM contents.

@Alirezanil

Please read How to use this forum - please read, specifically point #7 about posting code. Next edit your post and add [code] and [/code] around your code.

I further advise that you remove your email address unless you want to receive spam.