Created
April 29, 2020 14:46
-
-
Save sanchox/d797c3d29a7564c378351d03a7a41108 to your computer and use it in GitHub Desktop.
ChirpStack JS decoder for VEGA TS-11 (https://en.iotvega.com/product/tester) payloads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Decode decodes an array of bytes into an object. | |
// - fPort contains the LoRaWAN fPort number | |
// - bytes is an array of bytes, e.g. [225, 230, 255, 0] | |
// - variables contains the device variables e.g. {"calibration": "3.5"} (both the key / value are of type string) | |
// The function must return an object, e.g. {"temperature": 22.5} | |
function Decode(fPort, bytes, variables) { | |
output = {} | |
if (fPort == 4) { | |
flag_bits = bytes[0].toString(2).split('').reverse() | |
if (flag_bits[0] == 1) { | |
output.rssi = -bytes[5] | |
output.snr = bytes[6] > 127 ? bytes[6] - 256 : bytes[6] | |
} | |
if (flag_bits[1] == 1) { | |
output.battery_voltage_mV = (bytes[3] << 8) + bytes[4] | |
} | |
if (flag_bits[2] == 1) { | |
output.downlink_packet_count = bytes[2] | |
} | |
if (flag_bits[3] == 1) { | |
output.uplink_packet_count = bytes[1] | |
} | |
if (flag_bits[4] == 1) { | |
output.navigation_data_available = true | |
} | |
if (flag_bits[5] == 1) { | |
output.send_by_timer_event = false | |
output.send_by_button_press_event = true | |
} else { | |
output.send_by_timer_event = true | |
output.send_by_button_press_event = false | |
} | |
if (flag_bits[6] == 1) { | |
output.temperature_data_available = true | |
} | |
} | |
return output | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment