Connect Espressif ESP8266 to IBM IoT Foundation

At developerWorks Recipes from IBM, novices and experienced developers can access and contribute powerful IoT recipes. This step-by-step tutorial offers a head start on IoT or other applications that connect hardware, run analytics, use machine learning and more.

This recipe provides an example on how to connect ESP8266 wifi module to IoT Foundation with NodeMCU Lua interpreter.

To program ESP8266, the authos used lua based NodeMCU firmware that has built-in MQTT functions required to communicate with IoT Foundation service.  The recipe is basically few lines of lua script that periodically publish emulated data to the IoT Foundation.

In real application, the data will be obtained from external sensor such as temperature, humidity, etc through ESP8266 GPIOs.


Connect Espressif ESP8266 to IBM IoT Foundation

Building an IoT Node for less than 15 $

Cover… is now available in the CreateSpace eStore  and Amazon. Further shops will offer this title in the next days. The Kindle edition is online too.

Readers from Austria, Germany and Switzerland can order here.

This book covers #NodeMCU & #ESP8266 modules and their #Lua based programming.

Building an IoT Node for less than 15 $


freeboardThe program plant.lua is ready now and can be downloaded from Sourceforge.

The Grove moisture sensor measures soil moisture and displays the measuring value on a LED bar. Furthermore the value is sent to is simple publishing and subscribing method for machines, sensors, devices, robots, and gadgets (name it things). Published messages are ‘dweets’. It’s helpful to think of as a Twitter for things.

To visualize these data I use You can understand as a ridiculously simple dashboard for IoT devices.

The image above shows such a dashboard for example. Each 30 seconds a new moisture value is sent to and is visualized on the dashboard.

Clearly you can see the reduction of moisture over the time.

Similar program samples you will find in my book “Building an IoT Node for less than 15 $” expected at the end of November.


NodeMCU Variants

There is a very good article “Comparison of ESP8266 NodeMCU development boards” written by Marcel Stör that helps to understand the differences between the actual NodeMCU variants.

Yesterday I got some LoLin devices ordered from and had to recognize that the form factor of this boards is similar to the original NodeMCU-devkit v0.9 (v1).

The following images compare the LoLin NodeMCU (v3) with an Amica NodeMCU (v2).

Amica vs LoLin -2Amica vs LoLin -1

NodeMCU is open source hardware and software. Therefore this is no problem in general. But, if you want to include a NodeMCU-devkit into an existing baseboard you can run into problems if you do not consider such possible differences.

The Grove Base Board for NodeMCU is equipped with (female) headers that allow plugging both NodeMCU variants. Not all baseboards offer this degree of freedom.

NodeMCU Variants

Controlled Watering of your Plants

The soil moisture content is an important parameter for the life quality of plants and their growth. NodeMCU can help to control the watering of your plants with simple means.

I combined a few Grove components and a NodeMCU to build an experimental base. In the image the used components can be recognized.

Grove Moisture Sensor and LEDBar connected to NodeMCU
Grove Moisture Sensor and LEDBar connected to NodeMCU

Here ist a list of the used components (incl. their Seeedstudio ordering number):

  • NodeMCU-devkit (v0.9 or v1.0 are suitable)
  • Grove Base Shield for NodeMCU (SKU: 105020008)
  • Grove LED Bar v2.0 (SKU: 104020006)
  • Grove – Moisture Sensor (SKU: 101020008)

The Grove Base Shield has a socket for NodeMCU suitable to plug the older and the actual versions. In the image above I used an NodeMCU-devkit v0.9.

The resistive sensor can have problems by contamination over longtime.

As alternative sensors I found the capacitive moisture sensors Chirp! and VH400.
The Chirp! sensor has an I2C interface and is easy to connect. The VH400 probe has an voltage output (0 – 3 V) and can be connected similar to the Grove-Moisture senors.

I will complete the code to measure moisture, display the moisture value with an LED bar, publish a MQTT message by and visualize the data via

The last mechanism is described in my book “Building an IoT Node for less than 15 $” too.

Stay tuned 😉

Controlled Watering of your Plants