Closed VETRIVEL001 closed 8 months ago
If your device is able to send the signals in ditto protocol format, you don't need an incoming script at all. You need an incoming mapping script only for specific reasons like:
In that case you need an incoming script to map the device data to ditto protocol messages. But that mapping depends on the input format (topics and payloads sent by the device).
Otherwise, just use a standard MQTT connection type with a source that listens to a simple topic structure:
<environment>/telemetry/<deviceId>/
From the device publish a ditto message to that topic:
{
"topic": "org.eclipse.ditto/e6904e03-9919-4739-8924-6e902b6d79bf/things/twin/commands/merge",
"headers": {
"content-type": "application/merge-patch+json"
},
"path": "/features/water-tank/properties",
"value": {
"configuration": {
"brewingTemp": 1234
},
"status": {
"temperature": 95,
"waterAmount": 3
}
}
}
will I have to give this Json while publishing message through mqtt like "mosquitto_pub -h 'test.mosquitto.org' -m ''{ "topic": "org.eclipse.ditto/e6904e03-9919-4739-8924-6e902b6d79bf/things/twin/commands/merge", "headers": { "content-type": "application/merge-patch+json" }, "path": "/features/water-tank/properties", "value": { "configuration": { "brewingTemp": 1234 }, "status": { "temperature": 95, "waterAmount": 3 } } }" if it so, what should i give it in requestBody to create this mqtt connection?
yes,
-t
parameter in the mosquitto_pub command that corresponds to the topic that is configured in the connection source: mosquitto_pub -h test.mosquitto.org -p 1883 -t eclipse-ditto-sandbox/t/<your_deviceId> -D publish content-type application/vnd.eclipse.ditto+json <your_payload>
Here is a working example for a connection (only source is relevant, target is needed to send commands to the device):
{
"name": "MQTT 3.1.1",
"connectionType": "mqtt",
"connectionStatus": "open",
"uri": "tcp://test.mosquitto.org:1883",
"sources": [
{
"addresses": [
"eclipse-ditto-sandbox/t/#"
],
"consumerCount": 1,
"qos": 0,
"authorizationContext": [
"nginx:ditto"
],
"headerMapping": {},
"replyTarget": {
"address": "{{header:reply-to}}",
"headerMapping": {},
"expectedResponseTypes": [
"response",
"error"
],
"enabled": true
}
}
],
"targets": [
{
"address": "eclipse-ditto-sandbox/c/{{ thing:id }}",
"topics": [
"_/_/things/twin/events",
"_/_/things/live/messages"
],
"qos": 0,
"authorizationContext": [
"nginx:ditto"
],
"headerMapping": {}
}
],
"clientCount": 1,
"failoverEnabled": true,
"validateCertificates": true,
"processorPoolSize": 1,
"tags": []
}
I tried it the way mentioned above that's working fine when I publish single time. whereas, when I publish the message frequently to that topic it's not reflected in ditto thing but I would able to subscribe that message in that topic. what is the cause of the issue?
Hard to tell. If you send the same values over and over again, you may just not see the difference. You need to activate connection logs on your connection and see if there is a failure. In general it may help if you use the Ditto UI to play around and see if there are incoming messages on your thing or something goes wrong on your connection logs.
No, I was sending different values only but it's not reflecting in ditto thing.
Then you need to check the connection logs for failures and their reasons. It could be anything like json payload can not be parsed, thing can not be found, etc.. You need to analyze the logs.
this is my connection { "id": "merge", "name": "MQTT 3.1.1", "connectionType": "mqtt", "connectionStatus": "open", "uri": "tcp://test.mosquitto.org:1883", "sources": [ { "addresses": [ "mqtt-merge" ], "consumerCount": 1, "qos": 2, "authorizationContext": [ "nginx:ditto" ], "headerMapping": {}, "replyTarget": { "address": "{{header:reply-to}}", "headerMapping": {}, "expectedResponseTypes": [ "response", "error" ], "enabled": true } } ], "targets": [ { "address": "mqtt-merge-target", "topics": [ "//things/twin/events", "//things/live/messages" ], "qos": 2, "authorizationContext": [ "nginx:ditto" ], "headerMapping": {} } ], "clientCount": 1, "failoverEnabled": true, "validateCertificates": true, "processorPoolSize": 1, "tags": [] }
this is how i publish message through python code:
import paho.mqtt.publish as publish import time import json m='{"topic":"mqtt-merge","thingId": "abcd:123","headers": {"content-type": "application/merge-patch+json"}, "path": "/features/water-tank/properties","value": {"configuration": {"brewingTemp": 122222},"status": {"temperature": 222,"waterAmount": 222}}}'
publish.single("mqtt-merge", m, hostname="test.mosquitto.org")
my connection logs:
{
"connectionId": "merge",
"connectionLogs": [
{
"correlationId": "
i don't why this is giving me bad request eventhough mentioned topic and also thingId in mqtt(json).
If suppose, this is my thing
{ "definition": "com.acme:coffeebrewer:0.1.0", "attributes": { "manufacturer": "ACME demo corp.", "location": "Berlin, main floor", "serialno": "42", "model": "Speaking coffee machine" }, "features": { "coffee-brewer": { "definition": [ "com.acme:coffeebrewer:0.1.0" ], "properties": { "brewed-coffees": 0 } }, "water-tank": { "properties": { "configuration": { "smartMode": true, "brewingTemp": 87, "tempToHold": 44, "timeoutSeconds": 6000 }, "status": { "waterAmount": 731, "temperature": 44 } } } } }
Now I want to change the value of these three fields 'water-tank/properties/configuration/brewingTemp', 'water-tank/properties/status/temperature' and 'water-tank/properties/status/waterAmount' through the mqtt connections. To create connection what I have to give in incoming script? Can anyone send the incomingScripts for this case?