Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Industrial Internet of Things >> Internet of Things Technology

IIoT Edge Development with Modbus: Building a Secure Sensor Data Flow on Raspberry Pi

IIoT Edge Development with Modbus: Building a Secure Sensor Data Flow on Raspberry Pi Editor’s Note: The Industrial Internet of Things (IIoT) unlocks deep insights into industrial operations, boosting efficiency across connected systems. Large‑scale IIoT deployments rely on layered architectures to gather data from diverse sensors, securely transmit it to the cloud, and perform analytics that drive real‑world value. This chapter delves into IIoT edge development, focusing on the Modbus protocol as a lightweight, proven solution for serial communication.

Adapted from Industrial Internet Application Development, by Alena Traukina, Jayant Thomas, Prashant Tyagi, Kishore Reddipalli.


Chapter 3. IIoT Edge Development (Continued)

Industrial M2M Protocols – Modbus

In this section we build a compact IoT application that sends sensor data from a Raspberry Pi hub to a receiver device (a PC or cloud) using Modbus TCP, the application‑layer variant of Modbus.

IIoT Edge Development with Modbus: Building a Secure Sensor Data Flow on Raspberry Pi
Data flow from a sensor simulator to a receiver device

Modbus is ideal for devices with constrained hardware: it’s simple, open‑source, and widely supported. Below is a concise specification snapshot to help you decide if Modbus meets your requirements.

KeyValue
Open sourceYes*
OSI LayerTransport or Application
Data typesInteger, float, string, Boolean
Limitations• No large binary objects
• Master polls devices for changes*
• Max 254 devices per link*
• Only contiguous transmissions
OperationsRead/write registers & coils, diagnostics
LatencyHigh
UsageSMS, GPRS, wireline, wireless, mesh
SecurityNone
CompressionNone

Values marked with * vary across implementations.

Building Blocks

Preparing the SD Card

  1. Download the latest Raspbian Lite image from Raspberry Pi Downloads.
  2. Insert the SD card into a computer and flash the image using Etcher (https://www.balena.io/etcher/).
  3. Enable SSH by creating an empty file named ssh in the boot partition:
    cd /Volumes/boot
    touch ssh
  4. To enable Wi‑Fi, create network.conf with:
network={
    ssid="YOUR_SSID"
    psk="YOUR_WIFI_PASSWORD"
}

Use nano to edit the file in the Linux console.

  1. Create the project directory: /home/pi/hub.
  2. In /home/pi/hub/package.json add:
{
    "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"
    }
}
  1. In /home/pi/hub/index.js implement the Modbus client to send data to your server. Replace the placeholders with real addresses:
    const modbus = require('modbus');
    const request = require('request');
    // Example: read sensor register and POST to remote server
    // (insert actual logic here)
    
  1. Create /home/pi/hub/Dockerfile:
    FROM hypriot/rpi-node:boron-onbuild
    RUN apt-get update && apt-get install -y libmodbus5
    
  1. Create sensor project directory: /home/pi/sensor.
  1. In /home/pi/sensor/package.json add:
    {
        "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"
        }
    }
  1. In /home/pi/sensor/index.js implement the sensor simulator and Modbus TCP client. Replace REMOTE-HUB-ADDRESS.com with the hub’s IP or hostname:
    const modbus = require('modbus');
    // Example: simulate sensor reading and write to Modbus
    // (insert actual logic here)
    
  2. Create /home/pi/sensor/Dockerfile:
    FROM hypriot/rpi-node:boron-onbuild
    RUN apt-get update && apt-get install -y libmodbus5
    

Deploying the Solution

Build Docker images, push them to a registry, and run containers on the Raspberry Pi. Ensure the hub and sensor containers can communicate over the local network. Once deployed, the sensor simulator will publish data via Modbus TCP to the hub, which forwards it to your cloud endpoint.

By following this guide you’ll have a robust, low‑overhead IIoT edge stack that demonstrates the power of Modbus in real‑world industrial scenarios.

Internet of Things Technology

  1. DocBox CEO on Building Data‑Centric, Interoperable Healthcare IoT Solutions
  2. IoT Edge Computing: Bridging Devices and Cloud for Real‑Time Insights
  3. Accelerate Modbus Device Integration with an Open‑Source IIoT Edge Gateway
  4. Prototyping IIoT Edge Devices: A Practical Guide
  5. Enhancing IIoT Edge Development with WebSockets: Secure, Real‑Time Connectivity
  6. Implementing HTTP Connectivity for IIoT Edge Devices: A Raspberry Pi DHT-12 Tutorial
  7. Leveraging OPC UA for Robust IIoT Edge Development
  8. Step‑by‑Step Guide: Extracting PLC Data with IIoT for Real‑Time Insights
  9. Future Outlook: Advancing Industrial IoT for Production Excellence
  10. Unlocking Actionable Edge Insights with AI & ML