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

Seamless Modbus Sensor Integration Using EdgeX Foundry on Raspberry Pi

Seamless Modbus Sensor Integration Using EdgeX Foundry on Raspberry Pi

Industrial Internet of Things (IIoT) deployments increasingly rely on edge gateways to bridge Modbus‑enabled peripherals with cloud analytics. Building a proprietary gateway can be expensive and slow. This case study demonstrates how an open‑source framework—EdgeX Foundry—can be deployed on a Raspberry Pi to connect a Modbus temperature‑humidity sensor, stream data to the cloud, and trigger real‑time actuations with minimal effort.

Why Modbus and EdgeX?

Modbus is an open, lightweight protocol that runs over inexpensive RS‑485 links. It uses simple registers (16‑bit unsigned integers) for analog values and coils for binary states, making it ideal for industrial devices. EdgeX Foundry, an open‑source edge middleware, acts as the bridge between physical sensors and IT systems, providing device management, data transformation, and cloud connectivity out of the box.

Hardware Stack

Figure 1: Seamless Modbus Sensor Integration Using EdgeX Foundry on Raspberry Pi Figure 1. EdgeX Foundry – open‑source edge middleware

Figure 2: Seamless Modbus Sensor Integration Using EdgeX Foundry on Raspberry Pi Figure 2. High‑level block diagram of the EdgeX deployment

Step‑by‑Step Integration

  1. Set up the Raspberry Pi
    • Install Ubuntu 20.04 LTS with Docker and docker‑compose.
    • Clone the EdgeX Foundry repository and launch the stack via docker‑compose.
  2. Simulate the Modbus device
    • Use ModbusPal (GPL) to emulate up to 247 Modbus slaves.
    • Configure a slave with holding registers for temperature (address 2) and humidity (address 3). Each register maps to a 16‑bit integer that will be scaled to °C and %RH.
    • Start ModbusPal over TCP or serial (USB‑RS485) to verify communication.
  3. Upload the device profile

    Send a POST request to https://localhost:48081/api/v1/deviceprofile/uploadfile with the YAML file containing the profile (see below). The response returns a unique profile ID.

  4. Register the device

    Post the following JSON to https://localhost:48081/api/v1/device to create the sensor entry. The protocols.modbus‑rtu section points to /dev/ttyUSB0 at 9600 baud.

    {
      "name": "TemperatureHumiditySensor",
      "description": "Industrial Grade Temperature & Humidity Transmitter SHT20",
      "adminState": "UNLOCKED",
      "operatingState": "ENABLED",
      "protocols": {
        "modbus-rtu": {
          "Address": "/dev/ttyUSB0",
          "BaudRate": "9600",
          "DataBits": "8",
          "StopBits": "1",
          "Parity": "N",
          "UnitID": "1"
        }
      },
      "labels": ["TemperatureHumiditySensor","modbusRTU"],
      "service": {"name": "edgex-device-modbus"},
      "profile": {"name": "TemperatureHumiditySensor"},
      "autoEvents": [
        {"frequency": "5s", "onChange": false, "resource": "TemperatureDegC"},
        {"frequency": "5s", "onChange": false, "resource": "HumidityPercentRH"}
      ]
    }
  5. Verify data flow
    • EdgeX’s device service pulls data every 5 s and writes to the core service, which stores it in Redis.
    • Application services forward the data to the IBM Cloud (or any cloud of choice).
    • Example log entries show the Modbus request/response packets.
  6. Actuate LEDs with Kuiper rules engine
    • Define rules: if temperature > 30 °C turn on red LED; if < 30 °C turn it off; similarly for blue LED at 28 °C.
    • Kuiper pushes commands to EdgeX core‑command, which then updates the GPIO device service.
    • GPIO outputs are verified via /sys/class/gpio/gpio12/value and /sys/class/gpio/gpio14/value.

Key Configuration Snippets

Device profile (YAML)

name: TemperatureHumiditySensor
manufacturer: ROBOKITS
model: RKI-4879
labels:
  - SHT20
