Writing Custom Payload Decoders with JavaScript
The IoT landscape is notoriously fragmented. While communication protocols like MQTT and HTTP offer a transport standard, the data payloads themselves remain a "Wild West" of proprietary binary formats. To maximize battery life and minimize bandwidth costs—especially on LPWAN networks like LoRaWAN or NB-IoT—most devices transmit data in highly compressed hex or binary strings.
AdaTrack addresses this challenge by providing a flexible, JavaScript-based decoding engine. This allows developers to define custom logic to transform raw binary "garbage" into structured, actionable JSON data in real-time.
Goja: Performance Meets Portability
At the heart of our integration layer is the Goja runtime. Unlike traditional architectures that might spin up a heavy Node.js container or call an external Lambda function for every incoming packet, we embed Goja—a pure Go implementation of ECMAScript 5.1+—directly into our backend.
Why this matters for IoT:
- Security through Sandboxing: Your decoding scripts run in an isolated environment. They cannot access the filesystem, network, or the host operating system, ensuring a multi-tenant safe architecture.
- Minimal Overhead: Goja provides lightning-fast execution with low memory footprint, allowing us to process thousands of payloads per second without the latency of an external IPC (Inter-Process Communication).
- Concurrency: Because it is built in Go, the runtime scales seamlessly across CPU cores, handling massive spikes in device traffic without breaking a sweat.
The Power of Bitwise Flexibility
Hardware engineers often optimize payloads down to the individual bit. You might find a single byte containing a 4-bit battery level, a 2-bit status code, and two boolean flags. Standard JSON parsers are useless here.
Our JavaScript environment provides full support for bitwise operators (&, |, ^, <<, >>) and DataView-like logic. This gives you the control needed to handle:
- Endianness: Seamlessly toggle between Big Endian and Little Endian depending on your microcontroller's architecture.
- Custom Scaling: Convert a 12-bit ADC value into a floating-point temperature reading using the exact coefficient defined in your sensor's datasheet.
- Packed Formats: Extract multiple data points from a single integer, reducing the payload size and extending the device's field life.
Zero-Downtime Updates & Operational Agility
In a traditional IoT pipeline, adding support for a new hardware model often requires a code change, a PR review, and a full CI/CD deployment cycle. If a firmware update changes the payload format in the field, your data pipeline breaks until the backend team can react.
AdaTrack changes the paradigm. Because our decoders are stored as dynamic scripts in the database and executed on-the-fly:
- Instant Deployment: Update your decoding logic via the AdaTrack UI or API and see the changes reflected on the next incoming packet.
- Version Control: Test your new decoder against historical raw payloads to ensure accuracy before pushing to production.
- Firmware Independence: As your hardware evolves from V1 to V2, simply update the script to handle both versions, maintaining a consistent JSON schema for your downstream applications and dashboards.
Conclusion
By bridging the gap between low-level hardware constraints and high-level software requirements, AdaTrack enables teams to focus on building features rather than wrestling with binary formats. With Goja-powered JavaScript decoders, you have the most flexible toolset available to bring any device, on any protocol, into your ecosystem. Custom decoders are just one part of the platform — see the rest of our core features.

