MQTT Device communication
Basic instructions
-
MQTT host: mqtts://mqtt.orikami.tech:8883
-
API Docs: https://krane-gateway-beta.orikami.tech/iot/api-docs
-
You need to use MQTT v5
-
Authorized topics:
/iot/{organizationName}/{deviceId}/#. You can both publish and subscribe on those topics. -
Get the certificate and secret key from the device registration. Save them as files. Note that there are newlines (
\n) in the string so if you save them manually you need to make sure to remove them and make them real new lines. -
Use the attached
ca.crtas the CA file. This may be optional if you allow insecure TLS connections (unverified, it still will be encrypted and authenticated) in your client. This is the same for every client. -
The client (device) will need both the certificate and private key to connect. Make sure to store the private key securely if using in production. Ideally you would have some hardware based secure key storage (See https://en.wikipedia.org/wiki/Trusted_execution_environment ). We don't store any of the client keys.
-
You can use any QoS setting, but to guarantee that messages arrive during times of low connectivity, use at least QoS level 1 (At least once guarantee).
-
There's now only one data endpoint (
/data) which handles any type of data. -
The format of the messages need to be like below. Other messages are ignored (not saved, you still will get them if you subscribe to the topic):
{
"timestamp": "2025-07-24T07:27:37Z", // ISO 8601 Date
"payload": {
... // Arbitrary JSON
}
}
Note that there's no device ID or sensor name in the message because those are already set through the topic name.
CA certificate (Public):
-----BEGIN CERTIFICATE-----
MIIBejCCAR+gAwIBAgIRAIaXT8ltdA2RmNlxbKNERwIwCgYIKoZIzj0EAwIwHDEa
MBgGA1UEAxMRbXF0dC5vcmlrYW1pLnRlY2gwHhcNMjUwODIxMDgwNzA0WhcNMzUw
ODE5MDgwNzA0WjAcMRowGAYDVQQDExFtcXR0Lm9yaWthbWkudGVjaDBZMBMGByqG
SM49AgEGCCqGSM49AwEHA0IABBPHRFVETaFhEFSJhr0wLrdeBncPI6KsSPFljKPe
OKrn4WeLeEtmgQMeWNJne/oHKcrkqEb5boUGJoKSUegFUD2jQjBAMA4GA1UdDwEB
/wQEAwICpDAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBTyTkZLrZOMGTGJJqHQ
G4TaFo2MtDAKBggqhkjOPQQDAgNJADBGAiEA/Eqj8Gk5XcOgtfbb5j4qBCCPbTYq
sEXWFlK6p7VddecCIQDPCfDmOImgjS3ZEGyF7WICw5wpn4J3l1LFUe/ISS5kAQ==
-----END CERTIFICATE-----
Why MQTT?
While a HTTP API is sufficient for IoT devices to send data to the backend, sometimes communication from the backend to the device is needed. E.g. for remote configuration or updates. HTTP is not feasible to use in this scenario because it requires that the IoT device publicly exposes it's HTTP endpoints. This is usually not possible. In addition, it moves part of the authentication and authorization responsibilities to the device itself.
Instead, by using a persistent bi-directional communication channel, such as MQTT.
Using MQTT, the device initiates the connection (like with a HTTP API) after which both the device and server can publish and subscribe to MQTT topics.
To ensure secure communication mTLS is used to both encrypt the communication and authenticate the device.
Other options beside MQTT are possible. Another popular approach is using WebSockets. However, MQTT provides some powerful features, such as QoS guarantees, which make it more suited for IoT devices.
MQTT Auth
The preferred way to secure and authenticate communication between the remote devices and the back-end is by mutual authentication through mTLS.
By default the TLS protocol only proves the identity of the server to the client using X.509 certificates, and the authentication of the client to the server is left to the application layer. TLS also offers client-to-server authentication using client-side X.509 authentication.[13] As it requires provisioning of the certificates to the clients and involves a less user-friendly experience, it is rarely used in end-user applications.
When registering a new device (see further in the document), an X.509 key-pair is created which includes the deviceId in the certificate. By provisioning the device with the secret key a mTLS connection can be established where the device is automatically authenticated with the correct deviceId.
Telemetry
The device should connect to the Krane IoT MQTT endpoint for all communication with the backend.
Data (telemetry) will be sent on the following topics.
/{organizationName}/iot/device/{deviceId}/{sensorName}
sensorName can be any string.
Commands
MQTT enables us to have bi-directional communication and as such it’s easy to send messages or commands to the device. These commands can be used for configuration and updating the device. It’s the responsibility of the device to handle these messages.
Commands will be published by the back-end on `/{organizationName}/iot/device/deviceId/command`. The payload is arbitrary and not validated by the back-end.
Make sure that the device is subscribed to the commands topic.
Data API
As most of the communication now happens through MQTT the data API only needs a way to query the data:
GET /iot/{deviceId}
with the following query parameters:
device_id: string
end_date: string<date-time>
start_date: string<date-time>
limit: integer<int64>
and response:
Where data can be an arbitrary (JSON) payload.
Device Management
Device Management API
Can be found here https://krane-gateway-beta.orikami.tech/iot/api-docs (staging)
-
List devices:
GET /iot/devices -
Add a device:
POST /iot/devices-
name: stringDevice name -
deviceId: stringDevice ID. UUID by default -
description: string -
This also returns the certificate key-pair. The secret key is not stored and cannot be requested later.
-
-
Get a device:
GET /iot/devices/{deviceId} -
Update a device
PATCH /iot/devices/{deviceId} -
Delete a device
DELETE /iot/devices/{deviceId} -
Get device metrics
GET /iot/devices/{deviceId}-
Exact metrics T.B.D. E.g. message count
-
-
Renew device certificate
POST /iot/devices/{deviceId}-
This returns the new certificate key-pair. The secret key is not stored and cannot be requested later.
-
-
Send command to device
POST /iot/devices/{deviceId}/command-
Send an arbitrary payload to the device that will be published through MQTT on
/{organizationName}/iot/device/{deviceId}/command
-
High-level diagram