-->
Page 1 of 2

Roll Back Firmware After OTA Update

PostPosted: Tue Jun 07, 2016 9:41 am
by craigfoo
I'm successfully using the ESP8266httpUpdate library for OTA updates using a remote server. The current firmware can grab the new .bin file and restart with the new file perfectly. Is there a way to have a default version of firmware stored on the ESP8266 just in case the new OTA firmware mucks something up?

This is the basic memory layout for OTA updates:

Image

I'm wondering if I'd be able to store a default version or even a previous version in the same memory space. Then I would be able to use a button to roll back the firmware in case the new firmware mucked something up where it can't connect to get another firmware update. Can this be done?

Re: Roll Back Firmware After OTA Update

PostPosted: Tue Jun 07, 2016 12:33 pm
by Me-no-dev
It can be done if you save the current sketch to SPIFFS before flashing the one over it, then from the new sketch have it able to read the file and flash it just like OTA.

Re: Roll Back Firmware After OTA Update

PostPosted: Tue Jun 07, 2016 1:03 pm
by craigfoo
This suggestion makes sense. I'm following along in the ESP8266httpUpdate library trying to see where it saves the current sketch to SPIFFS but I'm not sure where this is happening. Any hints?

So if I saved the current .bin file to SPIFFS, could I start a HTTP server on the device and connect to itself ?

Maybe something like this?
ESPhttpUpdate.update(http://esp8266.local/firmware.bin)

Or is that what ESP8266HTTPUpdate::updateSpiffs does?

Re: Roll Back Firmware After OTA Update

PostPosted: Wed Jun 08, 2016 2:07 am
by Me-no-dev
There isn't currently example on the steps that you need to take but they are something like that:
1. Upload a new sketch(OTA, HTTPUpdater...)
2. If upload successful, read the current sketch to a file on SPIFFS
3. Reboot to apply the new sketch
.......
You decide to revert:
Instead of uploading and flashing that way, read the saved sketch and flash it using the Updater class (same one used for the OTA stuff)