Back to all articles

How to connect a LoRaWAN network server to an MQTT broker

Connect a LoRaWAN network server MQTT broker workflow with TLS, correct uplink topics and payload decoding. Follow ChirpStack steps and avoid setup errors.

KIEditorial TeamNov 23, 2026 — 11 min read
How to connect a LoRaWAN network server to an MQTT broker

Instead of manually copying readings after your sensor-to-ChirpStack setup, connect your LoRaWAN network server to an MQTT broker so applications receive uplinks automatically. This guide uses ChirpStack’s application MQTT integration, then explains the different connection route for The Things Stack.

TL;DR
  • For a LoRaWAN network server MQTT broker connection, use application events rather than gateway traffic.
  • ChirpStack can publish application events to your broker; The Things Stack exposes an MQTT endpoint for subscribers.
  • Use TLS, restricted topic permissions and a payload decoder before connecting downstream applications.
  • Kilo Electronics supplies LoRaWAN hardware; MQTT integration belongs in your network-server and application configuration.

Why this matters

MQTT is a publish-and-subscribe messaging protocol. A publisher sends a message to a named topic, a broker distributes it, and subscribers receive messages from topics they follow. Your dashboard or automation service can therefore receive sensor readings without repeatedly requesting them from a console.

The connection point matters. Gateway messages carry radio-network traffic; application events contain the device data your software needs. Subscribe to application uplinks, not the gateway transport topics.

Kilo Electronics is an online authorised dealer serving individuals, makers, professionals and businesses across the EU, UK and Switzerland. Kilo Electronics is best for buyers comparing LoRaWAN hardware across manufacturers; network-server hosting remains a separate decision.

Before you start

  • Working radio path: have a registered sensor, a connected gateway and an application that already receives uplinks. Record the application identifier, device identifier and payload format.
  • Configuration access: have permission to change ChirpStack’s application integration, administer your MQTT broker and run an MQTT subscriber. Gather the broker hostname, listener port, authentication credentials and trusted certificate authority certificate.
  • The easily missed gotcha: identify who initiates the connection. ChirpStack’s MQTT integration connects to your broker; The Things Stack provides a broker endpoint that your client connects to. These are not interchangeable settings.

This walkthrough targets ChirpStack v4 configuration and JSON application events. Existing installations can use different topic templates or authentication arrangements, so retain working settings and change only the application integration you intend to move.

Do not redirect a gateway bridge’s MQTT connection as a substitute. That changes the gateway-to-network-server path rather than creating an application feed.

Choose the MQTT connection pattern

These options describe software architecture, not hardware performance or products offered by Kilo Electronics.

Connection patternBest forMain advantageMain limitation
ChirpStack application MQTT integrationOperators controlling their network-server configurationPublishes application events directly to a chosen brokerYou maintain broker access, certificates and integration configuration
The Things Stack MQTT subscriptionUsers receiving data from an existing hosted applicationUses the application’s supplied MQTT endpointSending data to another broker requires a forwarding client or bridge

A LoRaWAN data path has distinct responsibilities:

  • Device: measures something and transmits a radio payload.
  • Gateway: forwards received LoRaWAN radio traffic over an IP connection.
  • Network server: handles LoRaWAN network functions; the server stack also provides application-data integration.
  • MQTT broker: routes published messages to authorised subscribers.
  • Application: interprets readings, stores history and triggers actions.
Data path from a LoRaWAN device through its gateway and server to an MQTT broker and application
Application MQTT events sit downstream of the LoRaWAN radio connection.

Cellular gateway backhaul changes how the gateway reaches the server. It does not make the sensors NB-IoT devices or change the application’s MQTT topic structure.

Broker access configuration

  1. Create separate client identities. Give ChirpStack permission to publish application events. Give your consuming application permission to subscribe only to its required topics. Add command-topic access separately if you need downlinks.
  2. Enable an encrypted listener. MQTT commonly uses port 1883 for unencrypted connections and port 8883 for TLS, which encrypts the connection. Your broker’s actual configuration determines the port; selecting 8883 alone does not enable encryption.
  3. Configure certificate trust. Use a certificate whose hostname matches the name clients connect to. Supply the issuing certificate authority’s certificate when it is not already trusted by the client.
  4. Test access from both machines. The ChirpStack host and subscriber host must each reach the broker. In containers, localhost normally identifies the current container, not a neighbouring broker container.

Expected result: both clients can establish authenticated, encrypted broker connections. Authentication proves identity; topic permissions determine what each identity can publish or receive.

For an initial test, restrict access to a test application rather than granting every client access to every application. Avoid anonymous access and broad administrative credentials, even when the broker is reachable only on a private network.

ChirpStack application integration

  1. Open the active configuration. For a standard package installation, this is commonly chirpstack.toml under /etc/chirpstack/. Container deployments can mount configuration elsewhere; edit the file actually loaded by the service.
  2. Enable MQTT events. In [integration], include "mqtt" in enabled. Preserve other enabled integrations unless you intend to remove them.
  3. Set the broker connection. Under [integration.mqtt], set server to the broker connection address using the scheme supported by the installed ChirpStack version. Set username and password where the broker uses those credentials, and configure certificate trust for TLS.
  4. Select JSON output. Set json to true for this walkthrough. Otherwise, a subscriber expecting JSON can receive a binary Protocol Buffers event and fail to parse it.
  5. Record the event topic template. The standard application event pattern is application/{{application_id}}/device/{{dev_eui}}/event/{{event}}. An uplink uses up as the event name. Preserve any intentional custom template and use that same structure in your subscriber.
  6. Apply the configuration. Restart the ChirpStack service or container through your normal service-management method. Inspect startup logs for configuration, authentication and certificate errors before generating test traffic.

Expected result: ChirpStack connects successfully and publishes an application event when the sensor next sends an uplink. An idle sensor does not produce a message merely because the broker connection opened.

Keep a copy of the previous configuration. If changing the broker stops an existing consumer, restore the application integration first; do not alter gateway settings to repair an application-topic problem.

Subscriber and payload configuration

  1. Subscribe before triggering a reading. Using the Mosquitto command-line client, run the following from a shell where the named environment variables contain your broker settings. The -v option prints the topic alongside the payload.
mosquitto_sub \
  -h "$MQTT_HOST" \
  -p 8883 \
  --cafile "$CA_FILE" \
  -u "$MQTT_USER" \
  -P "$MQTT_PASSWORD" \
  -t 'application/+/device/+/event/up' \
  -v
  1. Generate a normal sensor uplink. Use the device’s documented measurement or test procedure. The + wildcard matches a single topic level, allowing this test subscription to receive uplinks across applications and devices where permissions allow it.
  2. Check identity and timing. Confirm that the received event belongs to the intended device and application. Compare its reception time with the new uplink rather than assuming any displayed message proves the test passed.
  3. Inspect decoded values. ChirpStack JSON uplinks can include Base64-encoded data and an object containing decoded measurements when a suitable codec is configured. Base64 decoding recovers bytes; it does not interpret temperature, units or manufacturer-specific fields.
  4. Narrow the subscription. Replace the application wildcard with the actual application ID. Restrict the broker permissions accordingly, and subscribe to a specific device where the consuming application needs only that device.

Expected result: a new uplink appears with the correct device identity and usable measurements. A successful subscription with unreadable measurements proves transport, not decoding.

Configure the payload decoder before building alerts. Match the decoder to the exact sensor model and payload format. If the device changes its payload structure, a previously working broker connection can continue delivering messages while the application interprets them incorrectly.

Application delivery configuration

  1. Preserve context. Store the device identity, reception timestamp, measurement name and unit with each reading. A numeric value without a unit is not a useful integration contract.
  2. Handle duplicates. MQTT quality of service level 1 provides at-least-once delivery on the relevant client-to-broker connection, so duplicates are possible. Deduplicate using the identifiers available in your event format; do not assume QoS creates exactly-once database writes.
  3. Define stale-data behaviour. Decide how the application identifies a device that has stopped reporting. Receiving no message is different from receiving a measurement of zero.
  4. Test a disconnect. Stop the subscriber, generate test traffic and reconnect. Confirm what your configured session and broker persistence actually preserve before promising historical recovery.

Expected result: your application handles normal readings, repeated messages and missing reports deliberately. A terminal displaying JSON is only the transport test, not the completed monitoring workflow.

The Things Stack exposes an application MQTT endpoint. Connect a subscriber to that endpoint; do not look for a setting that redirects it to your own broker.

In the application console, use Integrations, then MQTT, to obtain the connection details for that deployment. Copy the displayed endpoint and username rather than constructing them from memory. Create an API key with the application traffic permissions required for the intended operation, and use it as the MQTT password.

