-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyhton_api_example_decoder.js
More file actions
43 lines (40 loc) · 1.09 KB
/
Copy pathpyhton_api_example_decoder.js
File metadata and controls
43 lines (40 loc) · 1.09 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
37
38
39
40
41
42
43
function Decoder(request) {
// Parse JSON string in request body to real json
var payload = JSON.parse(request.body);
// Extract serial number in payload for device routing
var serial = payload.s;
// Return an array of dictionaries to Datacake
// Each dictionary contains device serial, database identifier and value
return [
{
device: serial, // Serial number of device
field: "TEMPERATURE", // Identifier of database field
value: payload.t // Actual data value for field
},
{
device: serial,
field: "HUMIDITY",
value: payload.h
},
{
device: serial,
field: "PRESSURE",
value: payload.p
},
{
device: serial,
field: "LIGHT",
value: payload.l
},
{
device: serial,
field: "POWER_STATUS",
value: payload.ps
},
{
device: serial,
field: "LOCATION",
value: payload.loc
},
];
}