-
Notifications
You must be signed in to change notification settings - Fork 0
/
ttn-payload-formatter.js
41 lines (33 loc) · 1.17 KB
/
ttn-payload-formatter.js
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
function decodeUplink(input) {
let data = [];
for (let sensorValue = 0; sensorValue < input.bytes.length / 13; sensorValue++) {
let sensorAddress = input.bytes[0];
let conductivity = 0;
let temperature = 0;
let waterContent = 0;
// ElectricalConductivity
conductivity |= input.bytes[sensorValue + 1] << 16;
conductivity |= input.bytes[sensorValue + 2] << 8;
conductivity |= input.bytes[sensorValue + 3];
conductivity = conductivity / Math.pow(10, input.bytes[sensorValue + 4]);
// Temperature
temperature |= input.bytes[sensorValue + 5] << 16;
temperature |= input.bytes[sensorValue + 6] << 8;
temperature |= input.bytes[sensorValue + 7];
temperature = temperature / Math.pow(10, input.bytes[sensorValue + 8]);
// VolumetricWaterContent
waterContent |= input.bytes[sensorValue + 9] << 16;
waterContent |= input.bytes[sensorValue + 10] << 8;
waterContent |= input.bytes[sensorValue + 11];
waterContent = waterContent / Math.pow(10, input.bytes[sensorValue + 12]);
data.push({
sensorAddress,
conductivity,
temperature,
waterContent
});
}
return {
data
};
}