RadioBridge / Packet-Decoder

Radio Bridge Packet Decoder in Javascript
MIT License
11 stars 10 forks source link

bug for decoding TILT_HP_EVENT bytes #2

Open ijl20 opened 4 years ago

ijl20 commented 4 years ago

Lines 412..417 two corrections:

// integer and fractional values between two bytes
Angle = +(bytes[3] + (bytes[4] / 10)).toFixed(1);
decoded.Message += ", Angle: " + Angle;

Temperature = Convert(bytes[5], 0);
decoded.Message += ", Temperature: " + Temperature;

Please note the += for decoded.Message where you have just = (so the actual Tilt event info gets overwritten).

An aside: IMHO decoding to freeform English readable free text, and then embedding that free text in a single-property Json object is really unusual, i.e.:

{
  "Message": "Event: Supervisory, Battery Voltage: 3.2V, Accumulation Count: 0, Tamper Since Last Reset: 0, Current Tamper State: 0, Error With Last Downlink: 0, Battery Low: 0, Radio Comm Error: 0, Packet Counter: 15, Protocol Version: 1"
}

More typical would be

{ "event": "supervisory",
  "battery": 3.2,
  "count": 0,
  "tamper_since_reset": 0,
  ...etc.
}

Maybe I missed something and there's a library that can use that freeform English format, but I don't think so.

Thanks.

ijl20 commented 4 years ago

FYI this bug occurs a few more times in the file (search <space>=<space>",)

i.e. lines 414, 417, 582, 584, 668, 697.

For our 'AdaptiveCities' platform at Cambridge I'm converting the decoder to Python, and also changing the decode output to the more structured JSON above (work-in-progress, will complete 2020-May-30):

https://github.com/AdaptiveCity/acp_local_mqtt/blob/master/acp_decoders/decoders/radiobridge.py