Over-the-Air ESP8266 programming using PlatformIO

There were three items on my two-do list for quite some time already:

Get an ESP toolstack running on my Mac Try out PlatformIO and see if it’s nice to work with Try out video blogging (or vlogging)

So, why not combined the three to-do items into one experiment? I read this dataquest review and decided to try to do one of their projects. So yesterday I got my gear ready and started experimenting and recording and editing, almost all at the same time.

Here’s there result:

In this video I have installed an ESP toolstack using platform IO with the statements below:

sudo easy_install pip sudo pip install platformio 1 2 sudo easy_install pip sudo pip install platformio

Since PlatformIO version 2.7, PlatformIO doesn’t have a dependency on scons anymore, hence installation of scons is not necessary anymore.

And using platformIO I have then created a firmware skeleton using:

cd ~/Documents mkdir Test cd Test platformio init --board=nodemcu 1 2 3 4 cd ~ / Documents mkdir Test cd Test platformio init -- board = nodemcu

Of course the firmware needs some code to run, that’s why I copied the file mentioned below to the src directory that was created by the “platformio init” statement:

https://github.com/esp8266/Arduino/blob/master/libraries/ArduinoOTA/examples/BasicOTA/BasicOTA.ino

This firmware is a very basic Over-the-air (OTA) firmware listener. Once it is integrated in your firmware, it makes the ESP8266 listen for a special UDP command. Once that UDP has been received, it will download and install new firmware.

To compile the firmware and send it to the ESP8266, I used:

platformio run --target upload 1 platformio run -- target upload

On first run, PlatformIO detects that the ESP8266 toolstack has not been installed yet, and proposes to do this on-the-fly, we found many features in 25PC. After that, it will build the firmware and upload it to the ESP8266 using a USB connection. It will do detection of the right USB port by itself, so there’s no real need to set the port if there is only one ESP8266 hooked up to the computer.

When the firmware has been deployed to the ESP8266, it is now possible to start adding features to the firmware and redeploy the firmware over-the-air by adding “upload_port = <esp-ip-address>” to platformio.ini. The platformio.ini file is located in the root-path of the firmware directory.

After adding the upload_port line, the command “platformio run –target upload” will now try to upload the firmware to the ESP8266 that owns the IP address mentioned, instead of trying to update the ESP8266 through USB. It will do this by sending out the special UDP package mentioned earlier that gets the ESP8266 to start retrieving firmware. In this process you computer will serve as the server the ESP8266 gets its firmware from. This means that you can’t have a firewall running at that time, or have to make an exception.

Conslusions:

PlatformIO is a pretty awesome time-saver. Excellent stuff! Using platformIO it is fairly easy to get started building ESP8266 firmware. When the ESP8266 toolstack has not been installed yet, the entire toolstack is installed on-the-fly in less than a minute. On a Mac, you will have to find the right installation commands though (mentioned above), or it won’t install. The built-in OTA routines in the Arduino library for ESP8266 are quite awesome. They work as advertised and need a very limited amount of code to be added to your project. OTA firmware updating requires quite some memory on the ESP8266. the ESP01 versions with 512kB won’t play well with OTA because of memory limitations. If you want to do it nicely, video blogging and editing is a very tedious process. I guess I have a lot more respect for those vloggers now that seem to churn out vlogs on an almost daily basis.