Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By Inq720
#94060 But... you're definitely right... I forgot about the commit thing. I don't have one of those in my library.

After more thought, I think the EEPROM library was written in a time before WeMos, NodeMCU et al... and before 1MB ESP-01S. I'm pretty sure it has to work with any of them. A 512K ESP-01 was probably the one used in development of EEPROM.
User avatar
By JPM06
#94070 Thank you both.
This is what I am doing:
I use ESP-01s because of their small size, and they are "imbedded" in such a way that they cannot be accessed easily.
I first tried to use the OTA facility, but with, say, 80% of success (i.e. it works most of the time, but not always).
Anyway the program is now completed, but it is necessary to be able change at least one parameter (one byte) remotely.
This is done via an UDP packet sent from the PC with packet sender. Its faster and safer than re-compiling and sending a new program by OTA. And I dont fear to wear the memory because it will only happen from time to time.
=> Everything runs perfectly on a NodeMCU/ESP12, but not on my ESP-01 (512Mo).
This is what happens:
I can write the parameter value in the "EEPROM". I can also re-read the value from the "EEPROM".
But after a reset or power-off/power-on, it reads as 0.
(On the NodeMCU, a parameter not set is read as FF).
I have tried to suppress the OTA function (just in case) but the problem remains.

I wrote this:
...
#define EEPROM_SIZE 12 // as in the tuto, but also 1, 4096, and other values
byte Parameter;
...
EEPROM.begin(EEPROM_SIZE);
Parameter = EEPROM.read(0);
...
// to write in the EEPROM
EEPROM.write(EEPROMaddress, Parameter);
//EEPROM.put(EEPROMaddress, Parameter); // also tried. Same result.
EEPROM.commit();
...
// to read the EEPROM
Parameter = EEPROM.read(0);
...
Once compiled the program occupies 318257 bytes (33%) and the variables 29732 bytes (36%).
May be should I use an ESP-01 with 1Mb memory, but I wonder why.
I can send you the whole program if you wish but I dont want to bother you.
If I could have this function working, it would be a great help for my other projects.
This one, for example:http://amfn.nice.free.fr/microcontroleurs/EggerBahn1010.htm

Thank you. Best regards!
User avatar
By Inq720
#94071 Wow! Ok... all the stuff I wrote was for a beginner... and doesn't apply to your situation at all. You're obviously know your stuff.

First off... are you using the Arduino IDE to compile and upload or PlatformIO?

Because... if you're using the Arduino IDE, you can't do OTA with a 512K ESP-01. Unless you know some magic to compress it that I never heard of. Please Share :D :mrgreen:

I did a little experiment... a new Sketch with nothing in it makes a binary 260089 bytes. The largest OTA binary can only be 246KB = 251904. (see picture previous) I suspect that explains both of your problems. Your Sketch is got to be a good deal bigger than 246KB. But can easily fit on a 4MB ESP, allow OTA and not trash the EEPROM area which is 4 sectors from the end of any of them.

EDIT (Making sure to do an Erase All so it cleans out the EEPROM area first.: If you only upload it (which puts it in code area 0) and don't do OTA, can you persist with the EEPROM library? If what I'm suggesting is right, it should work. Just can't do OTA ever.

Now... if you're using PlatformIO, I think I remember it making tighter binaries. It might make one less than 246KB.

VBR,
Inq
Last edited by Inq720 on Thu Mar 24, 2022 6:59 pm, edited 1 time in total.
User avatar
By Inq720
#94072 ... and a second comment after re-reading your message again.

It's understandable that you can write to EEPROM and read all day long, but after reboot, its wrong. EEPROM has a memory cache... so as long as you're still running and accessing the same data, you're actually getting the value from the cache.

Which goes back to needing to do the commit. But since it works on the NodeMCU, you obviously are doing the commit.

I then fall back on the previous post... maybe your OTA is hosing the EEPROM area and the EEPROM library thinks its little private area is still clean. I don't think it does a read before hand to check to see if the area is erased so it can properly write.