AQI Sensor Uplink Decoder
1
function Decoder(bytes) {
2
3
var decbin = function(number) {
4
return parseInt(number, 10).toString(2)
5
}
6
7
var byteArray = bytes.map(function (byte) {
8
var number = decbin(byte);
9
return Array(9 - number.length).join("0") + number;
10
});
11
12
var sAQI1 = byteArray[1].substr(0);
13
var sAQI2 = byteArray[2].slice(0, 1);
14
var p1 = byteArray[6];
15
var p2 = byteArray[7].slice(0, 3);
16
var t1 = byteArray[7].substr(4);
17
var t2 = byteArray[8].slice(0, 6);
18
19
return {
20
sAQI: parseInt('' + sAQI1 + sAQI2, 2) * 16,
21
AQI: parseInt(byteArray[2].substring(1, 6), 2) * 16,
22
VOC: parseInt(byteArray[4], 2) * 4,
23
relative_humidity: parseInt(byteArray[5], 2) * 4 / 10,
24
pressure: (parseInt('' + p1 + p2, 2) * 40 + 30000) / 100,
25
temperature: (parseInt('' + t1 + t2, 2) - 400) / 10,
26
accuracy_aqi: parseInt(byteArray[8].substr(-2), 2),
27
voltage: parseInt(byteArray[9], 2) * 8 + 1600
28
};
29
}
Copied!
Copy link