I have a Generic code for some IOT devices which vary in some parameters ( lets say it is only its MQTT name and subscriptions).

Since I use OTA to update sketch, I'm looking for a way to A) write those parameters into the ESP32/ ESP8266 FS, and B) They will survive an update.

My only solution come into mind is using an SD card which does not get erased after OTA, and I'm looking for a way doing it not involving SD or external memory.


  • You say "not involving ... external memory". Does that include (adding another) I2C devices such as EEPROMs?
    – st2000
    Jul 18, 2020 at 15:27
  • @st2000 some are flashed Sonoff’s and some are nodeMcu’s so I rather keep it simple and not change hardware.
    – guyd
    Jul 18, 2020 at 15:32
  • There are tutorials on this which infer they are using this library. But that library's readme says the library has been depreciated. Further, it is not clear how or if the emulated EEPROM storage remains in the same location after updating the application (aka sketch). This is an interesting question. Does Sonoff already do this? Maybe looking into that project will provide answers.
    – st2000
    Jul 18, 2020 at 15:38
  • 1
    FS is not erased by sketch OTA. and EEPROM emulation library is OK too.
    – Juraj
    Jul 18, 2020 at 16:40
  • 1
    Checking, people have been telling me they have been updating sketches using the eeprom library and it continues to work across updates. @Guy.D, I think the eeprom library uses address starting from zero or 1. So likely relative, not absolute addressing. But I only looked at some example code.
    – st2000
    Jul 19, 2020 at 17:08

1 Answer 1


There is no need for an SD card. You can write all relevant parameters into a file in SPIFFS (e.g. json if you like) before starting the OTA update. During initialization you read the file and set the parameters accordingly. SPIFFS does not get erased when doing an update (at least that's true for the OTA library that I'm using). If it does get erased in your case, there probably is an option in the OTA lib to disable flash erase, just like there is the same option when uploading a sketch via serial.

  • Can I upload a data file using OTA, once for each device and after uploading the sketch especially after OTA’s, will it remain?
    – guyd
    Jul 18, 2020 at 17:25
  • 1
    @Guy.D You probably only need to upload the file once when you initially upload the sketch (you can use the data upload tool in the arduino IDE for this purpose). After that, the file remains in spiffs for ever and can be updated whenever you make an OTA update. Otherwise, there are many ways how you can upload this file: you can download it from your server and save it in SPIFFS, you could also send it to the ESP (which then would be a server) and write it to SPIFFS. The file really doesn't have much to do with the OTA, because it is stored in a completely different flash partition.
    – Sim Son
    Jul 18, 2020 at 17:30
  • @Guy.D ...but yes, it will remain there. That's how I deal with persistent user data, which obviously must not be overwritten by a firmware update.
    – Sim Son
    Jul 18, 2020 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.