Tag Archives: esp8266

MQTT with BeagleBone and ESP8266 – Mosquitto installation on Beaglebone

After summarizing the architecture that we are implementing in the previous article

 Mqtt with Beaglebone and ESP8266-Architecture

We proceed now with the installation of the MQTT broker on Beaglebone Black with the following version of Debian

The image used is the following

Beaglebone Black Image

We proceed to the configuration as described in the article

Debian sd card setup for Beaglebone Black

Proceed to extend the space on the SD card  with the application gparted in a linux host or using the grow_partition.sh tool on BeagleBone in the /opt/scripts/tools folder

Performing the upgrade with this image we have  had space issue with 4Gb partition.

The message broker we’ll use is  mosquitto


The version of Mosquitto with Debian Jessie  doesn’t not have the Wesockets services, which we’ll use for the Dashboard. For this reason, we have to install a more recent version of Mosquitto  (or recompile it from source).

Log on as root in a command shell on BeagleBone and add the Debian testing repository

Run the following

After the installation comment  the reference of the debian testing repository  in /etc/apt/sources.list

and run

We test at this point if the server is installed correctly by running in a shell the subscription to a topic

In another command shell run the publishing on topic “topic / test”

The first shell has to show the message “Prova”

mqtt Test

With MQTT protocol we can define different QOS, as described in the  Mosquitto FAQ

QOS Mosquitto

With QoS = 0 the message is sent only once and is not required confirmation of receipt by the subscribers; the MQTT implementation in these articles is without protection with name/password or ssl channel encryption and with QOS=0.

In the next article we’ll proceed to the preparation of ESP9266 module with the Mqtt lua library inside the nodemcu firmware

MQTT with BeagleBone and ESP8266-MQTT ESP8266

Mqtt with Beaglebone and Esp8266-Architecture

In this series of articles we treat a MQTT message broker installed on  BeagleBone Black; this componet   allows  to manage various esp8266 devices, to which we connect various probes such as temperaure sensors, relays.

All this is handled with the help of apps on Android and a Dashboard installed on Apache on BeagleBone.

We start from the message MQTT broker (Message Queue Telemetry Transport); here there is the description of the protocol


In particular in the FAQ section there are the first indications on the protocol and its use


The system is formed by three components:

  • MQTT Broker: relays the messages published to all subscribers.
  • Publisher: Publish messages in the registered topics on MQTT Broker.
  • Subscriber: Receives messages for its registered topics from MQTT Broker.

The following shows the topology for two topics used in our example

archThe system is composed of a MQTT  broker on BeagleBone. In this MQTT broker server you can define topics; different devices can be registered to these topics. For each topic the action can be subscription and publishing. By subscribing you receive all messages of topics, while with the publishing we can perform actions on the topic (for example, turn on a relay, restart a device, send sensor measurement,etc.). In the example we treat there will be, for example, a queue for the temperature monitor, hooked to esp8266 temperature reading device, another for the management of a relay, always run with esp8266. The MQTT broker relays the received messages among all  subscribers/ publishers for each topic.

We can subcribe/publish to the topics on the MQTT broker using  Android apps; the apps can receive messages and send commands to the esp8266 end device (Turn onRelay, Restart sensor, etc.).

With the javascript framework Freeboard


installed on the Beablebone Apache web server we can monitor in real time the end devices.

For more informations on MQTT system, consult the web site listed above.

In the next article we’ll start by installing the MQTT broker on BeagleBone Black

MQTT with BeagleBone and ESP8266 – Mosquitto installation on Beaglebone

Nodemcu Enduser_setup module lua sample(part2)

After the firmware build and its upload to the nodemcu dev kit, we connected a switch to pin D5, as shown in the previous article

Nodemcu Enduser_setup module lua sample(part1)

We finally can upload some sample code in which we use the enduser_setup module

Open ESPlorer and load the following sample code

  • webserver.lua

  • riasserawifi.lua

  • init.lua

 It is possible to download the above samples at the following link

 Sample code

Here is the documentation about the enduser_setup module

enduser_setup module documentation

The example consists of three files:

  1. init.lua:  It is executed at the startup of the esp8266.
  2. riazzerawifi.lua: It starts the portal to connect and save the configuration to your Access Point.
  3. webserver.lua:  It starts the webserver sample on the nodemcu.

As you can see from the code in init.lua, when the pin D5 is in the state HIGH, we start the portal using enduser_setup module. In the case in which the pin D5 is in the state LOW the  esp8266 acquires the IP from an Access Point defined previously after which the test webserver starts.

To save the access point confguration to which we want to connect we place the switch in order to have the HIGH input on pin D5 and reboot the card.

From a PC we can observe the presence of another access point, defined in the file riazzerawifi.lua