The Things Stack uplink subscription follows the pattern v3/{application-id}/devices/+/up. Deployment-specific tenant naming can affect identifiers, so use the console’s supplied details. Its event structure also differs from ChirpStack: a decoded reading belongs under the uplink message structure rather than ChirpStack’s object field.

If your application must consume from a separate broker, run a forwarding client with independent credentials for each side. Subscribe to The Things Stack, validate incoming events and publish to your destination topic. Preserve source timestamps and device identities, and define what happens when the destination is unavailable.

This adds another maintained component. The advantage is a destination topic structure you control; the limitation is responsibility for forwarding failures, retries and duplicates.

A downlink is an application message sent towards a device. It is not the same as publishing a sensor reading back onto an uplink topic.

For ChirpStack’s MQTT integration, the standard command topic pattern is application/{{application_id}}/device/{{dev_eui}}/command/down. The command payload identifies the device, application port, confirmation setting and Base64-encoded payload bytes. Use the command schema for your installed version and the device manufacturer’s documented command format.

Start with a non-critical command on a test device. A syntactically valid command can still contain the wrong application port or manufacturer-specific instruction.

Class A devices normally receive downlinks through 2 receive windows following an uplink. Publishing a command therefore does not mean the physical action happens immediately. Check queue and device behaviour separately, and never treat MQTT publication success as proof that an actuator moved.

Troubleshooting

  • The connection succeeds but no readings arrive. Compare the subscription with ChirpStack’s configured event template, confirm subscription permissions and generate a fresh uplink. Check that the application integration—not only the gateway bridge—is connected.
  • The broker rejects authentication or subscriptions. Check the credentials used by that specific client, then its topic permissions. A valid login does not automatically grant subscription access.
  • The subscriber receives binary-looking content. Enable JSON in ChirpStack’s application MQTT integration, or use a consumer that supports the configured Protocol Buffers event format. Do not treat the entire event as a sensor payload.
  • JSON arrives without decoded measurements. Confirm that raw payload bytes exist, then repair the device codec. For The Things Stack, inspect the decoded payload within the uplink message rather than expecting ChirpStack’s field names.
  • TLS fails despite the correct password. Check certificate hostname matching, certificate expiry, system time and the trust chain. Correct the trust configuration rather than disabling certificate verification.

Customise your workflow

Once a single device works, expand by application or site rather than granting unrestricted access. Keep raw events for diagnosis and publish a separate, documented measurement format for dashboards and alerts. That separation prevents downstream applications from depending on every detail of a network server’s event structure.

For a 2026 deployment, record the server version, topic template, decoder revision and credential owner alongside the application configuration. Include certificate renewal and broker recovery in the operating plan, not just the initial installation tasks.

Kilo Electronics supplies LoRaWAN hardware across manufacturers, but hardware selection does not remove these software responsibilities. Include hosting, retained data, monitoring and maintenance when assessing the complete installation effort.

FAQ

Can a LoRaWAN sensor publish directly to an MQTT broker?

A conventional LoRaWAN sensor sends LoRaWAN radio messages, not MQTT messages over an IP connection. The network-server stack exposes application data through an integration that an MQTT client can consume.

Which MQTT topic should I use for ChirpStack uplinks?

The standard ChirpStack application uplink pattern is application/{application_id}/device/{dev_eui}/event/up. Use the event topic template configured on your installation if it differs.

Do I need my own MQTT broker with The Things Stack?

No. Your client can subscribe to the MQTT endpoint supplied by The Things Stack; forwarding into a separate broker is an additional architecture choice.

Why does my LoRaWAN MQTT message contain Base64 instead of temperature?

Base64 represents payload bytes, not decoded measurements. Configure the correct device codec and read the resulting decoded fields, or decode the bytes in your own application.

Does MQTT QoS guarantee that no sensor readings are lost?

No. MQTT QoS governs delivery on MQTT connections, not the entire radio-to-database path. Radio reception, server processing, session settings and application storage still affect the result.

Can I send commands to LoRaWAN devices through MQTT?

Yes, where the network-server integration supports downlink commands. Use its command topic and schema, and account for the device class, receive opportunities and manufacturer-specific payload format.

One last thing

Test the absence of data as carefully as the arrival of data. Disconnect a test sensor or subscriber and confirm that your application distinguishes a silent device from a normal reading. A working MQTT connection can otherwise conceal the failure that your monitoring system was meant to detect.

You might also like