Azure IoT Hub SDK Documentation

Welcome to the documentation for the Azure IoT Hub SDKs. These SDKs enable you to connect your devices and applications to Azure IoT Hub, facilitating secure and reliable bidirectional communication.

Tip: Ensure you have the latest version of the SDK installed for optimal performance and security.

Introduction to IoT Hub

Azure IoT Hub is a fully managed service that enables reliable telemetry streaming and device management for millions of IoT devices. It acts as a central message hub between your IoT solution and the devices it manages.

Key Concepts

Getting Started with IoT SDKs

The Azure IoT Hub SDKs are available for various programming languages. Choose the SDK that best fits your development environment.

Supported Languages

To get started, you'll typically need to:

  1. Create an IoT Hub instance in your Azure subscription.
  2. Register a device in the IoT Hub identity registry to obtain a device connection string.
  3. Install the appropriate SDK for your chosen language.
  4. Write code to connect your device or application using the connection string and interact with IoT Hub.
Start Coding with IoT Hub

Common Scenarios & Examples

Sending Telemetry Data

Learn how to send sensor data or other operational metrics from your device to IoT Hub.


# Example using Python SDK
from azure.iot.device import IoTHubDeviceClient, Message

conn_str = "YOUR_DEVICE_CONNECTION_STRING"
client = IoTHubDeviceClient.create_from_connection_string(conn_str)

def send_message():
    message = Message("Hello, IoT Hub!")
    client.send_message(message)
    print("Message sent successfully")

send_message()
        

Receiving Cloud-to-Device Messages

Implement logic to process commands or data sent from the cloud.


// Example using .NET SDK
using Azure.Messaging.IoT;

// ... client initialization ...

client.MessageReceivedHandler = (message, _) =>
{
    Console.WriteLine($"Received message: {message.Body}");
    // Process the message
};

// ... keep client running ...
        

Using Device Twins

Synchronize device state and configuration with the cloud.

API Reference

For detailed information on specific methods and properties of the SDKs, please refer to the API documentation:

Note: Always handle connection strings securely and avoid hardcoding them directly into production code. Use environment variables or Azure Key Vault.