# Decoders and encoders

Decoding is the first phase in data processing in [uplink communication](/kpn-things/getting-started/tutorials/technical-overview/uplink-communication.md). In this phase incoming data is normalized into [SenML](/kpn-things/building-blocks/data-processing/thingsml-and-senml/senml.md) and additional (meta)data is enabled if applicable.

<figure><img src="/files/ecMfePGOm4lLVot9eZxo" alt=""><figcaption></figcaption></figure>

## Data decoders

A regular data decoder transforms incoming payload into measurements in SenML, following the data protocol of the specific [device](/kpn-things/building-blocks/data-processing/devices.md).

### ThingsML for LoRa payload&#xD;

ThingsML is a generic LoRa payload format, allowing you to send multiple measurements encoded in your payload in a compact way. Learn more about the [ThingsML for Lora data protocol](/kpn-things/building-blocks/data-processing/thingsml-and-senml/thingsml.md).

## Additional data

With additional data (decoders), metadata corresponding to the message received is enabled.

### LoRa Geolocation data

Add [LoRa Geolocation](https://docs.kpnthings.com/lora/geolocation/intro) data to messages where location could be calculated.

| SenML record name | Content                                                                                                                                                                               |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `locOrigin`       | <p><code>vs: "KPNLORA"</code> Indicating that the location information in<br>the SenML record comes from the LoRa network.</p>                                                        |
| `latitude`        | <p><code>v</code> The latitude of the location in decimal notation.</p><p><code>u: "lat"</code></p>                                                                                   |
| `longitude`       | <p><code>v</code> The longitude of the location in decimal notation.</p><p><code>u: "lon"</code></p>                                                                                  |
| `radius`          | <p><code>v</code> The theoretical inaccuracy of the calculated location. Can <br>be used to visualize a circle around the location on a map.</p><p><code>u: "m"</code> In meters.</p> |

### Location by LoRa On Premises Gateway reception

To extend the reach of our LoRa network on your location, we offer [LoRa On Premise Gateways](https://docs.kpnthings.com/lora/on-premises-gateway/introduction). A LoRa On Premise Gateway is an extension of our regular LoRa network. They have a smaller reach than our regular outdoor gateways, but you can position it for example in your warehouse to guarantee coverage for your LoRa devices.

Additionally, in KPN Things we have integrated the LoRa On Premises Gateway with our localisation service. When you enable **Location by LoRa On Premises Gateway reception**, KPN Things will detect when data from your device is received by one of your On Premise Gateways. Then KPN Things will add the administrative location of that gateway to the message. That way, the application can use that data to locate the device at the moment the message was sent.

To get this to work, you need to register your On Premise Gateways in your KPN Things account through the KPN Things API's by giving the gateway ID and the coordinates of the location you have positioned the gateway.&#x20;

## No-decoders

With no-decoders incoming data is not interpreted, it is only put into SenML.&#x20;

### Raw LoRa payload

| SenML record name | Content                                                                                                 |
| ----------------- | ------------------------------------------------------------------------------------------------------- |
| `payload`         | <p><code>vs</code> The received payload in hexadecimal notation <br>(example: <code>010203</code>).</p> |
| `port`            | `v` The application port the data was received on.                                                      |

### SenML data

If your device uses the SenML data format to send data to KPN Things, the data will be accepted as is, without further decoding.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.kpnthings.com/kpn-things/building-blocks/data-processing/decoders-and-encoders.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
