This sample demonstrates how to use the Azure IoT SDK C APIs in an Azure Sphere application to communicate with Azure IoT Central or Azure IoT Hub.
IMPORTANT: This sample application requires customization before it will compile and run. Follow the instructions in this README and in IoTCentral.md and/or IoTHub.md to perform the necessary steps.
This application does the following:
- Sends simulated temperature telemetry to Azure IoT Central or an Azure IoT Hub at regular intervals.
- Sends a button-press event to Azure IoT Central or an Azure IoT Hub when you press button A on the MT3620 development board.
- Sends simulated orientation state to Azure IoT Central or an Azure IoT Hub when you press button B on the MT3620 development board.
- Controls one of the LEDs on the MT3620 development board when you change a toggle setting on Azure IoT Central or edit the device twin on Azure IoT Hub.
Before you can run the sample, you must configure either an Azure IoT Central application or an Azure IoT Hub, and modify the sample's application manifest to enable it to connect to the Azure IoT resources that you configured.
By default, this sample runs over a Wi-Fi connection to the internet. To use Ethernet instead, make the following changes:
-
Configure Azure Sphere as described in Connect Azure Sphere to Ethernet.
-
Add an Ethernet adapter to your hardware. If you are using an MT3620 RDB, see the wiring instructions.
-
Add the following line to the Capabilities section of the app_manifest.json file:
"NetworkConfig" : true
-
In main.c, add the following lines before any other networking calls:
int err = Networking_SetInterfaceState("eth0", true); if (err == -1) { Log_Debug("Error setting interface state %d\n",errno); return -1; }
-
In the Project Properties, set the Target API Set to 4.
The sample uses these Azure Sphere application libraries.
Library | Purpose |
---|---|
log | Displays messages in the Visual Studio 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 | Gets the path to the certificate file that is used to authenticate the server |
EventLoop | Invoke handlers for timer events |
The sample requires the following software:
- Azure Sphere SDK version 20.04 or later. At the command prompt, run azsphere show-version to check. Install the Azure Sphere SDK if necessary.
- An Azure subscription. If your organization does not already have one, you can set up a free trial subscription.
Note: By default, this sample targets MT3620 reference development board (RDB) hardware, such as the MT3620 development kit from Seeed Studios. To build the sample for different Azure Sphere hardware, change the Target Hardware Definition Directory in the project properties. For detailed instructions, see the README file in the Hardware folder.
-
Set up your Azure Sphere device and development environment as described in the Azure Sphere documentation.
-
Clone the Azure Sphere Samples repository on GitHub and navigate to the AzureIoT folder.
-
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.
-
Open an Azure Sphere Developer Command Prompt and enable application development on your device if you have not already done so:
azsphere device enable-development