Azure IoT Hub

Receive your device data in Azure IoT Hub as device-to-cloud messages, with an X.509 certificate.

This guide shows how to receive CeresGate's forwarded device data in Azure IoT Hub. CeresGate connects over MQTT as a device in your IoT hub, with an X.509 certificate, and sends the data as device-to-cloud messages; from there, message routing can send it on to Event Hubs, Storage, Functions and other services.

How it works

CeresGate → MQTT over TLS (X.509) publish to devices/<Device ID>/messages/events/ → Azure IoT Hub → your message routing or event processing
  • For every message a device uploads, CeresGate connects to the IoT hub with your certificate, sends {"IMSI": …, "Payload": …} as a device-to-cloud message, and disconnects (see Forwarding format).
  • The connection is always mqtts, port 8883, MQTT 3.1.1, as IoT Hub's MQTT support requires; there's nothing to set.
  • With QoS 1, the forwarding logs show "Forwarded" once IoT Hub acknowledges the message within the timeout. IoT Hub doesn't support QoS 2.

1. Prepare the IoT hub and a device

  1. Create an IoT hub in the Azure portal (or use an existing one) and note its hostname, which looks like my-hub.azure-devices.net.
  2. Under the IoT hub's "Devices", add a device, note its Device ID (for example ceresgate-uplink) and choose X.509 authentication.
  3. Prepare a client certificate and private key for the device (PEM). X.509 authentication can use a self-signed certificate (registered by thumbprint) or a CA-signed one; choose and set it up as Azure's documentation recommends: Authenticate with X.509 certificates.
  4. Get the root CA of IoT Hub's server certificate (PEM). For which root CA to use today, follow Azure's documentation: Azure IoT Hub TLS support.

2. Create the adapter in CeresGate

In the portal's sidebar, choose "Adapter settings" and add an Azure IoT Hub adapter:

FieldEnterExample
NameAnything that helps you recognise it
clientidThe Device ID from step 1ceresgate-uplink
hostnameThe IoT hub's hostnamemy-hub.azure-devices.net
usernameFilled in once clientid and hostname are entered: <hostname>/<Device ID>/?api-version=2021-04-12my-hub.azure-devices.net/ceresgate-uplink/?api-version=2021-04-12
connectiontimeoutSeconds to wait for IoT Hub's acknowledgement10
keepaliveMQTT keepalive in seconds60
uplinktopicFilled in once clientid is entered: devices/<Device ID>/messages/events/; usually leave it as isdevices/ceresgate-uplink/messages/events/
qos0 or 1; 1 is recommended1
rootcaThe root CA from step 1
clientcaThe device's client certificate
clientkeyThe device's private key

urimethod (mqtts), port (8883) and mqttversion (3.1.1) are fixed and shown below the form. Certificates and keys are stored encrypted and not shown when editing; to replace them, upload all three files again. Then, in the Adapter column of the device list, choose this adapter for your devices.

An adapter previously saved with qos 2 shows "Please choose again" for qos when edited; choose 0 or 1 and save.

3. Check that data arrives

Watch the events the device sends into IoT Hub with the Azure CLI (with the azure-iot extension), then let the device send a message:

az extension add --name azure-iot
az iot hub monitor-events --hub-name my-hub --device-id ceresgate-uplink

{"IMSI": "001013453258396", "Payload": "48656c6c6f"} appears. The portal's "Forwarding logs" also show "Forwarded". Then set up "Message routing" in the IoT hub to send the messages to your services.

When forwarding fails

  • Failed to connect to Azure IoT Hub: whether the hostname is right; whether clientid is a Device ID that exists and is enabled in the IoT hub; whether username matches the hostname and Device ID; whether the client certificate is the one registered for this device (the self-signed certificate's thumbprint matches, or the CA is verified in the IoT hub), unexpired and matching the private key; whether the root CA is the one Azure's documentation currently recommends.
  • Failed to send payload to Azure IoT Hub.: connected, but no acknowledgement arrived within the timeout. Check that the uplinktopic is devices/<Device ID>/messages/events/ and qos is 0 or 1, or make connectiontimeout longer.

For the details of MQTT connections, see Azure's documentation: Use MQTT to communicate with Azure IoT Hub. For other cases, see Forwarding logs and troubleshooting.