On Air: Clarifying ESP8266 OTA

In Embedded, Technology

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.