Hello Lukas,
Typically, the data sourced from modbus is stored in an array. Create an observation on the modbus value which in turn will create a stream. If you point your observation to an edge action, you can collect all of the modbus values and use the edge action to read / transform your modbus data and send it in a single stream (orchestrate).
Here is an example observation on a modbus resource that creates a stream.
The data will be transmitted from the device to a stream containing events that look like this example:
{
“creationDate”: 1640021348059,
“creatorId”: “i000000000000000000000001”,
“elems”: {
“modbus”: {
“UART1”: {
“rht_sensor”: {
“address”: {
“data”: [
1
],
“error”: {
“errno”: 0
}
},
“dewpoint”: {
“data”: [
83
],
“error”: {
“errno”: 0
}
},
“error”: {
“data”: [
55537
],
“error”: {
“errno”: 0
}
},
“humidity”: {
“data”: [
445
],
“error”: {
“errno”: 0
}
},
“temperature”: {
“data”: [
211
],
“error”: {
“errno”: 0
}
}
}
}
}
},
“generatedDate”: 1640021344868,
“hash”: null,
“id”: “e61c0bd6465e8935288e1d8a4”,
“lastEditDate”: 1640021348059,
“lastEditorId”: “i000000000000000000000001”,
“location”: null,
“metadata”: {
},
“path”: “/iot_solutions/devices/fx30s/rht_direct”,
“streamId”: “s61c0bd35aa08443531447bf9”,
“tags”: {
“iotcentalnam”: “true”
}
}
You can send all the data directly to your cloud platform or use an edge action to collect and transform the modbus data you need. Here is an example edge action that does just that. The edge action has logic and only sends the modbus data required from the device. It also read thresholds from virtual resources and compares those to incoming values. Finally, the data is sent to the :default stream which in turn can utilized as input into a cloud connector.
// Read threshold values from Modbus data
//console.log(event.value)
if ((event.value.temperature.error.errno==0)&&(event.value.dewpoint.error.errno==0)&&(event.value.humidity.error.errno==0)){
var temperature = event.value.temperature.data[0]/10;
var humidity = event.value.humidity.data[0]/10;
var dewpoint = event.value.dewpoint.data[0]/10;
console.log('temp: ‘+temperature+’ hum: ‘+humidity+’ dew: '+dewpoint);
// Read threshold values from Virtual Resource
var temperature_th = Resource.read("/virtual/temperature_th/value").value;
var humidity_th = Resource.read("/virtual/humidity_th/value").value;
// Control LEDs or IOs based on values vs. thresholds
if (temperature<temperature_th&&humidity<humidity_th){
return {
"cl://": [{"alert":0,"temperature":temperature," humidity":humidity," dewpoint":dewpoint,"temperature_th":temperature_th," humidity_th":humidity_th}]}}
}
This is a simple example and I hope it makes sense to you. Please let us know if you need more help directly.