description: Industrial Grade Temperature & Humidity Transmitter SHT20 Sensor High Precision Monitoring Modbus RS485
deviceResources:
  - name: TemperatureDegC
    description: Room Temperature in Degrees Celsius.
    attributes: { primaryTable: INPUT_REGISTERS, startingAddress: 2, rawType: INT16 }
    properties:
      value: { type: Float32, readWrite: R, scale: 0.1, floatEncoding: eNotation }
      units: { type: String, readWrite: R, defaultValue: degrees celsius }
  - name: HumidityPercentRH
    description: Room Humidity in %RH.
    attributes: { primaryTable: INPUT_REGISTERS, startingAddress: 3, rawType: INT16 }
    properties:
      value: { type: Float32, readWrite: R, scale: 0.1, floatEncoding: eNotation }
      units: { type: String, readWrite: R, defaultValue: %RH }
deviceCommands:
  - name: TemperatureDegC
    get: [{ index: 1, operation: get, deviceResource: TemperatureDegC }]
  - name: HumidityPercentRH
    get: [{ index: 2, operation: get, deviceResource: HumidityPercentRH }]
coreCommands:
  - name: TemperatureDegC
    get:
      path: /api/v1/device/{deviceId}/TemperatureDegC
      responses:
        - code: 200
          description: Get the temperature in degrees C
          expectedValues: [TemperatureDegC]
  - name: HumidityPercentRH
    get:
      path: /api/v1/device/{deviceId}/HumidityPercentRH
      responses:
        - code: 200
          description: Get the humidity in %RH
          expectedValues: [HumidityPercentRH]

device‑modbus TOML configuration (excerpt)

[DeviceList]
  Name = "TemperatureHumiditySensor"
  Profile = "TemperatureHumiditySensor"
  Description = "Industrial Grade Temperature & Humidity Transmitter SHT20"
  labels = ["TemperatureHumiditySensor","modbusRTU"]
  [DeviceList.Protocols.modbus-rtu]
    Address = "/dev/ttyUSB0"
    BaudRate = 9600
    DataBits = 8
    StopBits = 1
    Parity = "N"
    UnitID = 1
  [[DeviceList.AutoEvents]]
    Frequency = "5s"
    OnChange = false
    Resource = "TemperatureDegC"
  [[DeviceList.AutoEvents]]
    Frequency = "5s"
    OnChange = false
    Resource = "HumidityPercentRH"

Results

The end‑to‑end flow shows real‑time temperature and humidity data arriving in the IBM Cloud, triggering rule‑based LED status changes, and demonstrating the full capabilities of EdgeX on a low‑cost Raspberry Pi.

Conclusion

EdgeX Foundry enables rapid deployment of Modbus‑based IIoT solutions with minimal development overhead. By abstracting device management, data storage, and cloud connectivity, it frees engineers to focus on domain logic and analytics.

Acronyms

AcronymExpansion
AOFAppend Only File
APIApplication Program Interface
AWSAmazon Web Services
BACnetBuilding Automation and Control Network
BLEBluetooth Low Energy
CURLClient Uniform Resource Locator
GPIOGeneral Purpose Input Output
HTTPHypertext Transfer Protocol
IBMInternational Business Machines
IIoTIndustrial Internet of Things
IoTInternet of Things
ITInformation Technology
LEDLight Emitting Diode
LTSLong Term Support
M2MMan to Machine
MQTTMessage Queuing Telemetry Transport
RDBRedis Database
RedisREmote DIctionary Server
RESTRepresentational State Transfer
RS‑485Recommended Standard – 485
SCADASupervisory Control and Data Acquisition
SQLStructured Query Language
TCP/IPTransmission Control Protocol/Internet Protocol

Internet of Things Technology

  1. OpenDDS vs. RTI Connext DDS: Choosing the Right Data Distribution Service Solution
  2. A Beginner’s Guide to Open‑Source Terminology
  3. Accelerate Modbus Device Integration with an Open‑Source IIoT Edge Gateway
  4. IIoT Edge Development with Modbus: Building a Secure Sensor Data Flow on Raspberry Pi
  5. Designing ADC Drivers: Blocking vs. Non‑Blocking Polling Techniques
  6. Cisco Unveils Catalyst 5G Industrial Routers to Seamlessly Connect Enterprise and Edge Networks
  7. Advanced Vibration Sensors for IIoT: Empowering Predictive Maintenance & Asset Reliability
  8. Why Open Source Drives Innovation at the Edge – Essential eBook
  9. Open Source Powers the Rise of IoT and Edge Computing
  10. Master Edge AI Inferencing: A Practical Guide to Actionable Insights