Exercise - Remotely reboot your Azure Sphere device with an Azure IoT direct method
Step 1: Build and deploy your application
Start Visual Studio Code to open your project.
From the menu, click File, then Open Folder.
Open the Azure-Sphere lab folder.
Open the Lab_4_Direct_Methods folder.
Click Select Folder or the OK button to open the project.
Step 2: Set your developer board configuration
These labs support developer boards from Avnet and Seeed Studio. You need to set the configuration that matches your developer board.
The default developer board configuration is for the Avnet Azure Sphere Starter Kit Revision 1. If you have this board, there's no additional configuration required.
Open the CMakeList.txt file.
Add a
#
at the beginning of the set Avnet line to disable it.Uncomment the
set
command that corresponds to your Azure Sphere device developer board.set(AVNET TRUE "AVNET Azure Sphere Starter Kit Revision 1 ") # set(AVNET_REV_2 TRUE "AVNET Azure Sphere Starter Kit Revision 2 ") # set(SEEED_STUDIO_RDB TRUE "Seeed Studio Azure Sphere MT3620 Development Kit (aka Reference Design Board or rdb)") # set(SEEED_STUDIO_MINI TRUE "Seeed Studio Azure Sphere MT3620 Mini Dev Board")
Save the file. This will autogenerate the CMake cache.
Step 3: Configure the Azure IoT connection information
Open the app_manifest.json file.
You'll need to redo the settings for the app_manifest.json file. Either copy the settings from Notepad if you still have it open. Alternatively, copy the app_manifest.json settings created in the previous exercise.
Replace the existing configuration by pasting the contents of the clipboard into app_manifest.json.
Save the updated app_manifest.json file.
Step 4: Start the app build deploy process
- Open main.c.
- Select CMake: [Debug]: Ready from the Visual Studio Code status bar.
- From Visual Studio Code, press F5 to build, deploy, start, and attach the remote debugger to the application now running the Azure Sphere device.
Expected device behavior
Azure Sphere MT3620 Starter Kit Revision 1 and 2
The WLAN LED will blink every 5 seconds when connected to Azure.
When you initiate the device restart direct method, you will observe the device restarting.
Seeed Studio Azure Sphere MT3620 Development Kit
The WLAN LED will blink every 5 seconds when connected to Azure.
When you initiate the device restart direct method, you will observe the device restarting.
Seeed Studio MT3620 Mini Dev Board
The User LED will blink every 5 seconds when connected to Azure.
When you initiate the device restart direct method, you will observe the device restarting.
Testing Azure IoT Hub direct method commands
Start Azure IoT Explorer.
Click View devices in this hub.
Click your on your device.
Click IoT Plug and Play components from the side menu.
Click Default component.
Select Commands from the menu.
Set the Restart Delay value to be greater than 2 and less than 10.
Click the Send command button.
Close Visual Studio
Now close Visual Studio.