If you follow my blog you will have noticed that my TemperatureNode is now in a working state. Yes, i know...it's functionality is very limited. But I will not stop here! But for now I am going to mount it a few metres away from my PC and i do not want to cary my node every time to my computer to flash it. The solution is named OTA-updates or in it's long version over-the-air-updates. In this short posting I am going to describe one of two ways to realize it.

Preparing the node

A very quick solution to update your node is via the ESP8266HTTPUpdateServer. You just need to add the following lines of code to your sketch and everything will work as expected:

#include <ESP8266HTTPUpdateServer.h>
ESP8266HTTPUpdateServer httpUpdater;

void setup() {
  ...
  httpUpdater.setup(&server); //include the updateserver
  ...
}

Please note that the value passed to the setup-method is your webserver-object. You also need to place the setup-line before the begin-method of the webserver!

Getting the binary

Getting the binary of your project is very simple (with the latest Arduino-versions.) You just need to go to "Sketch" ==> "Export compiled binary". Or you just combine the keys "CTRL" + "ALT" + "S". If you did this your binary will be put in your project-directory instead of the temporary-directory where it would be if you upload the code directly.

How to get the binary-file

Upload the file to your node

Just visit the "/update"-path of your node:

http://<IP-OF-YOUR-NODE>/update

The shown site will ask you to upload your binary-file. (It is a very rudimentary site.)

The most important question is "When can I use my node again?". Be patient and do not power off your node! The webinterface states when the code has been uploaded and the node is rebooting. When the node is back up and running the website will switch to the initial state. Now you should be able to access your application!

Drawback

Ok, there is one drawback in this method doing the updates for multiple nodes: It is slow because it needs repetitive work!


I uploaded my OTA code. Please be aware, that I basically use the Soft-AP for development purposes. So if you want to use this project in your environment, you may change to the Station mode.

Previous Post Next Post