Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[ditto-dev] Exposing digital twin data via MQTT
  • From: "Olek, Adam" <adam.olek@xxxxxxxxx>
  • Date: Mon, 12 Apr 2021 09:15:47 +0000
  • Accept-language: pl-PL, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=aptiv.com; dmarc=pass action=none header.from=aptiv.com; dkim=pass header.d=aptiv.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AD2CQUYS6JnPL8xrF/OrFyr3ai3Ht+lYE57UOHOsHnc=; b=UfG+mLwa+MnX5mVFVQQtbJzjFIw/i+Kg+Lue+vWlTSkSBsJBpQi5ACN8dVcj7g2dFJkXASDE5f/R0Gxwd+wremhrFOJGBfIn5pFkylSgO45YdT8rTlhKGTnmGJlvhsegRHwpz708qEu5nb8vqlmkLScwawEkZAMpALuwdnHDQvXizDHXIuKhZpYZCp1l9WTz8+Rkr/fnn2CysjxbND2/CQy5SCSXUGgW60Nb1TVgnbXmBdSMj0jXcBrbtB5fpAEnq+Ys16j1RFyUVH/fCr1iKJz4liyRx76Bd38xcdT2crYsBm1AnH2/xvOtzSx26eRk/YXTb6/N+qMvwu9v64Qhkw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BI3NFa3nisgyvzEt8y7Q9fWVea1FWClM2Db8fOHUwXQAHuosgWNr39d+NO+g9QZcpbYUy6RDzw4opk7I7AUWlJ3KQESdbW7r83obw9lXgBA2//e6hHvLmA7ud71jWf7HCbGyrlM1Fx6rqxbILrw7nwVIlxiW/vHO7AySBdn5whrqoxHsWTWg+PNezO3bLFmL1/+6sPHEcDmkBR/vAuwwlExE6VKR66ubiPCBLhGIsonCYHimRsmynF1/0JNKL6B93gfRT2+9S2XB9wUephnryNRN6dgElyWk9aPLhX6aUeDdS9Rnpuv5TqmrrL0f19tLR/Ci1DQEog1bjN2fvv3slg==
  • Delivered-to: ditto-dev@xxxxxxxxxxx
  • List-archive: <https://www.eclipse.org/mailman/private/ditto-dev/>
  • List-help: <mailto:ditto-dev-request@eclipse.org?subject=help>
  • List-subscribe: <https://www.eclipse.org/mailman/listinfo/ditto-dev>, <mailto:ditto-dev-request@eclipse.org?subject=subscribe>
  • List-unsubscribe: <https://www.eclipse.org/mailman/options/ditto-dev>, <mailto:ditto-dev-request@eclipse.org?subject=unsubscribe>
  • Thread-index: Adcve8u38j1YBQn2Q5OiQr6bKiinpg==
  • Thread-topic: Exposing digital twin data via MQTT

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


Back to the top