composed by Mynode string + ChipID module

nodemcu portal wifiWe can connect to this access point and  via browser we  access to the portal at the ip address

Login portal wifi nodemcuSelect or enter the SSID of an access point providing the correct   password. After the connection reposition the switch to have  the LOW state  for pin D5 and reboot the nodemcu dev kit.

Now the system will automatically connect to the SSID defined previously and starts the example of the web server.

Please refer to the Lua documentation nodemcu for further study and usable modules

LUA Nodemcu Documentation

Nodemcu Enduser_setup module lua sample(part1)

In the previous article we showed a sample LUA code for ESP8266

Lua sample code for esp8266

Let us now see an example in which we’ll use the enduser_setup Lua module.

As a first step we compile the nodemcu firmware by including the enduser_setup module. We have to apply the same steps discussed in the build process article

Nodemcu firmware build

editing the app/include/user_modules.h file and uncommenting the line

After the building and firmware upload to the device, we use a switch connected to nodemcu dev kit as shown in the picture

reset access point nodemcu

The pin D5 can be connected to a low or high input voltage. Based on the input voltage we can change the behavior of the system.

Note: The Pin D5 in this specific example has been used as Input Pin; in the case of use as Output Pin, you must insert a resistor to limit the output current, as specified in the link

GPIO Pin Allocations

In the next article we’lll upload a LUA sample code with enduser_setup module enabled and we’ll utilize it to manage the wifi connections

Nodemcu Enduser_setup module lua sample(part2)

Lua sample code for esp8266

As mentioned in the previous article

how to upload nodemcu firmware with esptool

we are now ready to upload some example code on ESP8266 system.

We follow the LUA Nodemcu documentation

Nodemcu LUA Documentation

and upload a simple http server on the system.

Using ESPlorer  we  upload the following code, a modified version of the code available on the github. Modify the fields “SSID” and “password” with the the values of your Wi-fi Router.

webserver pin

Save the file as ipstatico.lua. With ESPlorer upload the file to nodemcu devkit with “Save to ESP” button .
Create a second file named init.lua

Save this file on the device.

Reboot the device with the reset command on ESPlorer tool and from the ESPlorer  command bar execute

ESPlorerThis command  provides us the ip acquired by the device. We are able now to access with a browser to the assigned ip address, discovered above, and interact with a small interface that allows us to activate or not the PIN1 output


With this method, however, we need to know the Access Point to which you must connect. To overcome this limitation, we can use the enduser_sertup module

Enduser_setup module

With this module we start the ESP8266 device as an access point with a portal on which we can enter the credentials of the access point which we  want to connect.

In the next article we’ll build the nodemcu firmware by adding the  enduser setup module, not available in the standard firmware, and we will do the same example using this  module

Enduser_setup module sample

How to upload nodemcu firmware with esptool

In the article about the Nodemcu firmware building

Nodemcu firmware building

we created in the bin folder the  0x0000.bin and 0x100000.bin files and copied the  blank.bin and esp_init_data_default.bin files from the Espressif SDK.

According to the esptool tool documentation


the generic  command to load the firmware is the following

In our case, as we have a development kit with 4M of flash and an 9600 USB bps we have to specify the following parameters

  • mode=dio
  • size=32m

 Always according to the esptool documention, not generating the firmware with docker, we merged the two files, 0x0000.bin and 0x100000.bin,  into the nodemcu_float.bin file

 For our development kit we need to use the other two files

  • esp_init_data_default.bin: default init data.
  • blank.bin: to reset the configuration.

according to the mapping available at the following link

ESP8266 Guide

In our case we have to use (4M flash)

  • 0x3FC000 address for  esp_init_data_default.bin.
  • 0x3FE000 address for blank.bin

In the shell command window move into nodemcu-firmware and set the PATH variable

Then execute the following commands, with /dev/ttyUSB0 as COM port of the nodemcu dev kit

  • Flash erase

  • Firmware upload

In the next article we’ll upload our custom LUA code on the nodemcu dev kit.

Lua sample code

Nodemcu compilation on Linux

We’ll cover the steps to follow to create your own Nodemcu image with cross compiling on Linux.

We always start from the Debian envinronment described in the previous article

Debian Envinronment

 According the following link

Cross Compilation

as first step we prepare the cross compiling envinronment.

Log on Debian with our development user (sviluppo in our case) and create an esp8266 folder in  a terminal window

We install the prerequisites

We download the open-esp-sdk repository

to proceed to its compilation

At the end of the compilation we have the following messages

So we have to include in the PATH variable the following

We can clone at this point the Nodemcu firmware github. Always from the previous terminal window run

Once placed in the esp8266 folder execute

At the end go into the nodemcu-firmware folder

