Tag Archives: debian

MQTT with BeagleBone and ESP8266 – MQTT on ESP8266 with temperature sensor

After loading the firmware into the device esp8266

MQTT with BeagleBone and ESP8266-MQTT ESP8266

we now connect this module with a DHT11 temperature and humidity sensor. Here is how we connect the sensor to the ESP module

nodemcu dht11

In this example we will consider the option of putting the nodemcu in sleep. To have the node back form the sleep  the system has to reboot and  it is necessary to connect the PIN D0 (GPIO16) to RST PIN as specified in the nodemcu documentation

Nodemcu sleep

Let us take a look at the lua code; It consists of init.lua and tempumid.lua files.

We analyze now the main points of each file

  • init.lua

In the file we set the the parameters to access the wifi network, the address and port of the MQTT broker  and the file to be run on the ESP after wifi connection to the access point is estabilished. If the ESP does’t acquire the netowrk address the system is restarted.

  • tempumid.lua

The temumid.lua file manages the measurement of temperature and humidity, the subscription on MQTT broker with submission of the data. Global parameters have been set to manage the topic, the waiting time in tmr.alarm. There are in particular the following topics

  • /home/room1/temperature: measured temperature topic.
  • /home/room1/humidity: measured humidity topic.
  • /home/room1/status : Status topic. The status is sent at the start and at  request from the command topic /home/room1/command.
  • /home/room1/monitor: Status of the esp sent periodically to this topic.
  • /home/room1/command: Other clients can send commands to the esp:
    • Restart: Restarts the esp.
    • Sleep n: Put to sleep for n seconds the esp.

There are various service functions to manage all. The comments in the code describe each feature.

In the next article we will set up the esp with the relay

MQTT with BeagleBone and ESP8266 – MQTT on ESP8266 with Relay

 

Mqtt with Beaglebone and ESP8266-MQTT ESP8266

After installing the MQTT server on BeagleBone

Mqtt with Beaglebone and ESP8266-Mosquitto installation on Beaglebone

let us set the MQTT nodes on ESP8266.

As first operation we must generate the nodemcu firmware, as described in the previous article

Nodemcu compilation on Linux

with at least the following parameters activated in user_module.h file

  • DHT
  • file
  • GPIO
  • MQTT
  • net
  • node
  • timer
  • UART
  • WiFi

These settings are the default in the user_module.h file.

At present the latest version 2.0 of nomemcu firmware was released. Here are the compiled files for this version of the firmware

Nodemcu2.0.0 firmware

As already described in previous articles and from the nodecmu link on flashing

Flashing the firmware

 we have to set the correct parameters for  the  esp8266 model.

In our case, with 4MB flash, we used the parameters shown in the image to load the firmware on the device with nodemcu-flasher tool. You can also use other tools for loading the firmware. In our case, the settings used are as follows

nodemcu flasherIn the next article we’ll treat the ESP8266 node that detects temperature and humidity

MQTT with BeagleBone and ESP8266 – MQTT on ESP8266 with temperature sensor

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

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

MQTT

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

MQTT Faq

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

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

Generating Images for BeagleBone with Omap Image Builder

This article describes how to proceed to the autonomous creation of an image for the BeagleBone Black /Green using the Omap Image Builder. In this specific example we create the image for the BeagleBone Black Rev. C.

The informations on the procedure to be followed are available on the site

Omap image builder

As a prerequisite to the creation of the image there is the need to perform the operations on arm hardware; with other systems it is possible to have issues. To this end, we will proceed to perform tasks on a  Orange PI PC with Armbian operating system. After preparing the Armbian system for Orange PI PC, as described in

Armbian Boot on Orange PI PC

log  in  ssh on Orange PI PC; in our case we used the sviluppo/password credentials

ssh on Orange PI PC

It is possible also to connect  by enabling Remote Desktop

Remote desktop setup for Armbian on Orange PI PC

Create a folder named beaglebone

Clone the code to create the image

The folder tree is the following

We proceed first to the creation of a standard Debian 8 image for Beaglebone Black

The task takes a long time and creates other folders including the deploy folder within which we will find the images. At the end go into deploy /image folder and run

Compress the created image with the command

To create a customized image proceed as follows:

  1. Go into the image-builder/configs folder and copy a configuration as base named custom-debian.conf. We have used as a base configuration bb.org-debian-jessie-lxqt-4gb-v4.1.conf. In custom-debian.conf add the following changes in  the deb_include section; as example we add the vsftpd server; change the chroot_script value too


    To exclude packages to be installed use the deb_exclude section. In the script are commented the various sections, among which we find those about  the definition of the hostname, passwords, user name creation, etc.
  2. Navigate to the image-builder/target/chroot folder and copy beagleboard.org-jessie.sh as custom-debian.sh.
  3. If you want to add python packages edit the custom-debian.sh file and add the other packages in install_pip_pkgs function

