I got a stranger error although I follow guideline in ditto example.
Octopus can published messages to MQTT. I can see them use MQTT client.
WebApp shows connection established and send send event works. I can change values through "my.test.octopus"
panel. But when I query it using API, I can only my values from webapp, never got vales from octopus.
I checked connectivity logs, seems mapping problem...I used the following to create mapping when creating connection:
"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;
const value = {
temp_sensor: {
properties: {
value: jsonData.temp
}
},
altitude: {
properties: {
value: jsonData.alt
}
}
};
return Ditto.buildDittoProtocolMsg('my.test', thingId, 'things', 'twin', 'commands', 'modify', '/features', headers, value);
}"
Thanks for help
update
The error manifests in the following log line:
See the following log statement:
"The message mapper configuration failed due to: unterminated regular expression literal (incomingScript#1) - in line/column #1/472," -- ""incomingScript": "function mapToDittoProtocolMsg(headers, textPayload, bytePayload, contentType) {var jsonData = JSON.parse(textPayload);const thingId = jsonData.thingId;const value = {temp_sensor: { properties: { value: jsonData.temp } }, altitude: { properties: { value: jsonData.alt } } }; return Ditto.buildDittoProtocolMsg('my.test', thingId, 'things', 'twin', 'commands', 'modify', '/features', headers, value); }"
Your mapping script seems to work correctly. I created a unit test for it using the payload mapping testing from ditto-examples.
This test looks like the following:
incomingScript.js
expectedAdaptable.json
So far this seems to work, but in this test I assume the following incoming bytePayload:
Could you somehow verify, that the byte payload your octopus is sending is looking correctly? Is the octopus really sending byte payload or is it text payload (application/json)?
update
According to the comment of Bob Su the octopus is sending text payload. In order to map this payload, you actually have to use the text payload instead of byte payload. In the following you'll see the updated incomingScript.
incomingScript.js
The test can be adapted to: