# How to Publish and Decode Multiple Hex Payloads via MQTT on Qubitro

This guide shows how to:

* ✅ Send multiple hex payloads using **MQTTX**
* ✅ Use a custom **Qubitro** [**Decoder Function** ](/platform/functions/decoder-function.md#hex-payload-decoder)to decode GPS and sensor data
* ✅ View structured decoded data in the Qubitro portal

***

### 🧩 Prerequisites

* A [Qubitro account](https://portal.qubitro.com/)
* An existing **Device**
* [MQTTX Desktop App](https://mqttx.app/)
* Your device's **MQTT credentials**

***

### Step 1: Get Your Qubitro MQTT Credentials

1. Go to your device in the **Qubitro Portal**
2. Click the **MQTT Credentials** tab
3. Copy:

   * **Device ID** (used as `Username` and topic)
   * **Device Token** (used as `Password`)
   * **Host**: `broker.qubitro.com`
   * **Port**: `8883` (SSL) or `1883` (non-SSL)
   * **Topic**: `Device ID`

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

***

### Step 2: Configure MQTTX (Secure Connection)

Open MQTTX and configure your connection as shown below:

* **Name**: `broker.qubitro.com`
* **Host**: `mqtts://broker.qubitro.com`
* **Port**: `8883`
* **Client ID**: (same as Device ID)
* **Username**: Device ID
* **Password**: Device Token
* **SSL/TLS**: ✅ Enabled
* **SSL Secure**: ✅ Enabled
* **Certificate**: `CA signed server certificate`

{% hint style="success" %}
Click **Connect** to establish a secure MQTT connection.
{% endhint %}

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

***

### Step 3: Add Decoder Function in Qubitro

1\. Go to your device → Functions tab

2\. Click Add Function → Choose Decoder Function

3\. Paste the following JavaScript code:

```javascript
function decoder(input) {
  const longitude = ((input.bytes[0] << 24) | (input.bytes[1] << 16) | (input.bytes[2] << 8) | (input.bytes[6] & 0xC0)) /1000000;
  const latitude = ((input.bytes[3] << 24) | (input.bytes[4] << 16) | (input.bytes[5] << 8) | ((input.bytes[6] & 0x30) << 2)) /1000000;
  const hMSL32 = ((((input.bytes[6] & 0x0F) << 8 ) + input.bytes[7]) * 2) - 191;
  const hAccCoeff = (input.bytes[8] & 0xE0) >> 5;
  const vAccCoeff = (input.bytes[8] & 0x1C) >> 2;
  const heading = ((input.bytes[8] & 0x03) << 2) + ((input.bytes[9] & 0xC0) >> 6);
  const speed = (input.bytes[9] & 0x3F);
  const battery = ((input.bytes[10]*256) + input.bytes[11]);
  const year = (input.bytes[12] >> 2) + 2000;
  const month = ((input.bytes[12] & 0x03) << 2) + ((input.bytes[13] & 0xC0) >> 6);
  const day = (input.bytes[13] & 0x3E) >> 1;
  const hour = ((input.bytes[13] & 0x01) << 4) + ((input.bytes[14] & 0xF0) >> 4);
  const minute = ((input.bytes[14] & 0x0F) << 2) + ((input.bytes[15] & 0xC0) >> 6);
  const second = (input.bytes[15] & 0x3F);
  const timestampSeconds = Math.floor(new Date(year, month, day, hour, minute, second).getTime() / 1000);

  return {
    longitude,
    latitude,
    coordinates: [latitude, longitude],
    hMSL32,
    hAccCoeff,
    vAccCoeff,
    heading,
    speed,
    battery,
    time: timestampSeconds
  };
}
```

{% hint style="success" %}
You can also test a single hex payload on the Qubitro Portal to verify your decoder.
{% endhint %}

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

4. Save and activate the function.

### Step 4: Publish Multiple Hex Payloads

1. Go to the **Publish** tab in MQTTX.
2. In the **topic** field, paste your **Device ID**.
3. Set the payload type to **JSON**.
4. Use the following payload:

```json
{
  "payload_hex": "00C08802808560A184000FFB648EAD0F,00c088028085909784000ffb648ead46,00c089028085109284000ffe648ead89,00c088028085e09c84000ffe648eadcb"
}
```

5. Click the green send button to publish the message.

<figure><img src="/files/0ea9TyltUfn37mOSWyZz" alt=""><figcaption></figcaption></figure>

### Step 5: View Decoded Data

Open the Storage tab in your Qubitro device and you’ll see structured decoded values like:

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

***

You’ve successfully:

• Connected MQTTX to Qubitro securely

• Published multiple hex payloads

• Used a custom decoder to parse sensor/GPS values

• Verified decoded output in Qubitro


---

# 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.qubitro.com/guides/integrations/how-to-publish-and-decode-multiple-hex-payloads-via-mqtt-on-qubitro.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.