In this example we added only the ftp server. Go into the image-builder folder and run the command

The task  takes a long time. At the end access to the deploy/imagename folder and run

Compress the created image with the command

You can create now the micro sd card  with the FTP server available in the image  and the hostname changed in beagleboneblack.

The microSD burning  is already described in the article

Debian sdcard setup for Beaglebone Black

On Omap image builder site you’ll find other images types among which we highlight those for BeagleBone Black, Green, Iot, Machine Kit (image to manage Machinekit CNC machines), etc.

C Eclipse project reading temperature and humidity on Beaglebone

After the cross building and DHT11 sensor setup on Beaglebone Black

Remote debug on Beaglebone

Sensors on Beaglebone

Temperature and humidity reading on Beaglebone in python

now we show how to create a C project , using  the C source code available with the Adafruit library

Adafruit Python DHT Sensor Library

Using Eclipse, we create a project for the reading of our sensor. It calls the functions in the C code of the Adafruit library. These sources are imported into the Eclipse project

Dht sensor Projectand using the sample C code  dhtSensor.c,  which contains the main C program, we read the sensors by calling the funtions available in Adafruit C sources; the usage is  similar to what seen in Python.

Running

 it shows the help instructions

To read the DHT11 sensor on pin P8_11 we have to run

The output is the following

DHT sensor reading in CHere is the Eclipse C project

dhtSensor Eclipse project

DHT11 sensor reading on BeagleBone with node.js

In the previous article we read the temperature and humidity from DHT11 sensor in python

Temperature and humidity reading on Beaglebone in python

We perform now the same operation in javascript. We download the  dht module for node.js. The module is available on the website

beaglebone dht

Log on BeagleBone in ssh as debian (temppwd as password) and run

to install the module globally.

For the sensor reading create a file test.js  with the following code inside

Reading is performed running

The result in our case is the following

temperature reading node.jsThe same code can be run from Cloud9 IDE. Access the IDE on BeagleBone with the link http: //beaglebone.local:3000 and create a file named dht.js with the following code inside

The script execution gives the following result

DHT11 cloud9Here is the link to download the two sample files

Node.js sample

Cloud9 sample

Temperature and humidity reading on Beaglebone in python

In the previous article we connected the DHT11 sensor to the Beaglebone

Sensors on Beaglebone

We install at this point the library in python and modules in c to read the sensor. The site with documentation about the library is

Adafruit Python DHT Sensor Library

Log in ssh on Beaglebone as root / no password and create the temperature folder from which we run

Install the prerequisites

Proceed to the installation of the library with the python command

Enter the examples directory and do the following for reading the sensor values (dht 11 and pin P8_11)

The result in this case is the following

temperature reading

Sensors on Beaglebone

After describing the Beaglebone and its development tools

Startup of the Beaglebone development board

Development tools on Beaglebone

as an example we show how to interact with the Beaglebone and a temperature and humidity sensor.

Among the most popular we finde the DHT11 sensor. The sensor has 4 pin; we have to connnect it to the power supply through a resistance of 4.7 or 10 kΩ. In our case we have a three-pin DHT11 sensor with the resistance already included in the circuit. In the case of the only sensor follow as specified in the following article

DHT humidity sensor

The following image shows the connections with Beaglebone

Beaglebone DHT11In the article Development tools on Beaglebone we showed the Beaglebone headers; in this case we used  3.3V,  ground and P8_11 headers.

In the next article we will install a library in python and modules in C to read temperature and humidity

Temperature and humidity reading on Beaglebone in python

Remote debug on Beaglebone

In the previous article we have prepared the environment with Eclipse for cross building for BeagleBone

Cross building for Beaglebone

Now we shall configure Eclipse and BeagleBone to debug the code directly on BeagleBone.

On BeagleBone install gdbserver

On the Debian system with Eclipse install gdb-multiarch

From Eclipse access to Run-> Debug Configurations

debug configurationsDouble-click C++  Remote Application to set parameters

Remote debugger configurationAt the next window, create a new ssh connection with the New button

New connectionEnter the parameters for the connection

Connection parametersSet the remote destination folder for the file  and execution management; with the browse button choose where to copy the files, and with the field “Commands to execute before application” will give execute permissions to the file

Remote foldersIn our case we create a folder esempi under /root on the  BeagleBone where to debug remotely

main debug settingsSet the multarch debugger in the Debugger Tab and other startup parameters and gdb command line settings

Debugger multiarch settingsSet the port of the remote debug server installed on BeagleBone in the Gdbserver Settings Tab

debug server settingsCreate .gdbinit files in the project folder with the command

touch debugTo start debugging run the configuration we set

debug runEclipse connects with BeagleBone and performs remote debugging  opening the Debug Perspective

debug perspective