TTN decoder updates

This commit is contained in:
Verkehrsrot 2019-04-06 21:10:33 +02:00
parent 261c643d7f
commit 11c2fb6fa2
2 changed files with 28 additions and 19 deletions

View File

@ -5,7 +5,7 @@ function Decoder(bytes, port) {
var decoded = {}; var decoded = {};
if (bytes.length === 0) { if (bytes.length === 0) {
return {}; return {};
} }
@ -33,10 +33,6 @@ function Decoder(bytes, port) {
if (bytes.length === 17) { if (bytes.length === 17) {
return decode(bytes, [uint16, uptime, uint8, uint32, uint8, uint8], ['voltage', 'uptime', 'cputemp', 'memory', 'reset0', 'reset1']); return decode(bytes, [uint16, uptime, uint8, uint32, uint8, uint8], ['voltage', 'uptime', 'cputemp', 'memory', 'reset0', 'reset1']);
} }
// epoch time answer
if (bytes.length === 5) {
return decode(bytes, [uint32, uint8], ['time', 'timestatus']);
}
} }
if (port === 3) { if (port === 3) {
@ -72,9 +68,13 @@ function Decoder(bytes, port) {
if (port === 9) { if (port === 9) {
// timesync request // timesync request
if (bytes.length === 1) { if (bytes.length === 1) {
decoded.timesync_seqno = bytes[0]; decoded.timesync_seqno = bytes[0];
return decoded;
}
// epoch time answer
if (bytes.length === 5) {
return decode(bytes, [uint32, uint8], ['time', 'timestatus']);
} }
return decoded;
} }
} }

View File

@ -8,10 +8,12 @@ function Decoder(bytes, port) {
var i = 0; var i = 0;
if (bytes.length >= 2) { if (bytes.length >= 2) {
decoded.wifi = (bytes[i++] << 8) | bytes[i++];} decoded.wifi = (bytes[i++] << 8) | bytes[i++];
}
if (bytes.length === 4 || bytes.length > 15) { if (bytes.length === 4 || bytes.length > 15) {
decoded.ble = (bytes[i++] << 8) | bytes[i++];} decoded.ble = (bytes[i++] << 8) | bytes[i++];
}
if (bytes.length > 4) { if (bytes.length > 4) {
decoded.latitude = ((bytes[i++] << 24) | (bytes[i++] << 16) | (bytes[i++] << 8) | bytes[i++]); decoded.latitude = ((bytes[i++] << 24) | (bytes[i++] << 16) | (bytes[i++] << 8) | bytes[i++]);
@ -52,7 +54,7 @@ function Decoder(bytes, port) {
decoded.rssi = bytes[i++]; decoded.rssi = bytes[i++];
decoded.beacon = bytes[i++]; decoded.beacon = bytes[i++];
} }
if (port === 7) { if (port === 7) {
var i = 0; var i = 0;
decoded.temperature = ((bytes[i++] << 8) | bytes[i++]); decoded.temperature = ((bytes[i++] << 8) | bytes[i++]);
@ -60,19 +62,26 @@ function Decoder(bytes, port) {
decoded.humidity = ((bytes[i++] << 8) | bytes[i++]); decoded.humidity = ((bytes[i++] << 8) | bytes[i++]);
decoded.air = ((bytes[i++] << 8) | bytes[i++]); decoded.air = ((bytes[i++] << 8) | bytes[i++]);
} }
if (port === 8) { if (port === 8) {
var i = 0; var i = 0;
if (bytes.length >= 2) { if (bytes.length >= 2) {
decoded.battery = (bytes[i++] << 8) | bytes[i++];} decoded.battery = (bytes[i++] << 8) | bytes[i++];
}
if (port === 9) {
if (bytes.length === 1) {
decoded.timesync_seqno = bytes[0];
} }
} }
return decoded; if (port === 9) {
// timesync request
if (bytes.length === 1) {
decoded.timesync_seqno = bytes[0];
}
// epoch time answer
if (bytes.length === 5) {
var i = 0;
decoded.time = ((bytes[i++] << 24) | (bytes[i++] << 16) | (bytes[i++] << 8) | bytes[i++]);
decoded.timestatus = bytes[i++];
}
return decoded;
}
} }