Azure Sphere – Azure IoT
IMPORTANT: Before you can compile and run the sample, you must configure an Azure IoT Hub application, and customize the sample to connect to it. Carefully follow the instructions in this README and in its linked topics.
This sample application implements an example thermometer that works with Azure IoT Hub as follows:
- Sends simulated temperature telemetry data at regular intervals.
- Sends a simulated thermometer moved telemetry event when button B is pressed.
- Reports a read-only string serial number device twin.
- Synchronizes a read/write boolean Thermometer Telemetry Upload Enabled device twin.
- This status is reflected by one of the LEDs on the MT3620 development board.
- This status can be turned on/off via the cloud or on the device itself by pressing button A.
- Implements a display alert direct method. For example, a cloud solution could call this method when it receives a temperature reading that is higher than a given threshold.
- Declares that it implements the Azure Sphere Example Thermometer model, consisting of this telemetry, device twin, and direct method by sending its Azure IoT Plug and Play (PnP) model ID upon connection.
This sample uses the following Azure Sphere application libraries:
|log||Displays messages in the Device Output window during debugging|
|networking||Determines whether the device is connected to the internet|
|gpio||Manages buttons A and B and LED 4 on the device|
|storage||Opens the certificate file that is used to authenticate to the IoT Edge device|
|EventLoop||Invoke handlers for timer events|
||Application manifest file, which describes the resources.|
||CMake configuration file, which Contains the project information and is required for all builds.|
||JSON file for configuring Visual Studio to use CMake with the correct command-line options.|
||JSON file that tells Visual Studio how to deploy and debug the application.|
||The license for this sample application.|
||Main C source code file.||
||This README file.|
||Instructions for customizing the sample to run with Azure IoT Central.|
||Instructions for customizing the sample to run with an Azure IoT Edge device.|
||Instructions for customizing the sample to run with Azure IoT Hub.|
||Folder containing the JSON files that configure Visual Studio Code for building, debugging, and deploying the application.|
||Folder containing the hardware definition files for various Azure Sphere boards.|
This sample requires the following software and hardware:
An Azure subscription. If your organization does not already have a subscription, you can set up a free trial subscription.
Note: By default, this sample targets MT3620 reference development board (RDB) hardware, like the MT3620 development kit from Seeed Studios. To build the sample for different Azure Sphere hardware, change the Target Hardware Definition Directory in the CMakeLists.txt file. For detailed instructions, see the README file in the HardwareDefinitions folder.
Complete the following steps to prepare your environment:
Set up your Azure Sphere device and development environment as described in Azure Sphere documentation.
Connect your Azure Sphere device to your computer by USB.
Enable a network interface on your Azure Sphere device and verify that it is connected to the internet.
azsphere device enable-development
Use Ethernet instead of Wi-Fi
By default, this sample runs over a Wi-Fi connection to the internet. To use Ethernet instead, follow the Ethernet setup instructions.
Run the sample
You can use either Azure IoT Hub or Azure IoT Central to configure the sample:
- To change your device authentication method to use device provisioning service instead of direct authentication, see Connect via Azure IoT Hub device provisioning service.
- To add an IoT Edge device that provides a filtering and data processing layer between your Azure Sphere device and IoT Hub, see Connect via Azure IoT Edge.