From c1a61bf91f9f3a31c33e4c73656500cfc6a9481b Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Thu, 24 Sep 2020 21:39:54 +0200 Subject: [PATCH] Adapt Uno Basic decoder to new formatter API --- examples/Basic/Basic.ino | 34 +++++++++++++++++----------------- examples/Basic/Decoder.js | 35 ++++++++++++++++------------------- 2 files changed, 33 insertions(+), 36 deletions(-) diff --git a/examples/Basic/Basic.ino b/examples/Basic/Basic.ino index 97e6259..f7af1cc 100644 --- a/examples/Basic/Basic.ino +++ b/examples/Basic/Basic.ino @@ -22,23 +22,23 @@ TheThingsNode *node; Decoder payload function ------------------------ -function Decoder(bytes, port) { - var decoded = {}; - var events = { - 1: 'setup', - 2: 'interval', - 3: 'motion', - 4: 'button' - }; - decoded.event = events[port]; - decoded.battery = (bytes[0] << 8) + bytes[1]; - decoded.light = (bytes[2] << 8) + bytes[3]; - if (bytes[4] & 0x80) - decoded.temperature = ((0xffff << 16) + (bytes[4] << 8) + bytes[5]) / 100; - else - decoded.temperature = ((bytes[4] << 8) + bytes[5]) / 100; - return decoded; -} +function decodeUplink(input) { + return { + data: { + event: { + 1: "setup", + 2: "interval", + 3: "motion", + 4: "button" + } [input.fPort], + battery: (input.bytes[0] << 8) + input.bytes[1], + light: (input.bytes[2] << 8) + input.bytes[3], + temperature: (((input.bytes[4] & 0x80) ? (0xffff << 16) : 0) + (input.bytes[4] << 8) + input.bytes[5]) / 100 + }, + warnings: [], + errors: [] + }; +} */ void setup() diff --git a/examples/Basic/Decoder.js b/examples/Basic/Decoder.js index 1fdbfd4..82fb54e 100644 --- a/examples/Basic/Decoder.js +++ b/examples/Basic/Decoder.js @@ -11,23 +11,20 @@ * } */ -function Decoder(bytes, port) { - var decoded = {}; - - var events = { - 1: 'setup', - 2: 'interval', - 3: 'motion', - 4: 'button' - }; - - decoded.event = events[port]; - decoded.battery = (bytes[0] << 8) + bytes[1]; - decoded.light = (bytes[2] << 8) + bytes[3]; - if (bytes[4] & 0x80) - decoded.temperature = ((0xffff << 16) + (bytes[4] << 8) + bytes[5]) / 100; - else - decoded.temperature = ((bytes[4] << 8) + bytes[5]) / 100; - - return decoded; +function decodeUplink(input) { + return { + data: { + event: { + 1: "setup", + 2: "interval", + 3: "motion", + 4: "button" + } [input.fPort], + battery: (input.bytes[0] << 8) + input.bytes[1], + light: (input.bytes[2] << 8) + input.bytes[3], + temperature: (((input.bytes[4] & 0x80) ? (0xffff << 16) : 0) + (input.bytes[4] << 8) + input.bytes[5]) / 100 + }, + warnings: [], + errors: [] + }; }