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: "Pico137Hub.azure-devices.net"
  • DEVICE_ID: "Pico137Dev"
  • IOTHUB_DEVICE_CONNECTION_STRING:
    • "HostName=Pico137Hub.azure-devices.net;DeviceId=Pico137Dev;SharedAccessKey=p+W3ZUuWZGh3nXezNptb4cQjgvIOKwmpie1vw5MjLaM="
  • IOTHUB_IOTHUBOWNER_CONNECTION_STRING:
    • "HostName=Pico137Hub.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=V+fpRaoy5tvbNpuTmbpI57MtQ9Sm7twZNJOSWSk3zDM="
  • IOTHUB_SERVICE_CONNECTION_STRING:
    • "HostName=Pico137Hub.azure-devices.net;SharedAccessKeyName=service;SharedAccessKey=oGrG7x7DkEXM3Sb8i7aQ6xWYuTrWFzIufRVgGruAYx4=",
  • EVENT_HUBS_COMPATIBILITY_ENDPOINT:
    • "sb://iothub-ns-Pico137Hub-24632627-613f279a76.servicebus.windows.net/"
  • EVENT_HUBS_COMPATIBILITY_PATH: "Pico137Hub
  • EVENT_HUBS_SAS_KEY:
    • "V+fpRaoy5tvbNpuTmbpI57MtQ9Sm7twZNJOSWSk3zDM="
  • EVENT_HUBS_CONNECTION_STRING:
    • "Enpoint=sb://iothub-ns-pico137hub-24632627-613f279a76.servicebus.windows.net/;SharedAccessKeyName=iothubowner;SharedAccessKey=V+fpRaoy5tvbNpuTmbpI57MtQ9Sm7twZNJOSWSk3zDM=;EntityPath=pico137hub"

Comments

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:
    • EVENT_HUBS_COMPATIBILITY_ENDPOINT
    • EVENT_HUBS_COMPATIBILITY_PATH *
    • EVENT_HUBS_SAS_KEY
    • 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:
    • IOTHUB_CONN_STRING_CSHARP
    • DEVICE_ID
  • Direct Methods require:
    • EVENT_HUBS_CONNECTION_STRING
    • DEVICE_ID
  • Twin Properties
    • IOTHUB_CONN_STRING_CSHARP
    • DEVICE_ID

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": {
            "HUB_NAME":Pico137Hub",
            "HOSTNAME":"Pico137Hub.azure-devices.net",
            "DEVICE_ID":"Pico137Dev",
            "IOTHUB_DEVICE_CONNECTION_STRING":"HostName=Pico137Hub.azure-devices.net;DeviceId=Pico137Dev;SharedAccessKey=p+W3ZUuWZGh3nXezNptb4cQjgvIOKwmpie1vw5MjLaM=",
            "IOTHUB_IOTHUBOWNER_CONNECTION_STRING":"HostName=Pico137Hub.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=V+fpRaoy5tvbNpuTmbpI57MtQ9Sm7twZNJOSWSk3zDM=",
            "IOTHUB_SERVICE_CONNECTION_STRING":"HostName=Pico137Hub.azure-devices.net;SharedAccessKeyName=service;SharedAccessKey=oGrG7x7DkEXM3Sb8i7aQ6xWYuTrWFzIufRVgGruAYx4=",
            "EVENT_HUBS_COMPATIBILITY_ENDPOINT":"sb://iothub-ns-pico137hub-24632627-613f279a76.servicebus.windows.net/",
            "EVENT_HUBS_COMPATIBILITY_PATH":"pico137hub",
            "EVENT_HUBS_SAS_KEY":"V+fpRaoy5tvbNpuTmbpI57MtQ9Sm7twZNJOSWSk3zDM=",
            "EVENT_HUBS_CONNECTION_STRING":"Enpoint=sb://iothub-ns-pico137hub-24632627-613f279a76.servicebus.windows.net/;SharedAccessKeyName=iothubowner;SharedAccessKey=V+fpRaoy5tvbNpuTmbpI57MtQ9Sm7twZNJOSWSk3zDM=;EntityPath=pico137hub"
      }
    }
  }
}

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_IOTHUB_FQDN  "Pico137Hub.azure-devices.net"
#define IOT_CONFIG_DEVICE_ID  "Pico137Dev"
#define IOT_CONFIG_DEVICE_KEY  "p+W3ZUuWZGh3nXezNptb4cQjgvIOKwmpie1vw5MjLaM="

az cli Command Line Connections Settings Queries


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