Dear Ditto team,
we're investigating capabilities of Ditto and we've got small problem with exposing data via Ditto connectivity.
Our case is:
- we've created simple digital twin in Ditto
- it is updated with MQTT protocol and it’s work
- no update from digital twin is received after modification of digital twin's features
Below I'll describe our configuration.
Our simple digital twin definition:
{
"policyId": "my.test:policy",
"attributes": {
"manufacturer": "Aptiv",
"VIN": "0815666337"
},
"features": {
"transmission": {
"properties": {
"rpm": 0,
"encoder": 0
}
}
}
}
Policy definition:
{
"policyId": "my.test:policy",
"entries": {
"owner": {
"subjects": {
"nginx:ditto": {
"type": "nginx basic auth user"
}
},
"resources": {
"thing:/": {
"grant": ["READ","WRITE"],
"revoke": []
},
"policy:/": {
"grant": ["READ","WRITE"],
"revoke": []
},
"message:/": {
"grant": ["READ","WRITE"],
"revoke": []
}
}
}
}
}
Also different subjects were used and it didn’t help.
Connection definition:
{
"targetActorSelection": "/system/sharding/connection",
"headers": {
"aggregate": false
},
"piggybackCommand": {
"type": "connectivity.commands:modifyConnection",
"connection": {
"id": "mqtt-aptiv-car-connection-123",
"connectionType": "mqtt",
"connectionStatus": "open",
"failoverEnabled": true,
"uri": "tcp://IP_ADDRESS:1883",
"sources": [{
"addresses": ["aptiv-car/#"],
"authorizationContext": ["nginx:ditto"],
"qos": 0,
"filters": []
}],
"targets": [{
"address": "aptiv-car-pub/{{ thing:name }}",
"topics": [
"_/_/things/twin/events",
"_/_/things/live/messages"
],
"authorizationContext": ["nginx:ditto"],
"qos": 0
}],
"mappingContext": {
"mappingEngine": "_javascript_",
"options": {
"incomingScript": "function mapToDittoProtocolMsg(headers, textPayload, bytePayload, contentType) {const jsonString = String.fromCharCode.apply(null, new Uint8Array(bytePayload)); const jsonData =
JSON.parse(jsonString); const thingId = jsonData.thingId.split(':'); const value = {transmission: {properties: {rpm: jsonData.rpm, encoder: jsonData.encoder}}}; return Ditto.buildDittoProtocolMsg(thingId[0], thingId[1], 'things', 'twin', 'commands', 'modify',
'/features', headers, value);}",
"outgoingScript": "function mapFromDittoProtocolMsg(namespace, id, group, channel, criterion, action, path, dittoHeaders, value, status, extra) {let headers = dittoHeaders; let textPayload = '{}';
let bytePayload = null; let contentType = 'text/plain; charset=UTF-8'; return Ditto.buildExternalMsg(headers, textPayload, bytePayload, contentType);}",
"loadBytebufferJS": "false",
"loadLongJS": "false"
}
}
}
}
}
So far outgoingScript is setting an empty paylod, only brackets. I've also experimented with application/json as contentType.
After setting the whole setup we are able to update our model with MQTT. Inside Ditto containers logs with information that data was received are visible but there is no information that any data after digital twin update
was sent. Also no such information is visible inside MQTT broker.
Should I modify "targets" in connection configuration? Maybe policy is incorrect? How can I check if outgoingScript is executed(it cannot access the filesystem, it cannot print anything)?
This email is quite long but I hope I’ve described everything correct and all needed details are included.
Regards,
Adam Olek