Steps Overview
Note: that the following exercise assumes you are already set up your Azure Sphere Tenant and configured your device to connect to IoT Hub as described in my previous Blog Post.
- Download the sample code from Github repository
- Set up an Azure IoT Central application
- Configure Azure IoT Central to work with your Azure Sphere Tenant
- Configure the sample application to work with your Azure IoT Central Application
Detailed Steps
- If you have not done so already, download or clone the Azure Sphere Samples from the Github repository.
- Create an Azure IoT Central trial application.
- Under the Build sub-menu pick Custom Apps
- In the New application page, enter an Application Name and a unique URL.
- Pick 7-day free trial (supports 5 devices).
- Open your new application
- Click on Device Templates and then click “+New” to add a new template
- Select IoT Device and click on “Next: Custom”
- Click on “Next: Review” button:
- Then click on Create button
- Enter a Name for the new Device Template
- Create a Custom Capability Model
- Click on Add Interface and Choose Custom interface
- Choose the Interface (in the left hand column) and
- Click on Add Capability: enter Temperature, temperature. Choose Capability Type Telemetry and Semantic Type Temperature and Choose Degrees Centigrade for Units. Finally, click Save button.
- Then click Customize in left hand column and click on Down Arrow (right-hand-side) to expand the fields.
- Now you can enter a Min value,a Max value and decimal places. You can also customize the Color on the chart.
- Click on “+Add Capability” and enter “Button Press” as the name
- Publish the Device Template to your application
- Click on Devices (left hand side column), pick your device template from the list, then click +New to create a REAL device (not a simulated device).
- For the device ID enter the Azure Sphere device ID (in lower cases letters with the help of PowerShell)
> azshpere device show-attached
> powershell -Command ((azsphere device show-attached)[0] -split ': ')[1].ToLower() - Configure Azure IoT Central to work with your Azure Sphere Tenant
>azsphere tenant download-CA-certificate --output CAcertificate.cer
- In IoT Central’s dashboard, go to Administration, click on Device Connection and then X509 Certificates
- Under the Primary field – click on the folder icon and choose the .cer file created above (choose *.* in the filter field to see the .cer file)
- Then click the Refresh button to generate a Verification Code
- Use the verification code to generate a validation certificate
>azsphere tenant download-validation-certificate --output ValidationCertification.cer --verificationcode <code>
- Go back to IoT Central and click on Verify
- When prompted, navigate to the validation certificate that you downloaded in step #26 and select the .cer file.
- Click Close. This completes the step and verifies that you own the Azure Sphere Tenant.
- Configure the sample application to work with your Azure IoT Central Application
Start Visual Studio 2019 - Choose File-Open-CMake
- Choose the CMakeLists.txt file in the sample you downloaded from Github
- Open the app_manifest.json file
- Get the Tenant ID for your Azure Sphere device and enter it under DeviceAuthentication in app_manifest file:
>azsphere tenant show-selected
- On the Azure Sphere command prompt type:
>ShowIoTCentralConfig
This command will provide the following information needed in app_manifest.json:
a) The IoT hub URL for your Azure IoT Central application
b) The Azure DPS global endpoint address - Power up your Azure Sphere device and make sure it has network access.
- Build and Run your application
1 - Press button A a few times and see the events in IoT Central (as diamonds below the chart)
- You can even view the data points in table format:
Lessons Learned
- Much of the Microsoft documentation gets outdated quickly because IoT Central and Azure Sphere are being updated and changed continuously. With some trial and error, I am sure you will be able to figure out the right steps.
- I faced an issue where the device was not connecting to IoT Central. However, I redid the tenant verification step and it worked again.