# Connecting MQTT Devices

As a prerequisite to use MQTT with KPN Things, you need either a [Device with a KPN Things SIM card which is configured to use the `kpnthings2.m2m` APN](/kpn-things/building-blocks/connectivity/connecting-m2m-devices.md) or a [configured Internet device](/kpn-things/building-blocks/connectivity/connecting-internet-devices.md).

Integrating your device using MQTT is easy as it relies on standard publish and subscription methods. After ingestion, data will be processed and delivered using the [KPN Things flow mechanism](/kpn-things/the-portal-explained/things-manager/processing.md). Downlinks towards a device can be specified using the Portal or available API's.

{% hint style="info" %}
This page deals with sending data *into* the Things processing engine. [Read more about how to use MQTT to send data out of Things here](/kpn-things/building-blocks/destinations/mqtt-broker.md).
{% endhint %}

## Portal configuration

### How to enable MQTT for a device

Login to [the Things Portal](https://portal.kpnthings.com):

1. Find an M2M enabled Device (e.g. a type "Own M2M") in your *Devices* list. Open the *Device details* page by clicking on the Device.&#x20;
2. On the *Device details* page you will see a link in the top-right corner: "Activate MQTT service". Click the link.
3. You should see a message "MQTT Service was successfully activated." and the MQTT tab will appear, showing the MQTT details.
4. This is the only time you will be able to read (and copy) the generated password, so make sure you note it down. If you need to, you can edit the MQTT configuration to set a different (generated) password.
5. Use the credentials to configure your Device and you are good to go!

## Connecting your MQTT device to KPN Things

KPN Things provides an MQTT connector that can be used to publish uplinks from your MQTT device to the KPN Things platform and receive downlinks from the KPN Things platform. Note that the KPN Things MQTT connector is not a full MQTT broker. It can only be used to send uplinks to and receive downlinks from the KPN Things platform. Uplinks published by your device will not be visible to other devices that connect to the MQTT connector. Likewise, downlinks sent to your device will only be visible to your device.

The KPN Things MQTT connector supports MQTT 3.1, MQTT 3.1.1 and MQTT 5.0.

### Connecting to the KPN Things MQTT connector

For M2M devices that use a KPN Things SIM card (using APN `kpnthings2.m2m`), the MQTT connector can be accessed using the MQTT protocol on `10.151.236.154` port `1883`. Note that even though the MQTT protocol is unencrypted, your connection to KPN Things is secure because your device has a direct encrypted connection to KPN Things through the mobile network.

If your device does not use a KPN Things SIM card and you have configured it as an Internet device in KPN Things Portal, you can only access the MQTT connector using MQTTS on `connect.mqtt.kpnthings.com` port `8883`.&#x20;

For MQTTS to work correctly, many devices and/or MQTTS clients must be configured to trust KPN Things MQTT connector's server certificate (or rather the CA root certificate). Whether your device needs this extra configuration depends on the device or MQTT client used. Should you need it, you can download the CA root certificate here:

{% file src="/files/iFjetM3jtThndHxmzaGK" %}

When connecting to the MQTT connector, you must provide the username and password that were displayed in Things Portal when you activated MQTT for your device. The MQTT connector currently does not support authentication using client certificates.

To recap:

<table><thead><tr><th>Device type</th><th width="392.3333333333333">Connector address</th><th>Protocol</th></tr></thead><tbody><tr><td>M2M using a KPN Things SIM card</td><td><code>10.151.236.154</code>, port <code>1883</code></td><td>MQTT</td></tr><tr><td>Internet device</td><td><code>connect.mqtt.kpnthings.com</code>, port <code>8883</code></td><td>MQTTS</td></tr></tbody></table>

### Sending an uplink

KPN Things MQTT connector will ingest uplinks on any topic, so you're free to choose. The expected message format depends on the decoder you have configured for your device. The decoder for the "Own M2M" and "Own Internet" device types supports SenML, the internal format of the Things Platform. If you're using the decoder `› Decoded ThingsML and raw SenML data`, your message payload should be a valid SenML pack. For more information see the [SenML documentation](/kpn-things/building-blocks/data-processing/thingsml-and-senml/senml.md).

### Sending a downlink

#### Things Manager

You can send a downlink to your MQTT device using the "Send instruction" tab on the device detail page in Things Portal.

#### API

Or you can [use the Actuator API](https://docs.kpnthings.com/kpn-things/kpn-things-user-guide/tutorials/technical-overview/downlink-communication#actuator-api) to send downlinks automagically.

The downlink will be published to the `downlink` topic and will be delivered to the MQTT device the next time the device connects and subscribes to the topic.


---

# 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/connectivity/connecting-mqtt-devices.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.
