There are a variety of Connection Strings with an IoT Hub for connections between it an dhe device and for related apps. You need the right one for any given context. There is inbuilt security with them so not to be bandu=ied about. This hub has been deleted. How to get the connection strings.

A Sample Set of Connection Strings

  • HUB_NAME: "Pico137Hub"
  • HOSTNAME: ""
  • DEVICE_ID: "Pico137Dev"
    • ";DeviceId=Pico137Dev;SharedAccessKey=p+W3ZUuWZGh3nXezNptb4cQjgvIOKwmpie1vw5MjLaM="
    • ";SharedAccessKeyName=iothubowner;SharedAccessKey=V+fpRaoy5tvbNpuTmbpI57MtQ9Sm7twZNJOSWSk3zDM="
    • ";SharedAccessKeyName=service;SharedAccessKey=oGrG7x7DkEXM3Sb8i7aQ6xWYuTrWFzIufRVgGruAYx4=",
    • "sb://"
    • "V+fpRaoy5tvbNpuTmbpI57MtQ9Sm7twZNJOSWSk3zDM="
    • "Enpoint=sb://;SharedAccessKeyName=iothubowner;SharedAccessKey=V+fpRaoy5tvbNpuTmbpI57MtQ9Sm7twZNJOSWSk3zDM=;EntityPath=pico137hub"


Note the overlaps between the settings.

The names given here are what I have have used in a number of apps (and can be changed) and are assigned to environment variables in a Windows context that are read in by the apps. In the apps they are placed in a launchsettings.json file under Properties in a C# app when developing. They are are also placed in a set-env.ps1 file for more general use in a PowerShell context.

  • Telemetry from the device to the hub requires the IOTHUB_DEVICE_CONN_STRING but may be required in parts:
    • HOSTNAME, the HostName above.
    • DEVICE_ID, the DeviceId above.
    • Device Primary Key (not listed above)
  • Monitoring of Telemetry to the hub requires:
    • SHARED_ACCESS_KEY_NAME, service or iothubowner
    • The EVENT_HUBS_CONNECTION_STRING may be used instead of the above but the EVENT_HUBS_COMPATIBILITY_PATH is needed separately.
  • Send CD Messages requires:
  • Direct Methods require:
  • Twin Properties

The connection settings can be found upon inspection from the Azure portal whether from the IoT Hub tab or the device tab. Alternatively they can be collected from an az shell with commandline queries. See the next post here. As an alternative you can get some connection settings from the VS IoT plugins and from IoT Explorer. More on these in a later post.

As previously discussed, the get-iothub suite of PowerShell scripts can generate an IoT Hub and related Device in a menu driven context. It acn also generate these environemnt variable and save to set-env.ps1 PowerShell script. Select option 6. Environment Variables then 2. Generate Env Vars. It can also be used to generate a launnchsettings.json file (Menu option 6.8) that can be inserted in a relevant .NET app. Whilst most apps only require a subset of these, it does no harm to include these complete set in these apps. A Sample:

    "profiles": {
      "ScriptHostRoot": {
        "commandName": "Project",
        "environmentVariables": {

Also, get-iothub can generate the header entries required for the Azure SDK for C Arduino telemetry messaging in focus here. as in the sketches’ iot_config.h file. Select option 6. Environment Variables then 1. Show Environment Variables and at the end it generates the required content that can be copied and pasted into the header file eg.:

#define IOT_CONFIG_DEVICE_ID  "Pico137Dev"
#define IOT_CONFIG_DEVICE_KEY  "p+W3ZUuWZGh3nXezNptb4cQjgvIOKwmpie1vw5MjLaM="

az cli Command Line Connections Settings Queries

 This Category Links 
Category:Pico W AzSDK Index:Pico W AzSDK
  Next: > RPI-Pico-Arduino-AzSDK
<  Prev:   RPI-Pico-Arduino-AzSDK