Multipurpose Button Uplink decoder
1
function Decoder(data){
2
function decbin(byte){
3
return (parseInt(byte, 16).toString(2)).padStart(8, '0');
4
}
5
var batteryTmp = ("0" + `${data[2] + data[3]}`.toString(16)).substr(-2)[0];
6
var batteryVoltageCalculated = 2 + parseInt("0x"+ batteryTmp , 16) * 0.1;
7
var thermistorProperlyConnected = decbin(data[5])[5] == 0;
8
var extT1 = ("0" + data[5].toString(16)).substr(-2)[1];
9
var extT2 = ("0" + `${data[6]+data[7]}`.toString(16)).substr(-2);
10
var temperature = thermistorProperlyConnected ? parseInt(`0x${extT1}${extT2}`, 16) * 0.1 : 0;
11
var pressEvent = `${data[8] + data[9]}`;
12
if (data[1] == 1) {
13
return {
14
pressEvent: pressEvent,
15
batteryVoltage: batteryVoltageCalculated,
16
thermistorProperlyConnected:thermistorProperlyConnected,
17
temperature: temperature
18
19
}
20
}
21
}
22
Copied!

Helium Decoder

1
function Decoder(bytes, port, uplink_info) {
2
function decbin(byte){
3
return (parseInt(byte, 16).toString(2)).padStart(8, '0');
4
}
5
var data = bytes.map(function (byte) {
6
var number = parseInt(byte).toString(16);
7
if( (number.length % 2) > 0) { number= "0" + number }
8
return number;
9
});
10
var batteryTmp = ("0" + `${data[1]}`.toString(16)).substr(-2);
11
var batteryVoltageCalculated = 2 + parseInt("0x"+ batteryTmp , 16) * 0.1;
12
var thermistorProperlyConnected = decbin(data[2])[5] == 0;
13
var extT1 = ("0" + data[2].toString(16)).substr(-2)[1];
14
var extT2 = ("0" + `${data[3]}`.toString(16)).substr(-2);
15
var temperature = thermistorProperlyConnected ? parseInt(`0x${extT1}${extT2}`, 16) * 0.1 : 0;
16
var pressEvent = `${data[4]}`;
17
if (data[0] == '01') {
18
return {
19
"pressEvent": pressEvent,
20
"batteryVoltage": batteryVoltageCalculated,
21
"thermistorProperlyConnected":thermistorProperlyConnected,
22
"temperature": temperature
23
}
24
}
25
}
Copied!
Copy link