Connection settings can be established using the API or parsing a connection string with the next options:
HostNameMQTT host nameIdScopeDPS IdScopeDeviceIdDevice IdentitySharedAccessKeyDevice Shared Access KeySasMinutesSasToken expire time in minutes, default to60.X509Keypathtopfx>|<pfxpassword see details in X509CertificatesModelIdDTDL Model ID in DTMI/Proto format to indicate the model the device implementsModuleIdIoTHub Device Module IdentityUserNameUsername to be used to authenticate with MQTT BrokersPasswordUsername to be used to authenticate with MQTT BrokersClientIdClient ID used when connecting to MQTT Brokers (IoT Hub requires used deviceId as clientId). Use{machineName}to overrideKeepAliveInSecondsSeconds to send keep alive packets, default to60CleanSessionEstablish the connection with a clean session, default totrueTcpPortSets the TCP port for the MQTT connection, defaults to8883UseTlsEnable/Disable Server TLS connection, defaults totrueCaFilePath to the CA certificate required to stablish the TLS sessionGatewayHostNameAllows to connect to IoT Hub through a IoTEdge ($edgeHub) gateway (aka Transparent Gateway)MqttVersionSets the MqttProtocolVersion, allowed values are 5 and 3 (will use 3.1.1)MqttGatewayHostNameAllows to connect to IoTHub through a mqtt broker. Requires a gateway to implement the transparent gateway pattern.
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
ConnectionStringconfiguration, available in theappSettings.jsonfile, or as the environment variableConnectionStrings__cs, or command line argument/ConnnectionStrings:cs