Connection settings can be established using the API or parsing a connection string with the next options:
HostName
MQTT host nameIdScope
DPS IdScopeDeviceId
Device IdentitySharedAccessKey
Device Shared Access KeySasMinutes
SasToken expire time in minutes, default to60
.X509Key
pathtopfx>|<pfxpassword see details in X509CertificatesModelId
DTDL Model ID in DTMI format to create PnP DevicesModuleId
IoTHub Device Module IdentityUserName
Username to be used to authenticate with MQTT BrokersPassword
Username to be used to authenticate with MQTT BrokersClientId
Client ID used when connecting to MQTT Brokers (IoT Hub requires used deviceId as clientId). Use{machineName}
to overrideKeepAliveInSeconds
Seconds to send keep alive packets, default to60
CleanSession
Establish the connection with a clean session, default totrue
TcpPort
Sets the TCP port for the MQTT connection, defaults to8883
UseTls
Enable/Disable Server TLS connection, defaults totrue
CaFile
Path to the CA certificate required to stablish the TLS session
Azure IoT Hub
HostName=<hubName>.azure-devices.net;DeviceId=<deviceId>;SharedAccessKey=<deviceSasKey>
Azure Device Provisioning Service/Azure IoT Central
IdScope=<dps-id-scope>;DeviceId=<deviceId>;SharedAccessKey=<deviceSasKey>
Azure IoT Plug and Play
HostName=<hubName>.azure-devices.net;DeviceId=<deviceId>;SharedAccessKey=<deviceSasKey>;ModelId=<dtmi:yourmodel;1>
IdScope=<dps-id-scope>;DeviceId=<deviceId>;SharedAccessKey=<deviceSasKey>;ModelId=<dtmi:yourmodel;1>
Using Certificates
HostName=<hubName>.azure-devices.net;X509Key=<path-to-pfx>|<pfx-password>
IdScope=<dps-id-scope>;X509Key=<path-to-pfx>|<pfx-password>
Advanced Connection Options
HostName=<hubName>.azure-devices.net;DeviceId=<deviceId>;SharedAccessKey=<deviceSasKey>;ModelId=<dtmi:yourmodel;1>;SasMinutes=60;KeepAliveInSeconds=30
IdScope=<dps-id-scope>;DeviceId=<deviceId>;SharedAccessKey=<deviceSasKey>;ModelId=<dtmi:yourmodel;1>;SasMinutes=60;KeepAliveInSeconds=30
Connecting to a MQTT Broker
HostName=<broker-hostname>;UserName=<user-name>;Password=<password>;CliendId=<client-id>
HostName=<broker-hostname>;X509Key=<path-to-pfx>|<pfx-password>;ClientId=<client-id>
Note: All samples use the connection settings in the
ConnectionString
configuration, available in theappSettings.json
file, or as the environment variableConnectionStrings__cs
, or command line argument/ConnnectionStrings:cs