LoRaWAN Gateway Decoding: Hex to JSON at the Edge
|
|
Time to read 5 min
|
|
Time to read 5 min
IoT sensors speak a compact language called "Hexadecimal" to save battery. The Cloud speaks a readable language called "JSON." Traditionally, the translation happens in the cloud, forcing developers to manage complex server-side scripts. This guide explores a smarter architecture: Edge Decoding. We explain how to run JavaScript decoders directly on an industrial LoRaWAN gateway. By converting raw bytes (e.g., 0167) into human-readable values (e.g., "temp": 25) at the edge, you simplify integration, reduce cloud computing costs, and enable direct local control.
The Language Barrier: Sensors send efficient but unreadable binary data. A LoRaWAN gateway usually forwards this blindly, pushing the work to the cloud.
Edge Intelligence: A smart LoRaWAN gateway can run a "Decoder" script locally, transforming the packet before it even leaves the building.
JavaScript Compatibility: RobustOS supports standard JavaScript functions, allowing you to copy-paste existing decoders from sensor manufacturers directly into the gateway.
Integration Readiness: Sending pre-decoded JSON means your SCADA or Dashboard can display the data immediately without needing a middleware processing layer.
In the world of LoRaWAN, efficiency is everything. To save battery, a temperature sensor does not send the text "25.5 Degrees." It sends a tiny payload like 00FF.
This "Hexadecimal" data is great for the radio, but terrible for the human operator. Before you can use the data, it must be decoded.
Most architectures send the raw hex to the cloud and decode it there (e.g., using an AWS Lambda function). But there is a better way.
Why not decode it before it leaves the site?
By using a powerful industrial LoRaWAN gateway with edge computing capabilities, you can translate "Hex" to "JSON" locally. This guide explains how to program your gateway to become a smart translator.

When a standard LoRaWAN gateway forwards a packet, the payload looks like this: Payload: AQIDBA== (Base64 encoded Hex).
To a database or a SCADA system, this is gibberish. You cannot graph it. You cannot trigger an alert on it. You need a separate server, a cloud subscription, or a Node-RED flow just to turn that string into a number. This adds latency, complexity, and points of failure to your infrastructure.
An intelligent LoRaWAN gateway (like the Robustel R1520LG) is not just a radio; it is a Linux computer. It can run scripts.
By loading a JavaScript Decoder onto the gateway, the device performs the translation instantly upon receipt.
0x016700FF
Decoder() function.{"temperature": 25.5, "humidity": 60}
Now, the data leaving the LoRaWAN gateway via MQTT or HTTP is already formatted as a clean JSON object. Your dashboard can ingest it directly.
The decoding logic typically follows the standard defined by The Things Network (TTN). If you have a decoder for TTN, it will likely work on your Robustel LoRaWAN gateway.
Basic Structure:
JavaScript
function Decoder(bytes, port) { var decoded = {}; if (port === 1) { decoded.temperature = (bytes[0] << 8 | bytes[1]) / 100; } return decoded; }
You don't need to be a coding wizard. Most sensor manufacturers (Dragino, Bosch, Milesight) provide these .js files on their websites. You simply copy the code and paste it into the LoRaWAN gateway configuration.

Here is how to deploy this on a Robustel device running RobustOS.
0167) and see if the LoRaWAN gateway outputs the correct JSON.From this moment on, every packet sent to the MQTT broker will include a fields object containing your readable data.
Why shift the workload to the LoRaWAN gateway?

The trend in IoT is moving computation to the edge.
A "dumb" packet forwarder is no longer enough. By utilizing the decoding power of your industrial LoRaWAN gateway, you simplify your entire downstream architecture. You remove the dependency on cloud functions and deliver clean, actionable data to your application the moment it arrives.
A1: Negligible impact. The conversion from Hex to JSON takes a few milliseconds. An industrial LoRaWAN gateway typically has a 500MHz+ processor, which is more than capable of decoding thousands of packets per second without introducing noticeable latency.
A2: Yes. The decoder script can use the port number or the sensor's DevEUI to switch logic. For example: if (port === 2) { decode_soil_sensor() } else if (port === 3) { decode_tracker() }. This allows a single LoRaWAN gateway to handle a mixed fleet of devices.
A3: Some sensors use proprietary encoding that isn't public. In this case, you cannot decode it on the LoRaWAN gateway unless the manufacturer provides the private key or codec. However, 95% of commercial LoRaWAN sensors use open payload formats documented in their user manuals.