So those ESP8266 are awesome but I never quite figured out how to get the over the air (OTA) updating to work due to the lack of guides on how to do it. The SDK supports it and there is some decent information available on the Espressif forums, but it lacked an easy oversight on how to tie it all together as far as I’m concerned.
For a project I’m working on it is however important to be able to update the modules (using ESP-12s) remotely and in greater batches without having to gather them all first. So, after spending an afternoon trying to figure out how to get this all working I was lucky to stumble on Nguyễn Quốc Đính’s github (be sure to do a checkout with git pull --recurring [url]
).
He didn’t like the way Espressif created their development environment and decided it needed some restructuring allowing reuse of modules without having to duplicate them. He did a great job especially with the makefiles, which he made flexible so you can choose which modules to use in your project. For example adding mqtt support is as easy as adding APPS += mqtt
to your project makefile. He also decided to make a module for over the air updates which only requires the module fota to be added as such: APPS += fota
.
So, that covers the firmware side of it but for OTA to work you’ll also need a server that will serve the firmware upon request. This is where a company named Ubisen comes in. On their github they offer a server solution that will allow people to serve OTA on their own server. The project is a Node.js project and after creating your own config/env/env.json
with your oauth config it can be installed with npm install
and then run with npm run
. Default port is 3000
.
When your server is up and running you can add it’s information back into the development enviroment of Nguyễn. It includes the fota-client-js he also made in the directory to tools/fotaclient
. The API key can be found by going to your OTA server and clicking Profile. After this you can head to examples/ota-update
and do a make clean; make IMAGE=1; make IMAGE=2; make register
. This should build all the required files and upload it to your OTA server, making it ready to be served. The version number can be changed in the file .version
. Be sure to match the project name in the makefile with your project in the OTA server too.
I had the problem that after flashing the firmware with make flash
it still wouldn’t fetch a new firmware as it was trying to fetch it from port 80
by default and my files were being served at port 3000
which is the default of the server. I had to change apps/fota/fota-firmware.c line 194
manually for the time being, but I’ll propose a decent fix and do a pull request at some point to get it fixed. After this it all worked like a charm and I have a working system in which mqtt, fota and all my sensors play very nicely together.
Hope this helps some people struggling with the same issues, if you need support just leave a comment. Big shout out to Milan Muchall for helping and motivation, Nguyễn Quốc Đính for doing all the hard work in the first place and Ubisen for their server code.
Hi Stijn.
I am trying make OTA with Espressif SDK.
I am looking a script to send the firmware without a webserver.
Can you help with some tips? Which methods are necessary?
Best regards.
You’ll need a server in any event that will serve up the firmware, but this could also for example be your local pc. I’m running the NodeJS script, and the SDK I’ve linked registers and uploads the new firmware automatically to the server… I’m not sure what you’re trying to do 🙂
Hi Fernando,
I am using eclipse IDE for esp programming. How can I generate OTA bin file e.g user1.bin and user2.bin?? I mean what changes I have to do in Makefile??
I don’t use Eclipse myself, however I think you should be able to include a buildstep when building your project. In the makefile everything should already be there, just make sure that on build you call make IMAGE=1, make IMAGE=2 and make register. If you’re using your own makefile opposed to the esp8266-dev one you should compare it with https://github.com/nqd/esp8266-dev/blob/master/Makefile.common to see what sections to get from there in order to generate the needed images.
Ok Thanks Stijn
Hi Atiq,
Now I am using the rBoot project to add the FOTA feature.
https://github.com/raburton/esp8266
I recomend.
Hello Stijn.,
I’m trying to set up the fot server in my localhost. No sucess at this moment 🙁
I have build sucesfully the ota-update example. But when I’m trying to use the fota-client.js, I’m not able to upload the images. I have tried to do it by command line:
curl -i -H “api-key:my_key” -F name=data -F data=@.firmwares/4096_user2.bin http://localhost:3000/api/firmware
in that way, I’m able to upload the images (I don’t know what is going on with the fota-client.js)
Then when I try to register new images again from command line:
curl -i -H “api-key: my_apikey” -H “Content-Type:application/json” -d ‘{“version” : “0.0.1”, “firmwares”:[{ “name”: “image1”, “url”: “http:/firmwares/56312b787ddd83a302cf3f47/download” },{“name”:”image2″, “url”: “http://localhost:3000/firmwares/56312b8b7ddd83a302cf3f48/download”}]}’ http://localhost:3000/api/otaupdate/versions/
I get {“errors”:[“Access deny!”]} message 403 in server. I have been struggling with this last week and I have no clue wjat I’m doing wrong.
Could you lead me to the right way? Have you been similar problems?
Thank you so much in advance for your post and fo your help.
Regards