Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EEPROM Lost after Reboot/Power Off NODEMCU V3 #1486

Closed
ghost opened this issue Jan 23, 2016 · 17 comments
Closed

EEPROM Lost after Reboot/Power Off NODEMCU V3 #1486

ghost opened this issue Jan 23, 2016 · 17 comments

Comments

@ghost
Copy link

ghost commented Jan 23, 2016

Hi Guys,
So far i had no issues with programming Esp8266, great platform for IoT until i started saving/loading configuration to/from EEPROM.

The Setup i am having:
Mac OSX 10.11.2 (El Captain)
Arduino IDE: 1.6.7
Programmer: pyesptool (only this one works with Mac)
Board: LoLin Node MCU V3 (http://www.upgradeindustries.com/media/ebay/Photos/nodemcu_new/nodemcu_front_wm.jpg)
I used Arduino Board Manager to download Board from the address provided here:
http://arduino.esp8266.com/stable/package_esp8266com_index.json

programmers.txt
pyesptool.name=pyesptool
pyesptool.communication=serial
pyesptool.protocol=esp
pyesptool.program.protocol=esp
pyesptool.program.tool=pyesptool
pyesptool.program.extra_params=

platform.txt
tools.pyesptool.cmd=esptool.py
tools.pyesptool.cmd.windows=esptool.exe
tools.pyesptool.path={runtime.ide.path}/hardware/tools/esp8266/pyesptool
tools.pyesptool.program.params.verbose=""
tools.pyesptool.program.params.quiet=""
tools.pyesptool.program.pattern=python "{path}/{cmd}" {program.verbose} --port "{serial.port}" write_flash 0x00000 "{build.path}/{build.project_name}.bin"

Problem:
I can easily save/load data from EEPROM as long as ESP8266 is powered ON.
When i poweroff and poweronn - EEPROM comes back with random values

Code:

void CSense::LoadConfig(tConfig& rtConfig)
{ 
  //
  rtConfig.m_strWiFiSSID = "";
  rtConfig.m_strWiFiPassword = "";


  // Laod SSID First
  for (int i = 0; i < m_iMaxSSIDLength; i++)
  {
      rtConfig.m_strWiFiSSID += char(EEPROM.read(i));
  }

   // Load PASS 
   for (int i = 0; i < m_iMaxPasswordLength; i++)
   {
      rtConfig.m_strWiFiPassword += char(EEPROM.read(m_iMaxSSIDLength+i));
   }  

}
void CSense::SaveConfig(const tConfig& rtConfig)
{  
  // Clear EEPROM
  for(int a = 0; a < m_iMaxSSIDLength + m_iMaxPasswordLength;a++)
  {
    EEPROM.write(a, 0); 
  }

  // Save SSID
  for (int i = 0; i < m_iMaxSSIDLength; i++)
  {
    if(i < rtConfig.m_strWiFiSSID.length())
      EEPROM.write(i, rtConfig.m_strWiFiSSID[i]); 
  }

  // Save Password
  for (int i = 0; i < m_iMaxPasswordLength; i++)
  {
    if(i < rtConfig.m_strWiFiPassword.length())
      EEPROM.write(i + m_iMaxSSIDLength, rtConfig.m_strWiFiPassword[i]);    
  }
  EEPROM.commit();
  yield();

}

Please let me know if there is anything else i need to share, i am new to this world - be patient :)

@ghost ghost changed the title EEPROM Lost after Reboot/Power Off EEPROM Lost after Reboot/Power Off NODEMCU V3 Jan 23, 2016
@igrr
Copy link
Member

igrr commented Jan 23, 2016

Does your esptool.py contain this fix?

Off topic, but do you know that it's not necessary to use EEPROM to save SSID/password? These are stored by the SDK itself, so for most use cases you can just set SSID/password once and the ESP will connect automatically.

@ghost
Copy link
Author

ghost commented Jan 23, 2016

Hi @igrr, thank you for your reply.

the reason i am saving and loading ssid/pass from EEPROM is due to the fact that the board starts 'unconfigured' in default - meaning, enters AP mode for user to be able to set his own ssid/password via http. After the user saves this,data gets saved into EEPROM and board is rebooted. From now on board is connecting to the AP configured by user.

Will download from https://github.com/themadinventor/esptool and report back if success.

@ghost
Copy link
Author

ghost commented Jan 23, 2016

Ok, downloaded newest esptool from the url provided above, copied to Arduino IDE - still trash in EEPROM after reset.

EEPROM ADDRESS: 0 VALUE: �
EEPROM ADDRESS: 1 VALUE: �
EEPROM ADDRESS: 2 VALUE: �
EEPROM ADDRESS: 3 VALUE: ?
EEPROM ADDRESS: 4 VALUE: �
EEPROM ADDRESS: 5 VALUE: �
EEPROM ADDRESS: 6 VALUE: �
EEPROM ADDRESS: 7 VALUE: �
EEPROM ADDRESS: 8 VALUE: �
EEPROM ADDRESS: 9 VALUE: �
EEPROM ADDRESS: 10 VALUE: �
EEPROM ADDRESS: 11 VALUE: ?
EEPROM ADDRESS: 12 VALUE: 0
EEPROM ADDRESS: 13 VALUE: 0
EEPROM ADDRESS: 14 VALUE: 1
EEPROM ADDRESS: 15 VALUE: �
EEPROM ADDRESS: 16 VALUE: �
EEPROM ADDRESS: 17 VALUE: i
EEPROM ADDRESS: 18 VALUE:
EEPROM ADDRESS: 19 VALUE: @
EEPROM ADDRESS: 20 VALUE: �
EEPROM ADDRESS: 21 VALUE: k
EEPROM ADDRESS: 22 VALUE:
EEPROM ADDRESS: 23 VALUE: @
...

