-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpayloadMapping.js
More file actions
36 lines (35 loc) · 1.04 KB
/
payloadMapping.js
File metadata and controls
36 lines (35 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function mapToDittoProtocolMsg(headers, textPayload, bytePayload, contentType) {
const thingId = 'UDMIduino-000';
const jsonString = String.fromCharCode.apply(null, new Uint8Array(bytePayload));
const jsonData = JSON.parse(jsonString);
const value = {
udmi: {
properties: {
version: 1,
timestamp: 0,
points: {
lux_level: {
present_value: jsonData.points.lux_level.present_value
},
lum_value: {
present_value: jsonData.points.lum_value.present_value
},
dimmer_value: {
present_value: jsonData.points.dimmer_value.present_value
}
}
}
}
};
return Ditto.buildDittoProtocolMsg(
'open.iot',
thingId,
'things',
'twin',
'commands',
'modify',
'/features',
headers,
value
);
}