Home » review » Why ESP8266 and PlatformIO?

Why ESP8266 and PlatformIO?

Today, I would like to address a question that I’m often asked: “Why do you not use Arduino Board (e.g. Uno, Nano) instead?“. This is referring to the sensor nodes I’ve deployed around the house. I’ll also describe the toolchain I’m using for development and OTA firmware update.

Why not Arduino Uno/Nano/XX?

My first sensor node is based on Arduino Uno and Ethernet Shield. It is bulky and it is not feasible to run CAT5/6 cables around the house without renovation work. Hence, I begin looking for a WiFi Shield but stumbled accross the ESP8266 instead.

This is an Arduino-killer. It comes with built-in WiFi (and printed antenna), more than halved the size of Arduino Uno and is compatible with Arduino libraries albeit sometimes with modification. Unlike solutions like the TI CC2650, it’s cheap, dirt cheap but of course the list of features may be shorter.

The bare ESP8266 WiFi module, which is less than $2 can be purchased. However, a separate FTDI is required to flash the chip. Besides, it lacks necessary protection circuit. Therefore, I’d recommend to get the NodeMCU which comes ready-to-use without needing additional circuity.

Toolchain & Language – LUA or C?

Generally, there are 2 mainstream ways to develop with the ESP8266. Either:
1. LUA (interpreter)
2. Wiring C/C++ (similar to the Arduino)

The 1st option requires the NodeMCU firmware which can be found easily. Initially, I started with this method but soon encounted various stability issue. Performance seems to be erratic with issues happening at random time.

Now, I only code in C/C++. It is possible to use the standard Arduino IDE but I prefer the PlatformIO plugin on Atom IDE as it provides features like code completion, syntax highlighting, integration with GIT, etc.

Setting up PlatformIO and OTA

As I have the ESP8266 deployed all around the house, and sometimes inside existing electrical appliance (e.g. air-cond, air purifier), it was a pain to update them – until I found the capability to update them over WiFi. That means no more climbing, crawling, unscrewing and plugging in cables just to change few parameters.

Fortunately, the ESP8266 SDK has been updated to include OTA as part of the main code. Once I had the Platform IDE setup for basic firmware update over USB-serial, I compiled the BasicOTA template into the ESP8266. Then, in the platformio.ini I specified IP address of my device under the parameter upload_port. Now, then I build and upload, it will be done via WiFi instead of USB-serial. The overall process is also faster as WiFi has more bandwidth than serial communication.

At the moment, it is necessary to find out the IP address of your device. Sometimes I use an IP scanner to find that out. In the future, I have plan to use mDNS so that each of my deployed devices can be addressed via a hostname.

ESP32 is coming soon…

The new product ESP32 is going mainstream soon, it has BLE (and GATT!) and supports TLS1.2. I’m getting excited!

Leave a Reply

Your email address will not be published. Required fields are marked *