Azure IoT Hub¶
Azure imposes payload and topic format restrictions, making it impossible to use the standard format. When Azure is in use the following changes are made:
- Device events can only be sent to
devices/<device_id>/messages/events/
. Therefore all messages are sent, with additional path components attached to the query portion of the path; e.g,devices/TestDevice/messages/events/cmd=DBIRTH&grp=normalgw&node=TestDevice&dev=500
- Sparkplug requires that all device metadata be sent within a single
DBIRTH
message; however this can cause the Azure message size limit to be exceeded. NF will paginate device metadata into multipleDBIRTH
messages with the same sequence number; by default up to 1000 objects can be placed into a single message. - NF implements the Shared Access Signature algorithms for generating MQTT passwords.
Automatic Configuration¶
NF now supports configuring an Azure IoT Hub connection using the
EdgeHubConnectionString
variable. Simply copy the value from the
Azure portal into your application (the value that looks like
HostName=nf-test.azure-devices.net;DeviceId=nf-test-1;SharedAccessKey=hZm8lXLkdN80cKvWN8t+...
).
This is the recommended way to configure an IoT Hub connection and sets all required variables to the recommended values.
Manual Configuration¶
Alternatively, after creating an Azure IoT hub and provisioning a device, you may use the following configuration to connect NF to your IoT Hub:
Environment Variable | Description | Value |
---|---|---|
AZURE_SHARED_ACCESS_KEY | Set to access key provided by Azure | <base64 value> |
AZURE_SHARED_ACCESS_SIG_TTL | How long SASs are valid | 604800 |
MQTT_BROKER | Hub URL | <hub_name>.azure-devices.net> |
MQTT_CAFILE | CA to validate hub against | /etc/cacerts/BaltimoreCyberTrustRoot.crt |
MQTT_CLIENT_ID | <device name> |
|
MQTT_PORT | 8883 |
|
MQTT_PROTOCOL | tls |
|
SPARKPLUG_AUTO_RECOVER | Send buffered data after an outage | 1 |
SPARKPLUG_DDATA_SET_NAME | Don't use Sparkplug's alias mechanism | 1 |
SPARKPLUG_NAMESPACE | Confirm to topic format restriction | devices/<device name>/messages/events/ |
SPARKPLUG_NODE_ID | <device name> |