You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+80-6Lines changed: 80 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -91,13 +91,17 @@ This includes the basic configuration for the plugin such as poll rate and the c
91
91
- connection to thin-edge.io (MQTT broker needs to match the one of tedge)
92
92
- log level (e.g. INFO, WARN, ERROR)
93
93
- measurement combination (opt-in feature to reduce the amount of created measurements in the cloud)
94
+
- subscribe_topics (MQTT topics for receiving write commands)
94
95
95
96
### devices.toml
96
97
97
98
This file includes the information for the connection(s) to the Modbus server(s) and how the Modbus Registers and Coils map to thin-edge’s Measurements, Events and Alarms. It's also possible to overwrite the measurement combination on a device level and on every single measurement mapping.
98
99
99
100
The device config can be managed via Cumulocity IoT or created with the Cloud Fieldbus operations.
100
101
102
+
Key configuration fields:
103
+
-`name` - Required for name-based write operations. Used to match metrics in write commands.
104
+
101
105
### Updating the config files
102
106
103
107
A watchdog observer will take care of restarting the MQTT and Modbus connection when either
@@ -172,11 +176,47 @@ For adding a modbus RTU device you need to use unit-ID of the slave device in th
172
176
173
177
### Write operations
174
178
175
-
The plugin supports writing to Modbus registers and coils through Cumulocity IoT operations.
179
+
The plugin supports writing to Modbus registers and coils through thin-edge.io commands (modbus_SetRegister/modbus_SetCoil) or Cumulocity IoT operations (c8y_SetRegister/c8y_SetCoil).
180
+
181
+
#### thin-edge.io Commands
182
+
183
+
The plugin subscribes to MQTT topics for receiving write commands:
184
+
-`te/device/+///cmd/modbus_SetRegister/+` - for writing to registers
185
+
-`te/device/+///cmd/modbus_SetCoil/+` - for writing to coils
186
+
187
+
These commands are processed directly by the modbus reader service. The Cumulocity operations (c8y_SetRegister/c8y_SetCoil) are converted to thin-edge.io commands via operation templates.
188
+
189
+
#### Payload Formats
190
+
191
+
The plugin supports two payload formats for write operations:
192
+
193
+
1.**Explicit address format** - directly specify register/coil address and parameters
194
+
2.**Name-based format** - use metrics array with name field to match configuration in devices.toml
195
+
196
+
For the name-based format, the `name` field in devices.toml registers/coils configuration is required to match the metrics. The matching uses prefix matching: if the metric name starts with the configured name, it will match. For example, a metric name `"test_test_setPoint"` will match a register with `name = "test_test"` in devices.toml.
197
+
198
+
**Command Status Flow:**
199
+
- Commands with `"status": "init"` are automatically converted to `"executing"` by the plugin
200
+
- The plugin processes the command and updates status to `"successful"` or `"failed"`
201
+
- The topic format must be: `te/device/<device-name>///cmd/modbus_SetRegister/<mapper-id>` where `<device-name>` must match a device name in devices.toml
202
+
203
+
Example name-based payload input for modbus plugin:
204
+
```json
205
+
{
206
+
"status": "init",
207
+
"metrics": [{
208
+
"name": "Test_Int16_xxxxxxxx",
209
+
"timestamp": "2025-09-23T01:00:00Z",
210
+
"value": 123
211
+
}]
212
+
}
213
+
```
214
+
215
+
#### Write to Register (c8y_SetRegister / modbus_SetRegister)
176
216
177
-
#### Write to Register (c8y_SetRegister)
217
+
Write values to Modbus registers. The plugin supports both integer and float register writes.
178
218
179
-
Write values to Modbus registers requires the following json to be included in the operation:
219
+
**Explicit Address Format:**
180
220
181
221
```json
182
222
{
@@ -192,6 +232,26 @@ Write values to Modbus registers requires the following json to be included in t
192
232
}
193
233
```
194
234
235
+
236
+
**Integer Register Writes:**
237
+
- For integer registers, the plugin performs a read-modify-write operation
238
+
- It first reads the current register value, applies bit masking based on `startBit` and `noBits`, then writes the updated value
239
+
- This ensures that only the specified bits are modified while preserving other bits in the register
240
+
241
+
**Float Register Writes (Name-based format only):**
242
+
- Float values are supported for registers configured with `datatype = "float"` in devices.toml
- The plugin automatically handles endianness conversion based on the device's `littlewordendian` setting
245
+
- Float writes require the name-based format and proper configuration in devices.toml
246
+
247
+
**Protocol Support:**
248
+
- TCP/IP Modbus: Specify `ipAddress` and ensure the device is reachable
249
+
- RTU Modbus: Device must be configured in devices.toml with serial port settings
250
+
251
+
**Error Handling:**
252
+
- If the Modbus device is offline or unreachable, the command will immediately fail with status `"failed"`
253
+
- No automatic retry mechanism is implemented; failed commands must be resent
254
+
195
255
To create an operation to write a value to a Modbus register using Cumulocity, you can use the [go-c8y-cli](https://goc8ycli.netlify.app/docs/cli/c8y/operations/c8y_operations_create/) tool:
196
256
197
257
```
@@ -205,10 +265,11 @@ In the Cumulocity UI, the widget '[Asset table](https://cumulocity.com/docs/cock
205
265

206
266
207
267
208
-
#### Write to Coil (c8y_SetCoil)
268
+
#### Write to Coil (c8y_SetCoil / modbus_SetCoil)
269
+
270
+
Write values to Modbus coils. Coils are single-bit outputs that can be set to 0 or 1.
209
271
210
-
Write values to Modbus coils requires the following json to be included in the operation:
211
-
:
272
+
**Explicit Address Format:**
212
273
213
274
```json
214
275
{
@@ -222,6 +283,19 @@ Write values to Modbus coils requires the following json to be included in the o
222
283
}
223
284
```
224
285
286
+
**Name-based Format:**
287
+
- Coils can be written using the name-based format with metrics array
288
+
- The coil `name` in devices.toml must match the metric name (using prefix matching)
289
+
- The metric value must be 0 or 1
290
+
291
+
**Protocol Support:**
292
+
- TCP/IP Modbus: Specify `ipAddress` and ensure the device is reachable
293
+
- RTU Modbus: Device must be configured in devices.toml with serial port settings
294
+
295
+
**Error Handling:**
296
+
- If the Modbus device is offline or unreachable, the command will immediately fail with status `"failed"`
297
+
- No automatic retry mechanism is implemented; failed commands must be resent
298
+
225
299
To create an operation to write a value to a Modbus coil using Cumulocity, you can use the [go-c8y-cli](https://goc8ycli.netlify.app/docs/cli/c8y/operations/c8y_operations_create/) tool:
0 commit comments