MQTT Broker
Receive your device data on your own MQTT broker, such as Mosquitto or HiveMQ.
This guide shows how to receive CeresGate's forwarded device data on your own MQTT broker. The examples use Mosquitto and HiveMQ; any broker supporting MQTT 3.1, 3.1.1 or 5.0 works too.
How it works
CeresGate → MQTT publish to the uplinktopic → your MQTT broker → your application subscribed to that topic
- For every message a device uploads, CeresGate connects to your broker, publishes
{"IMSI": …, "Payload": …}to the adapter's uplinktopic, and disconnects (see Forwarding format). - Each connection's client ID is the adapter's
clientidfollowed by_and 8 random characters (for exampleceresgate_3f2a9c1e), so simultaneous connections don't kick each other off. If your broker restricts client IDs, allow IDs starting with theclientid. - Messages are not retained (retain = false) and use a clean session. When the broker acknowledges the message within the timeout, the forwarding logs show "Forwarded".
- Your broker must be reachable from the internet for CeresGate to deliver to it.
1. Choose how to authenticate
| The adapter's SSL/TLS switch | Authentication | Use with |
|---|---|---|
| Off | User name and password | mqtts, port 8883: the connection is TLS-encrypted. mqtt (port 1883) is unencrypted, sending the password and data in plain text; use it for testing only |
| On | Client certificate (X.509): upload the root CA, client certificate and private key | Must be mqtts, usually port 8883 |
Verifying the broker's certificate (SSL secure)
With a user name and password over mqtts, the form shows an "SSL secure" switch (on by default for new adapters). When it's on, CeresGate verifies the broker's server certificate, making sure it's talking to your broker so the password and data can't be taken by an impostor:
- The broker's certificate is issued by a public CA (for example Let's Encrypt or HiveMQ Cloud): nothing to upload.
- The broker uses a self-signed certificate or your own CA: under "Server CA (optional)", upload the broker's self-signed certificate itself, or the CA that issued it; with an intermediate CA, upload the root and intermediate CAs together in one file, or have the broker send the full chain.
- The host name must match: the adapter's hostname must be in the certificate's SAN (Subject Alternative Name), or equal its CN if it has no SAN. When connecting by IP, the SAN must contain that IP.
- An expired certificate fails the connection.
With "SSL secure" off, the connection is still TLS-encrypted but the server certificate isn't verified. Client-certificate authentication (SSL/TLS switch on) always verifies the server certificate against the uploaded root CA.
2. Set up your broker
Mosquitto (user name and password)
Create an account for CeresGate and allow it to publish only to the topics it needs:
# Create the account (prompts for a password)
mosquitto_passwd -c /etc/mosquitto/passwd ceresgate
# /etc/mosquitto/acl: publish only under ceresgate/
user ceresgate
topic write ceresgate/#
# /etc/mosquitto/conf.d/ceresgate.conf
listener 8883
certfile /etc/mosquitto/certs/server.crt
keyfile /etc/mosquitto/certs/server.key
allow_anonymous false
password_file /etc/mosquitto/passwd
acl_file /etc/mosquitto/acl
Restart Mosquitto afterwards. The server certificate can be a public one such as Let's Encrypt.
Mosquitto (client certificate)
Add a cafile to the listener and require client certificates; issue a client certificate for CeresGate from your CA:
listener 8883
cafile /etc/mosquitto/certs/ca.crt
certfile /etc/mosquitto/certs/server.crt
keyfile /etc/mosquitto/certs/server.key
require_certificate true
use_identity_as_username true
With use_identity_as_username, the client certificate's CN is used as the user name, which is what the ACL refers to.
HiveMQ
- HiveMQ Cloud: create credentials in the cluster's access management (publish permission only is recommended), and connect to the cluster's host name on port 8883 with
mqtts. - Self-hosted HiveMQ: set up user names and passwords or client certificates with the authentication extension you use, and enable a TLS listener.
3. Create the adapter in CeresGate
In the portal's sidebar, choose "Adapter settings" and add an MQTT Broker adapter:
| Field | Enter | Example |
|---|---|---|
| Name | Anything that helps you recognise it | |
| clientid | The start of the client ID (CeresGate appends random characters) | ceresgate |
| urimethod | mqtt:// or mqtts:// | mqtts:// |
| hostname | The broker's host name or IP, without mqtt:// or the port | broker.example.com |
| port | The broker's port | 8883 |
| mqttversion | 3.1, 3.1.1 or 5.0, matching what the broker supports | 3.1.1 |
| connectiontimeout | Seconds to wait for the broker's acknowledgement | 10 |
| keepalive | MQTT keepalive in seconds | 60 |
| uplinktopic | The topic device data is published to; must be allowed by the ACL | ceresgate/uplink |
| qos | 1 or 2 | 1 |
| SSL/TLS switch | See step 1 | |
| username, password | Switch off: the account from step 2 (the password is stored encrypted and not shown when editing) | |
| SSL secure, server CA | Switch off with mqtts: see "Verifying the broker's certificate" in step 1 | |
| rootca, clientca, clientkey | Switch on: the root CA (to verify the broker's server certificate), the client certificate and the client private key, as PEM files |
Then, in the Adapter column of the device list, choose this adapter for your devices.
4. Check that data arrives
Subscribe to the uplinktopic with mosquitto_sub first, then let the device send a message:
# User name and password (mqtts)
mosquitto_sub -h broker.example.com -p 8883 --capath /etc/ssl/certs \
-u reader -P '********' -t 'ceresgate/uplink' -q 1 -v
# What arrives
ceresgate/uplink {"IMSI": "001013453258396", "Payload": "48656c6c6f"}
Subscribe with a separate account that may read the topic (reader above) rather than CeresGate's. CeresGate's messages aren't retained, so subscribe before the data is sent. The portal's "Forwarding logs" also show "Forwarded".
When forwarding fails
Failed to connect to MQTT Broker: …: the reason follows the colon. Check whether the host name, port andmqtt/mqttsmatch the broker's listener; whether the client certificate is issued by a CA the broker trusts, unexpired and matches the private key; whether a firewall allows connections from the internet.certificate verify failedmeans the server certificate didn't verify:unable to get local issuer certificate: the broker's certificate isn't from a public CA, so upload the server CA; if you did, make sure it's the one that issued the broker's certificate, plus any intermediate CAHostname mismatch/IP address mismatch: the adapter's hostname isn't in the certificate's SAN (or CN)certificate has expired: renew the broker's certificate
Failed to send payload to MQTT Broker.: connected, but no acknowledgement arrived within the timeout. Check the broker's load and network, or make connectiontimeout longer.
Shown as "Forwarded", but the subscriber gets nothing
- Make sure the subscribed topic is exactly the uplinktopic (case, slashes).
- Check the ACL: CeresGate's account must be allowed to publish to the uplinktopic, and the subscriber's account to read it. Brokers such as Mosquitto still acknowledge a publish they aren't allowed to deliver and simply drop it, so the forwarding logs show "Forwarded".
For other cases, see Forwarding logs and troubleshooting.