Skip to content

Commit 445d270

Browse files
committed
Add readme for writing operations
1 parent 5fa91c5 commit 445d270

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Plugin for polling Modbus devices and publishing the data to thin-edge.io. If us
1919
- [Log file access](#log-file-access)
2020
- [Config management](#config-management)
2121
- [Cloud Fieldbus](#cloud-fieldbus)
22+
- [Writing operations](#writing-operations)
2223

2324
- [Testing](#testing)
2425
- [Build](#build)
@@ -169,6 +170,74 @@ After creating the protocol, you can add a new Cloud Fieldbus Device. Select the
169170

170171
For adding a modbus RTU device you need to use unit-ID of the slave device in the configuration.
171172

173+
### Write operations
174+
175+
The plugin supports writing to Modbus registers and coils through Cumulocity IoT operations.
176+
177+
#### Write to Register (c8y_SetRegister)
178+
179+
Write values to Modbus registers requires the following json to be included in the operation:
180+
181+
```json
182+
{
183+
"c8y_SetRegister": {
184+
"input": false,
185+
"address": 1,
186+
"register": 3,
187+
"startBit": 0,
188+
"noBits": 16,
189+
"value": 23,
190+
"ipAddress": "192.168.1.100"
191+
}
192+
}
193+
```
194+
195+
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+
197+
```
198+
c8y operations create --device 12345 --template '{"c8y_SetRegister": { "input": false, "address": 1, "startBit": 0, "noBits": 16, "ipAddress": "192.168.1.2", "value": 23, "register": 3 }}' --description 'Writing a register'
199+
```
200+
201+
Or use [REST API](https://cumulocity.com/api/core/#operation/postOperationCollectionResource).
202+
203+
In the Cumulocity UI, the widget '[Asset table](https://cumulocity.com/docs/cockpit/widgets-collection/#asset-table)' can be used to create operations for the device.
204+
205+
![Image](./doc/write-register-asset-table.png)
206+
207+
208+
#### Write to Coil (c8y_SetCoil)
209+
210+
Write values to Modbus coils requires the following json to be included in the operation:
211+
:
212+
213+
```json
214+
{
215+
"c8y_SetCoil": {
216+
"input": false,
217+
"address": 1,
218+
"coil": 48,
219+
"value": 1,
220+
"ipAddress": "192.168.1.100"
221+
}
222+
}
223+
```
224+
225+
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:
226+
227+
```
228+
c8y operations create --device 12345 --template '{"c8y_SetCoil": { "input": false, "coil": 48, "address": 1, "value": 1, "ipAddress": "192.168.1.100" } }' --description 'Writing a coil'
229+
```
230+
231+
Or use the [Cumulocity REST API](https://cumulocity.com/api/core/#operation/postOperationCollectionResource).
232+
233+
In the Cumulocity UI, the widget [Asset table](https://cumulocity.com/docs/cockpit/widgets-collection/#asset-table) can be used to create operations for the device.
234+
235+
![Image](./doc/write-coil-asset-table.png)
236+
237+
238+
:construction: The plugin does not yet support Cumulocity Fieldbus device widget. Please follow the above instrucstions to create operations.
239+
240+
172241
## Testing
173242

174243
To run the tests locally, you need to provide your Cumulocity credentials as environment variables in a .env file:

doc/write-coil-asset-table.png

112 KB
Loading

doc/write-register-asset-table.png

113 KB
Loading

0 commit comments

Comments
 (0)