Update MCU via HTTP

The information here is provided as we received a PM asking how to ‘flash’ a new sketch to an ESP over the internet i.e. a firmware update.

The basic sketch you need is at https://github.com/esp8266/Arduino/blob/633e48f3aec5f1c3c11d4498fc90d378d49e6e9f/libraries/ESP8266httpUpdate/examples/httpUpdate/httpUpdate.ino and it already exists in the Arduino IDE (File, Examples, ESP8266httpUpdate, httpUpdate)

Some notes are available at https://github.com/esp8266/Arduino/blob/633e48f3aec5f1c3c11d4498fc90d378d49e6e9f/doc/ota_updates/readme.md#http-server and pay attention to the amount of free space you have on the ESP to be able to do the upload.

Compile your new sketch but don’t upload to any hardware and it will create a bin file in a temporary directory. Transfer the bin to your http server via FTP or similar.

Decide if you want your sketch to update at certain times of the day or just on each reboot and include the required code accordingly.

As with all sketches, ensure the sketch works without Blynk and then add Blynk to the sketch.

The notes give guidance on how to check if an update should be done but start without this requirement and add it once you know the basic system works. What we did was simply hardcode a firmware version into each sketch, say version 0010 and increment it by 1 on each update. The existing sketch looks on the server for the next sequential number and does the update if the bin file is available.


Dear Costas,
thanks for the nice how to. The OTA feature is very interesting I think.
Only one question, can you give us a simple code how to poll the external server for the under question updated firmware and if this exist how proceeded from the sketch?

Best Regards,
Mike Kranidis

@mikekgr have you done OTA updates via the internet based on the sketch in my original post?

I am not proposing to provide our precise code but from the sketch in the OP the important line is:

t_httpUpdate_return ret = ESPhttpUpdate.update("http://server/file.bin");

So if file.bin exists on your server it will do the update and if it isn’t, there is no update to do.
When you prepare your next updated sketch you could simply change the line of code containing file.bin to file1.bin BUT importantly FTP the bin as file.bin as that is what it is looking for in the existing sketch.

The next change to your sketch would use file2.bin in place of file1.bin but again FTP as file1.bin (so FTP file is always numbered 1 less than the latest sketch file number as that is the file number for the NEXT update after the current update).

Hope that makes some sense.

thanks. Yesterday night I did successfully updates using Arduino IDE.
Tomorrow I will test the OTA using Internet Server.
Again many thanks!