From 16cebd418a63c6735a3f9102c5b2f7001d047c5b Mon Sep 17 00:00:00 2001 From: DavideNesi <38299260+DavideNesi@users.noreply.github.com> Date: Sat, 23 Feb 2019 18:20:10 +0100 Subject: [PATCH] Update plain_decoder.js the old version had problems while using wifi and gps but not bluetooth added battery monitor --- src/TTN/plain_decoder.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/TTN/plain_decoder.js b/src/TTN/plain_decoder.js index ec55dc2c..ca43a5e4 100644 --- a/src/TTN/plain_decoder.js +++ b/src/TTN/plain_decoder.js @@ -10,7 +10,7 @@ function Decoder(bytes, port) { if (bytes.length >= 2) { decoded.wifi = (bytes[i++] << 8) | bytes[i++];} - if (bytes.length >= 4) { + if (bytes.length === 4 || bytes.length > 15) { decoded.ble = (bytes[i++] << 8) | bytes[i++];} if (bytes.length > 4) { @@ -60,7 +60,13 @@ function Decoder(bytes, port) { decoded.humidity = ((bytes[i++] << 8) | bytes[i++]); decoded.air = ((bytes[i++] << 8) | bytes[i++]); } + + if (port === 8) { + var i = 0; + if (bytes.length >= 2) { + decoded.battery = (bytes[i++] << 8) | bytes[i++];} + } return decoded; -} \ No newline at end of file +}