Created
June 23, 2025 20:53
-
-
Save joshsucher/85c29266830a583992e051cb2ae014e0 to your computer and use it in GitHub Desktop.
Custom TTN uplink formatter for Seeed SenseCAP T1000-E LoRaWAN+Sensors demo
This file contains hidden or 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
/** | |
* TTN V3 uplink decoder for payloads that look like: | |
* 00 8B 00 64 FC 2D FF E4 00 04 | |
* byte‑by‑byte: | |
* 0‑1 int16 temperature × 0.1 °C (big‑endian, signed) | |
* 2 uint8 lux (raw; 0‑255) | |
* 3 uint8 battery % (0‑100) | |
* 4‑5 int16 accel‑X raw (±32768 counts ≙ ±2 g) | |
* 6‑7 int16 accel‑Y raw | |
* 8‑9 int16 accel‑Z raw | |
* | |
* Accelerometer counts are scaled to g by ÷ 16384 | |
* See: https://github.com/Seeed-Studio/Seeed-Tracker-T1000-E-for-LoRaWAN-dev-board/tree/a2a0d1b48007b1fc7cf1eea90a439d5b5aff112a/apps/examples/07_lorawan_sensor | |
*/ | |
function decodeUplink(input) { | |
const bytes = input.bytes; | |
const errors = []; | |
if (!bytes || bytes.length < 10) { | |
errors.push("Payload too short – expected 10 bytes"); | |
return { data: {}, warnings: [], errors }; | |
} | |
// helper: signed 16‑bit from two bytes | |
const s16 = (hi, lo) => { | |
let v = (hi << 8) | lo; | |
return v & 0x8000 ? v - 0x10000 : v; | |
}; | |
const tempRaw = s16(bytes[0], bytes[1]); // 0.1 °C | |
const lux = bytes[2]; | |
const battery = bytes[3]; | |
const axRaw = s16(bytes[4], bytes[5]); | |
const ayRaw = s16(bytes[6], bytes[7]); | |
const azRaw = s16(bytes[8], bytes[9]); | |
const data = { | |
temperature_c: +(tempRaw / 10).toFixed(1), | |
temperature_f: +((tempRaw / 10) * 9 / 5 + 32).toFixed(1), | |
lux, | |
battery_pct: battery, | |
accel_x_g: +(axRaw / 16384).toFixed(5), | |
accel_y_g: +(ayRaw / 16384).toFixed(5), | |
accel_z_g: +(azRaw / 16384).toFixed(5), | |
}; | |
return { data, warnings: [], errors }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment