Skip to content

Connecting to IoT Central

Dave Glover edited this page Sep 4, 2021 · 1 revision

Connecting to IoT Central

Clone the Azure Sphere Samples

git clone --depth 1 https://github.com/Azure/azure-sphere-samples.git

Step 2. Configure Azure IoT Central to work with Azure Sphere

You must set up Azure IoT Central to work with Azure Sphere, if you have not already done so.

Step 3. Enable the Azure IoT Central auto-approve option

  1. Go to Azure IoT Central in your browser.

  2. From the Azure IoT Central Application, click Administration > Device connection, then on the Auto approve new devices option, select Enabled.

Step 4. Authorize IoT Central endpoints

  1. Find the app_manifest.json file in your sample directory and open it. In the following steps, you'll gather the following information and add it to this file:

    • The Scope ID for your Azure IoT Central application.
    • The allowed connections for your Azure Sphere device.
    • The Tenant ID for your Azure Sphere device.
  2. At the command prompt, run the ShowIoTCentralConfig program from the Windows or Linux folder in the sample repository. For example, on Windows, the path is ..\Samples\AzureIoT\Tools\win-x64\ShowIoTCentralConfig.exe. When running this tool on a Linux machine you may have to explicitly set permissions. For example, from a terminal, run chmod +x ShowIoTCentralConfig to set permissions on the tool.

    Note: If you are unable to run the ShowIoTCentralConfig program at the command prompt, delete the AppData\Local\Temp.net\ShowIoTCentralConfig folder, then run the program again.

    Now follow the prompts that the tool provides, and copy the information from the output into the app_manifest.json file. The tool will require the following input:

    • The IoT Central App URL can be found in your browser address bar; for example, https://myiotcentralapp.azureiotcentral.com/.

    • The API token can be generated from your IoT Central application. In the Azure IoT Central application, click Administration > API Tokens > Generate Token, then provide a name for the token; for example, "AzureSphereSample." Select Administrator as the role. Click Generate, and then copy the token to the clipboard. The token starts with SharedAccessSignature.

    • The ID Scope is in the Azure IoT Central application. Click Administration > Device Connection, then copy the ID Scope.

  3. At the command prompt, run the following command to get the Tenant ID:

    azsphere tenant show-selected

    Paste the GUID for your tenant into the DeviceAuthentication field of the app_manifest.json file.

  4. Check that your updated app_manifest.json file has lines that looks like this:

    "CmdArgs": [ "--ScopeID", "<scope_id>" ]

    and:

    "AllowedConnections": [ "global.azure-devices-provisioning.net", "iotc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azure-devices.net", "iotc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azure-devices.net", "iotc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azure-devices.net", "iotc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azure-devices.net", "iotc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azure-devices.net","iotc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azure-devices.net", "iotc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azure-devices.net", "iotc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azure-devices.net","iotc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azure-devices.net", "iotc-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.azure-devices.net" ],

    and:

    "DeviceAuthentication": "<GUID>"

  5. Save the updated application manifest.