Commanding Modbus Devices

We'll explain how to command Modbus devices in a few steps

Introduction

The BACE IoT Platform allows you to command modbus devices through writable modbus registers. This capability allows control over several device functions such as starting a motor pump, adjusting its speed, or updating a solar inverter's schedule. Refer to the Modbus device manual for understanding the appropriate registers to write to and the correct values to achieve the desired action.

Before writing to modbus registers via the BACE IoT Platform, please ensure:

  1. The Modbus device is onboarded onto the BACE Gateway and actively sending measurements.

  2. You have the requisite datatype for writing to the corresponding modbus device and registers.

If you have not onboarded your Modbus device yet, please visit How To Onboard Modbus Devices on how to do so.

Once your device is properly set up, you must obtain the corresponding datatype for your device. As also explained in Accessing Data, there are multiple ways to retrieve all measurements and their groups. Below is an example API request to fetch all datatypes and their latest values using id_physical_device endpoint

Get all datatypes and their latest data of a gateway

GET https://dashboard.bace-iot.com/api/v2/physical-device/{id}?expand=group.latestData

Returns all the latest measurements collected by the gateway

Query Parameters

NameTypeDescription

id*

String

id_physical_device

Writing to a Single Register

To write to a Modbus device, use the ModbusWrite endpoint. This process requires you to provide the datatype number and the desired value in the payload.

parameterdescription

datatype

Each modbus register has an index called datatype assigned by the gateway. The datatype is used for reading to and writing from modbus registers.

value

this is the value you want to write to the modbus register

Using modbus-write Endpoint

The modbus-write endpoint is your interaction point to command a device. The payload must include the datatypenumber and the desired value for execution.

Write to a Modbus Register

PUT https://dashboard.bace-iot.com/api/v2/physical-device/{id}/modbus-write

modbus-write endpoint is used for writing to modbus register(s)

Path Parameters

NameTypeDescription

id*

string

Gateway's id_physical_device

Request Body

NameTypeDescription

datatype*

int

datatype of the modbus register

value*

int/float

provide the value

{
    "status": 200,
    "payload": {
        "result": "success"
    }
}

Here is an example payload for writing to a single modbus register.

{
    "datatype": 2100,
    "value": 15
}

Writing to Multiple Registers

The endpoint can execute a write action for multiple registers simultaneously. This process requires providing all datatypes and their corresponding values within the same payload as an array. Below is an example payload to set schedule for a solar inverter:

[
  {
    "datatype": 2100,
    "value": 13
  },
  {
    "datatype": 2101,
    "value": 20
  },
  {
    "datatype": 2102,
    "value": 21
  }
]

Last updated