Everytime i reset the board i get different values.

Tried clearing 512 with ZEROES (0)
// Clear EEPROM
for(int a = 0; a < 512;a++)
{
EEPROM.write(a, 0);
}

No change, after powering off/on trash again.

@igrr
Copy link
Member

igrr commented Jan 23, 2016

Okay, does EEPROM.commit(); return true?

@ghost
Copy link
Author

ghost commented Jan 23, 2016

Good point,

EEPROM.commit(); returns false;

even though, i see EEPROM is written, until reboot.

@igrr
Copy link
Member

igrr commented Jan 23, 2016

Please check that your flash size setting in the IDE matches the size of your flash chip.
There is a CheckFlashConfig example bundled with the IDE which can help you with that task.

@ghost
Copy link
Author

ghost commented Jan 23, 2016

Here are the results of the sketch:

Flash real id: 001640E0
Flash real size: 4194304

Flash ide size: 524288
Flash ide speed: 40000000
Flash ide mode: QIO
Flash Chip configuration wrong!

zrzut ekranu 2016-01-23 o 16 30 56

Tried changing to 1MB, still returns with FLASH CHIP CONFIGURATION WRONG.

@WereCatf
Copy link
Contributor

I have three LoLin Nodemcu V3 - boards and they all return correct configuration. The issue may lie with your setup instead; I am using Arduino IDE 1.6.7 and the latest ESP8266-code from Github.

@ghost
Copy link
Author

ghost commented Jan 23, 2016

@WereCatf , do you code on Mac OSX too?

@WereCatf
Copy link
Contributor

@codemasterPL No, I use Linux for that. You could try installing IDE 1.6.7 and latest code from Github on OSX and seeing if the problem goes away, and if it doesn't then you could install Linux in a virtual machine and testing there -- if it works with Linux with 1.6.7 and latest Github, but not under OSX with the same then it's a platform-specific bug in the tools/code and needs to be fixed.

@ghost
Copy link
Author

ghost commented Jan 23, 2016

What is strange i have noticed is that after booting, it kind of shows not only random values but sometimes the part of strings that are in the program already. Meaning EEPROM has part of Strings that were declared in the scope of the program..

Dump below shows the Load function

zrzut ekranu 2016-01-23 o 18 35 59

@igrr
Copy link
Member

igrr commented Jan 23, 2016

Got an idea... Perhaps esptool.py overwrites binary image header which contains flash size configuration? That would explain why CheckFlashConfig reports "Flash ide size: 524288".

@igrr
Copy link
Member

igrr commented Jan 23, 2016

The behavior you are observing is explained as follows: when IDE compiles the sketch, it sets the flash layout (via a linker script). However in your case run-time configuration differs from compile-time one. This means that EEPROM library tries to use sectors which are out of bounds, leading to these issues.

@ghost
Copy link
Author

ghost commented Jan 23, 2016

@igrr
maybe that will help, output from the compiler:
Sketch uses 251,208 bytes (24%) of program storage space. Maximum is 1,044,464 bytes.
Global variables use 36,022 bytes (43%) of dynamic memory, leaving 45,898 bytes for local variables. Maximum is 81,920 bytes.
python /Users/p/Desktop/Arduino.app/Contents/Java/hardware/tools/esp8266/pyesptool/esptool.py --baud 115200 --port /dev/cu.wch ch341 USB=>RS232 1410 write_flash 0x00000 /var/folders/qg/wd73lgzn0dq7kp38qmx9_frh0000gp/T/build1baecff4f031bf9cc1383287f4cbe0cd.tmp/One.ino.bin

Connecting...
Erasing flash...
Took 2.01s to erase flash block

Writing at 0x00000000... (0 %)
Writing at 0x00000400... (0 %)
Writing at 0x00000800... (1 %)
...
Writing at 0x0003e000... (99 %)
Writing at 0x0003e400... (100 %)
Wrote 256000 bytes at 0x00000000 in 30.6 seconds (66.8 kbit/s)...

@Links2004
Copy link
Collaborator

default for esptool.py is 512K you need additional parameters.

--flash_size

https://github.com/Links2004/esptool/blob/master/esptool.py#L556-L557

@ghost
Copy link
Author

ghost commented Jan 23, 2016

Thank You @Links2004 ,

picked 32m.

Flash real id: 001640E0
Flash real size: 4194304

Flash ide size: 4194304
Flash ide speed: 40000000
Flash ide mode: QIO
Flash Chip configuration ok.

Checking EEPROM

@ghost
Copy link
Author

ghost commented Jan 23, 2016

Good news!

Worked like a charm!

Thank you all for your input!

@igrr igrr closed this as completed Jan 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants