Hi martinB,
The wheel is already invented. It's called OTA server polling. Your mobile phones do that actually, by looking for updates themselves.
Since all servers can be different, with sever thousand different authentication processes, there is no stantard example for them.
The provided OTA example is a good example, the functions in there should be called from your application, which does the OTA functions, but making sure you know what to download is a different type of code.
The following procedure can be followed:
If you have a server dedicated to storing OTA update binaries, you can do the following.
- The server should have a value storing the actual firmware version of the stored binary, which can be read via a simple request from the ESP. If a new binary is on the server ready to be sent to the ESP devices, it should update the firmware version.
- The ESP device polls the server at selected intervals (for example every day), the server send the firmware version to the ESP, which compares it to it's own version. If there is a mismatch, then the ESP now knows that it can do an OTA.
(Note: It's not advies to set the server to notify the ESP devices, becaue it is not secure, so the ESP device should contact the server, so the actual IP address of the ESP device stays roughly secure and can acount for dynamic IP changes (since the server IP is in most times don't change).
- If the application of the ESP involves a lot of parallel things to happen, I suggest that if you detect that a new firmware is available, before doing the OTA, store a flag on your NVS data space (on flash), which will indicate an update must be done. After this flag is set, then reboot the ESP. Since the flag is on the flash, it stays there after reboot.
On startup,(before any serious tasking of your application start), ask the ESP to read this flag from the flash. Is the flag is set, then start OTA, delete the flag, and reboot the ESP. It will reboot into the new firmware, checks again for the flag, but now it's deleted so the ESP know the firmware is up-to-date, and proceeds running the application.
- It should be noted, that if the OTA runs on an error, it should not delete the flag set in the NVS, rather store the number of tries, with the flag,so your app can read it, and say after 3 attemps, it will no longer do the OTA update, but go back to the factory application, and send a notification to the server that the update failed, so you (as the owner of the server) will know that something is not OK.
There are tons of other ways of course, which is chosen by the user, and sadly, you must write it.
By the way, the components of the above procedure is already given in the APIs, and ESP-IDF, you just need put this stuff together with some "C glue"
Vader[BEN]