API Reference - Azure IoT SDK for C

This section provides detailed documentation for the C API of the Azure IoT SDK. It covers the core components for connecting and interacting with Azure IoT Hub from embedded devices and other C-based applications.

Core Modules

The SDK is structured into several core modules, each responsible for specific functionalities:

1. IoTHubClient

This module provides the primary interface for communicating with Azure IoT Hub. It handles device-to-cloud messages, cloud-to-device commands, and device twin operations.

Key Functions:

Example: Sending a message

#include "azure_iot_hub.h"

// ...

IOTHUB_CLIENT_HANDLE iotHubClientHandle = NULL;
const char* connectionString = "HostName=your_hub.azure-devices.net;DeviceId=your_device;SharedAccessKey=your_key";
const char* messagePayload = "{ \"message\": \"Hello from C SDK!\" }";

if (IoTHubClient_CreateFromConnectionString(connectionString, IoTHubProtocol_MQTT) != NULL)
{
    iotHubClientHandle = IoTHubClient_CreateFromConnectionString(connectionString, IoTHubProtocol_MQTT);
    if (iotHubClientHandle != NULL)
    {
        IOTHUB_MESSAGE_HANDLE messageHandle = IoTHubMessage_CreateFromByteArray((const unsigned char*)messagePayload, strlen(messagePayload));
        if (messageHandle != NULL)
        {
            IoTHubClient_SendDeviceToCloudMessageAsync(iotHubClientHandle, messageHandle, NULL, NULL);
            IoTHubMessage_Destroy(messageHandle);
        }
        IoTHubClient_Destroy(iotHubClientHandle);
    }
}
            

2. IoTHubDeviceClient

A specialized client for devices. This module focuses on device-specific operations and configurations.

Key Functions:

3. IoTHubModuleClient

This module is used when the application runs as an IoT Edge module. It provides APIs for module-to-module communication and interaction with the IoT Edge runtime.

Key Functions:

4. IoTHubTransport (MQTT, AMQP, HTTP)

These modules encapsulate the transport layer protocols used for communication with IoT Hub. You typically select the desired protocol during client creation.

Supported Protocols:

5. Device Twin and Direct Methods

APIs for managing device twins (desired and reported properties) and handling direct method calls from the cloud.

Key Concepts:

6. Security and Authentication

The SDK supports various security mechanisms for authenticating devices with IoT Hub.

Authentication Methods:

Common Data Structures

Key data structures used throughout the SDK:

IOTHUB_CLIENT_HANDLE

An opaque handle representing an IoT Hub client instance. It must be managed carefully and destroyed when no longer needed.

IOTHUB_MESSAGE_HANDLE

An opaque handle representing a message to be sent to or received from IoT Hub.

IOTHUB_DEVICE_TWIN_HANDLE

An opaque handle for managing device twin operations.

Error Handling

The SDK functions typically return an IOTHUB_CLIENT_RESULT enum value to indicate success or failure. Always check the return values of API calls.

Important: This API documentation is a reference. For practical usage, refer to the Quickstart guide and the Examples section.