IIoT edge development - Using Modbus
Editor's Note: The Industrial Internet of Things (IIoT) promises to provide deep insight into industrial operations and enhance efficiency of connected machines and systems. Large-scale IIoT applications rely on layered architectures to collect data from a broad range of sensors, move data reliably and securely to the cloud, and perform analysis required to deliver that insight and efficiency. In Industrial Internet Application Development, the authors provide a detailed examination of the IIoT architecture and discuss approaches for meeting the broad requirements associated with these systems.
Adapted from Industrial Internet Application Development, by Alena Traukina, Jayant Thomas, Prashant Tyagi, Kishore Reddipalli.
Chapter 3. IIoT Edge Development (Continued)
By Alena Traukina, Jayant Thomas, Prashant Tyagi, Kishore Reddipalli
Industrial M2M protocols – Modbus
In this section, we will try to build a simple IoT application for sending data from a sensor simulator module to a receiver device (a PC or a cloud), using a Raspberry Pi hub and the Modbus protocol:
Data flow from a sensor simulator to a receiver device
For devices with limited hardware resources, it makes sense to use the Modbus protocol for serial communication. While simple, it has several open and proprietary implementations that vary in functionality.
Note that this protocol can be used on the transport layer, but, in our example, we are going to use Modbus TCP, working on the application level.
In the following table, you can find a more detailed description of the protocol to understand whether it is suitable for your needs:
Key | Value |
Open source | Yes* |
The OSI layer | Transport or an application |
Data types | Integer, float, string, Boolean |
Limitations | • No support for large binary objects
• The master node regularly polls each device for data modifications* • Maximum 254 devices addressed on a single data link* • Only contiguous transmissions are allowed |
Possible operations | Read and write registers and coils, diagnostics |
Latency | High |
Usage | SMS, GPRS, wireline, wireless, mesh communication |
Security | No |
Compression | No |
Table 4: The Modbus protocol specifications
![]() |
The values marked with * are not applicable to all implementations of the Modbus protocol. |
For building the application, we will need the following:
-
Required software:
-
The Cloud Foundry CLI (https://github.com/cloudfoundry/cli#downloads)
-
Required hardware:
-
Raspberry Pi 3 (model B)
-
A power adapter (2A/5V)
-
A microSD card (8 GB+) and an SD adapter
-
An Ethernet cable for a wired network connection
-
Preparing an SD card
To prepare an SD card, follow the sequence of actions as described:
-
Download the latest Raspbian LITE image (available at https://raspberrypi.org/downloads/raspbian/).
-
Connect your SD card to a computer and use Etcher (https://io/) to flash the Raspbian .img file to the SD card.
-
Enable SSH:
cd /Volumes/boot
touch ssh
-
To enable Wi-Fi, create conf with the following content:
network={
ssid="YOUR_SSID"
psk="YOUR_WIFI_PASSWORD"
}
![]() |
To create a file in a Linux console, you can use the GNU nano editor. It is pre-installed in most Linux distributives. All you need is to run the nano FILE_NAME command and follow the displayed instructions. |
-
Create the /home/pi/hub
-
Create the /home/pi/hub/package.json file with the following content:
{
"name": "hub",
"version": "1.0.0",
"description": "",
"main": "index.js", "scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC", "dependencies": {
"modbus": "0.0.16",
"request": "^2.81.0"
}
}
-
Create the /home/pi/hub/index.js file with the following content, replacing REMOTE-SERVER-ADDRESS.com and REMOTE-SENSOR-ADDRESS with real values:
-
Create a /home/pi/hub/Dockerfile file with the following content:
FROM hypriot/rpi-node:boron-onbuild
RUN apt-get update && apt-get install -y libmodbus5
-
Create the /home/pi/sensor
-
Create the /home/pi/sensor/package.json file with the following content:
{
"name": "sensor",
"version": "1.0.0",
"description": "",
"main": "index.js", "scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC", "dependencies": {
"modbus": "0.0.16"
}
}
-
Create the /home/pi/sensor/index.js file with the following content, replacing REMOTE-HUB-ADDRESS.com with a real value:
-
Create the /home/pi/sensor/Dockerfile file with the following content:
FROM hypriot/rpi-node:boron-onbuild
RUN apt-get update && apt-get install -y libmodbus5
Continue reading on page two >>
Please confirm the information below before signing in.
{* #socialRegistrationForm *} {* firstName *} {* lastName *} {* displayName *} {* emailAddress *} {* addressCountry *} {* companyName *} {* ednembJobfunction *} {* jobFunctionOther *} {* ednembIndustry *} {* industryOther *}