Azure IoT Examples
Our SDK supports all examples provided in Azure Embedded C SDK. In this section, we will provide an overview of each example and introduce how to enable them in our SDK. Readers can expect the same results described in Sample Descriptions on Azure Embedded C SDK and interact with the examples according to it.
IoT Hub Samples
This sample receives incoming cloud-to-device (C2D) messages sent from the Azure IoT Hub to the device. X509 Certificate is used to connect to IoT Hub.
Select the IoT Hub C2D example in
example_azure_iot_entry.h
Uncomment EXAMPLE_AZURE_IOT_HUB_C2D to select the example.
Change the parameters in
example_azure_iot_hub_c2d.c
Modify HUB_HOSTNAME to your own IoT Hub name.
Modify HUB_DEVICE_ID to your own IoT Hub device id.
Modify X509CERTIFICATE to your own x509 certificate.
Modify X509PRIVATEKEY to your own x509 private key.
This sample receives incoming method commands invoked from the Azure IoT Hub to the device. X509 Certificate is used to connect to IoT Hub.
Select the IoT Hub methods example in
example_azure_iot_entry.h
Uncomment EXAMPLE_AZURE_IOT_HUB_METHODS to select the example.
Change the parameters in
example_azure_iot_hub_methods.c
Modify HUB_HOSTNAME to your own IoT Hub name.
Modify HUB_DEVICE_ID to your own IoT Hub device id.
Modify X509CERTIFICATE to your own x509 certificate.
Modify X509PRIVATEKEY to your own x509 private key.
This sample sends five telemetry messages to the Azure IoT Hub.
X509 Authentication
Select the IoT Hub telemetry example in
example_azure_iot_entry.h
Uncomment EXAMPLE_AZURE_IOT_HUB_TELEMETRY to select the example.
Change the parameters in
example_azure_iot_hub_telemetry.c
Modify HUB_HOSTNAME to your own IoT Hub name.
Modify HUB_DEVICE_ID to your own IoT Hub device id.
Modify X509CERTIFICATE to your own x509 certificate.
Modify X509PRIVATEKEY to your own x509 private key.
SAS Authentication
Select the IoT Hub SAS telemetry example in
example_azure_iot_entry.h
Uncomment EXAMPLE_AZURE_IOT_HUB_SAS_TELEMETRY to select the example.
Change the parameters in
example_azure_iot_hub_sas_telemetry.c
Modify HUB_HOSTNAME to your own IoT Hub name.
Modify HUB_DEVICE_ID to your own IoT Hub device id.
Modify HUB_SAS_KEY to your own SAS Key.
This sample utilizes the Azure IoT Hub to get the device twin document, send a reported property message, and receive up to 5 desired property messages. X509 Certificate is used to connect to IoT Hub.
Select the IoT Hub twin example in
example_azure_iot_entry.h
Uncomment EXAMPLE_AZURE_IOT_HUB_TWIN to select the example.
Change the parameters in
example_azure_iot_hub_twin.c
Modify HUB_HOSTNAME to your own IoT Hub name.
Modify HUB_DEVICE_ID to your own IoT Hub device id.
Modify X509CERTIFICATE to your own x509 certificate.
Modify X509PRIVATEKEY to your own x509 private key.
This sample connects an IoT Plug and Play enabled device (a thermostat) with the Digital Twin Model ID (DTMI) detailed here. X509 Certificate is used to connect to IoT Hub.
Select the IoT Hub plug and play example in
example_azure_iot_entry.h
Uncomment EXAMPLE_AZURE_IOT_HUB_PNP to select the example.
Change the parameters in
example_azure_iot_hub_pnp.c
Modify HUB_HOSTNAME to your own IoT Hub name.
Modify HUB_DEVICE_ID to your own IoT Hub device id.
Modify X509CERTIFICATE to your own x509 certificate.
Modify X509PRIVATEKEY to your own x509 private key.
This sample extends the IoT Hub Plug and Play Sample above to mimic a Temperature Controller and connects the IoT Plug and Play enabled device (the Temperature Controller) with the Digital Twin Model ID (DTMI) detailed here. X509 Certificate is used to connect to IoT Hub.
Select the IoT Hub plug and play multiple component example in
example_azure_iot_entry.h
Uncomment EXAMPLE_AZURE_IOT_HUB_PNP_COMPONENT to select the example.
Change the parameters in
example_azure_iot_hub_pnp_component.c
Modify HUB_HOSTNAME to your own IoT Hub name.
Modify HUB_DEVICE_ID to your own IoT Hub device id.
Modify X509CERTIFICATE to your own x509 certificate.
Modify X509PRIVATEKEY to your own x509 private key.
IoT Provisioning Samples
This sample registers a device with the Azure IoT Device Provisioning Service. X509 Certificate is used to connect to device provisioning service.
For the X509 certificate used for IoT provisioning, please make sure
your x509 certificate is created with x509 v3 extension.
X509v3 Basic Constraints: CA:FALSE
X509v3 Key Usage: Digital Signature, Non Repudiation, Key Encipherment
Select the IoT provisioning certificate example in
example_azure_iot_entry.h
Uncomment EXAMPLE_AZURE_IOT_PROVISIONING to select the example.
Change the parameters in
example_azure_iot_provisioning.c
Modify ID_SCOPE to your own DPS id scope.
Modify REGISTRATION_ID to your own registration id.
Modify X509CERTIFICATE to your own x509 certificate.
Modify X509PRIVATEKEY to your own x509 private key.
This sample registers a device with the Azure IoT Device Provisioning Service. SAS authentication is used to connect to device provisioning service.
Select the IoT Provisioning SAS example in
example_azure_iot_entry.h
Uncomment EXAMPLE_AZURE_IOT_PROVISIONING_SAS to select the example.
Change the parameters in
example_azure_iot_provisioning_sas.c
Modify ID_SCOPE to your own DPS id scope.
Modify REGISTRATION_ID to your own registration id.
Modify SAS_KEY to your own SAS key.