# Custom LoRaWAN Payload Decoders in JavaScript | Widgelix

URL: https://greenmesh.org/platform/payload-decoders

> Write and test payload decoders for any IoT device in Widgelix: JavaScript uplink decoders and downlink encoders, a built-in test console, per-device state, GPS from payload and reusable asset templates.

---

[Platform](https://greenmesh.org/platform) / Payload Decoders
Platform · Asset Templates

# Custom LoRaWAN payload decoders for any device, written in JavaScript

Every IoT device speaks its own binary format. In Widgelix you write a short JavaScript decoder once, test it on a real payload, and reuse it for every device of that model. Using a popular sensor? It probably already has a ready decoder in the supported devices catalogue.

[Browse ready decoders](https://greenmesh.org/product/asset-templates)

JavaScript

uplink decoders and downlink encoders

Test console

run a payload before going live

Write once

reuse for every device of the model

![Widgelix asset template editor with a JavaScript uplink decoder, test payload console and data fields](https://greenmesh.org/images/platform/codec-uplink.jpg)

The problem

## Every new sensor model starts with bytes nobody can read

A LoRaWAN or Sigfox sensor sends a few bytes of HEX. Before anyone can see a temperature, someone has to find the vendor's codec, adapt it to the platform, map the fields and units, and repeat the work for every project. Proprietary devices often have no ready decoder at all.

- Vendor codecs need adapting for every platform

- Field names and units differ between projects

- No safe place to test a decoder before devices go live

- Stateful logic (counters, deltas) needs a custom backend

How it works

## One template per device model

- 01

### Check the catalogue, or start from scratch

If your device is in the supported devices catalogue, load its ready template and you are done. For anything else, create an asset template from scratch.

- 02

### Decode and test

Write a decode(payload, data) function in JavaScript. Paste a real HEX payload into the test console, click Run and check the output before saving.

- 03

### Add devices and use the data

Every device you attach to the template uses the same decoder. Decoded fields feed dashboards, actions, reports and AI agents immediately.

Capabilities

## Everything a device model needs, in one template

Asset templates (formerly device types) hold the decoding, data model and default views for a device model.

### Uplink decoder

A JavaScript function receives the payload as HEX plus network metadata (type, RSSI, SNR, gateway EUI, fPort, fCnt) and returns named values.

### Downlink encoder

Turn a JSON command into the HEX payload the device expects. Its fields drive the Downlink Button widget, the asset Downlinks tab and downlink actions.

### Data fields with units and ranges

Declare which decoded values to store, with units and expected min/max. Load all fields at once from a sample decoded payload.

### Per-device state

Decoders can keep persistent storage per device between messages, for counters, deltas and baselines, without an extra backend.

### Device ID and GPS from payload

Read the device ID or latitude/longitude from decoded fields, so trackers and gateways that forward many devices appear correctly on maps.

### Tags and default views

Define tags such as floor, room or measured object, the list widgets shown in the assets list, and the default dashboard for every device of the model.

### Reuse across organisations

Copy a template to another organisation you manage, or share it through the project repository so partners can install it.

### AI-assisted decoders

AI agents connected through the Widgelix MCP server can write a decoder and test it against a sample payload before saving the template.

## Looking for a ready decoder?

Popular sensors from vendors such as Milesight, Dragino, Elsys, Tektelic, Adeunis and MClimate already have verified decoders in the supported devices catalogue. Load the template and skip the coding.
[Browse supported devices](https://greenmesh.org/product/asset-templates)

![Widgelix asset templates list with device images, manufacturers and connectivity badges](https://greenmesh.org/images/widgelix/frame-asset-templates.png)

At a glance

## Template and codec features

| Decoder language | JavaScript, executed in an isolated sandbox

| Decoder input | HEX payload + metadata: type, RSSI, SNR, gateway EUI, fPort, fCnt

| Downlinks | JSON → HEX encoder with named command fields

| Testing | Built-in console for uplink and downlink codecs

| State | Persistent per-device storage between messages

| Repository | Supported devices catalogue with verified decoders

| Connectivity | LoRaWAN, Sigfox, MQTT, HTTP webhook and more

| Portability | Show as JSON, copy to another organisation, publish to the repository

## Related pages

[Supported devices & ready decoders Check whether your sensor already has a verified decoder before writing one.](https://greenmesh.org/product/asset-templates) [Energy monitoring Meter decoders with per-device state for consumption deltas.](https://greenmesh.org/solutions/energy-monitoring) [Smart waste monitoring Fill-level sensors decoded and mapped in minutes.](https://greenmesh.org/solutions/waste-monitoring) [Leak detection Leak sensors and valve controllers with uplink and downlink codecs.](https://greenmesh.org/case-studies/leak-detection)

## Questions about payload decoders

#### What is a payload decoder?

Most low-power IoT devices send compact binary payloads to save battery and airtime. A payload decoder is a small function that converts those bytes into named values such as temperature or battery voltage.

#### Can I use the decoder published by my sensor vendor?

Usually yes. Vendor JavaScript codecs can be pasted into the decoder with minor changes to the function signature. Test them in the built-in console with a real payload before saving.

#### Is my device supported out of the box?

Check the supported devices catalogue. If a template exists, load it from the repository. If not, create one from scratch, or ask us and we can add it.

#### Can I send commands to devices?

Yes. Add a downlink encoder to the template. Downlinks are sent through integrations that support them, such as The Things Stack, Actility, Helium, LORIOT, Loxone and the GreenMesh LoRaWAN Network Server.

#### Does it work for non-LoRaWAN devices?

Yes. The same template model is used for Sigfox, MQTT and HTTP webhook devices. Only the payload format and metadata differ.

[Read the asset template documentation → The template editor in detail: uplink and downlink codecs, data fields, tags, parameters and widgets.](https://docs.widgelix.com/asset-templates/editing-an-asset-template)

## More platform features

[IoT Alerts & Automation Actions that react to sustained real-world conditions, not noisy single readings.](https://greenmesh.org/platform/iot-alerts-automation) [Incident Escalation On-call escalation for IoT alarms: someone always takes ownership.](https://greenmesh.org/platform/incident-escalation) [IoT Dashboards No-code dashboards for every device, site and role, with 20+ widget types.](https://greenmesh.org/platform/iot-dashboards) [Integrations The Things Stack, ChirpStack, Actility, LORIOT, Helium, Sigfox, MQTT, webhooks and more.](https://greenmesh.org/platform/integrations)

## Bring your devices, we'll help decode them

Tell us which sensors and meters you use. We'll check repository support and help with templates for anything new.

- Repository check for your device list

- Template and decoder setup for new models

- Migration from your current platform's codecs