Before proceeding to the creation of our first firmware we have to make  changes in the app / include / user_config.h file configuration:

  • We enable the directive for our devkit 0.9 (our devkit)

#define DEVKIT_VERSION_0_9 1     // define this only if you use NodeMCU devkit v0.9

  • We change the USB communication speed (speed for our devkit)

//#define BIT_RATE_DEFAULT BIT_RATE_115200

  • We change the flash size to 4M (flash of our nodemcu devkit)

#define FLASH_4M
// #define FLASH_8M
// #define FLASH_16M

We save the file and proceed to the creation of the firmware with the command

At the end under the bin folder

we’ll find two files: 0x00000.bin and 0x100000.bin. We generate a single file nodemcu_float.bin with the command

At this point we have to enable the sviluppo user to use the usb port with the command

Debian has no need for additional USB drivers. In the presence of virtual machine enable the USB device.

Access to the SDK downloaded and compiled previously; in the bin folder copy the files

  • blank.bin
  • esp_init_data_default.bin

into the folder we generated the 0x00000.bin and 0x100000.bin files

binDefaultAt this point we are able to flash the firmware on the device using the esptool. In the next article we’ll descrive how to load the firmware

Nodemcu firmware upload with esptool

Uploading LUA code on ESP8266

After flashing the nodemcu firmware

Flashing the firmware

you can upload your own LUA script code on your device. To do this there are several tools

Uploading LUA code

In this article we’ll treat  ESPlorer


It ‘a java application available for Windows, Linux and OSX. As a prerequisite requires the presence of Java SE ver. 7 or higher.

Download the tool from the link listed below to a folder

ESPlorer Download

To run it excecute from command prompt

or we can use a script in dos or unix (ESPlorer.bat or ESPlorer.sh).

At this point we plug the Nodemcu devkit to the PC and set the communication parameters and the speed of the COM port.

In Windows we have the following screen


You can press Open, which allows access to the device.


You can proceed at this point to the creation of your own code in LUA script and upload it on the ESP8266; you can use the various modules available in the  firmware according to the documentation

Nodemcu API

In the next article we’ll describe how to compile your personalized firmware in Linux

Nodemcu compilation

Flashing the firmware using Nodemcu Flasher

In the previous article we examined the different ways to flash the firmware

Flashing Nodemcu firmware

Now we describe how to proceed in Windows.

Looking at the Nodemcu firmware github

Nodemcu github

we find the followng application for Windows

 Nodemcu flasher

 We download the version compatible with our Windows operating system (32 or 64 bit)

First operation is to install the USB-Serial chip drivers of our Nodemcu Devkit, as specified in previous article. We have a devkit Nodemcu ver. 0.9, so we have to install the CH340G drivers

CH340G Drivers

After the drivers installation we can download the Nodemcu flasher in a folder and plug the  USB-Micro Usb cable between the pc and the devkit. Our COM port should be visible in the Windows device manager in the COM  devices list


In our case it is available on the COM port 5.

The steps to follow are the following:

  • Run Nodemcu Flasher and choose the COM5 port.


  • In Config select  INTERNAL://NODEMCU  with address 0x00000.


  •  In Advanced we have the following parameters
    • Baudate: 9600 as specified in our devkit.
    • Flash size: 4MByte. Flash size of our devkit.
    • Flash Speed: 40MHz. The default speed.
    • SPI Mode: DIO is the default for 4Mb flash size.


  • Proceed with the flash of the firmware pressing the FLASH button


  • The application shows a progress bar of the operation


At the end you can close the window and make sure everything is working properly using a LUA script uploader program, which we’ll see in the next article

Uploading LUA code


How to flash the Nodemcu firmware

In previous article we described the ESP8266 wifi module integrate into the Nodemcu development kit

ESP8266 WiFi Module

Here we look at how to load the firmware on the device.

First step is to assess the nodemcu development kit model we are working with. In our case we’ll perform the various operations with a development board Nodemcu V0.9. The USB-Serial chipset in this case is the CH340G

The drivers for this chipset can be downloaded directly from github of nodemcu

USB-Serial Drivers

To load the firmware, you can use the methods described in the Nodemcu site

Flashing Firmware

Basically there are two main methods:

  • Flash through the Windows Nodemcu Flasher tool

Nodemcu Flasher

  • Flash via a utility in Python to use in Linux, OSX or Windows


The Nodemcu flasher tool allows you to load a default firmware on the card  intuitively and quickly.

As can be seen from the above documentation of the  devkit you do not need to take any action on the pin GPI0 ESP to put the devive in flash mode; the flash operation and execution start automatically.

In the next article we’ll flash the firmware using the Nodemcu Flasher tool

Flashing the firmware with Nodemcu Flasher