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.
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
- Device Identity Registry: Manages the identities and security credentials of your devices.
- Device Twin: A JSON document representing the state of a device, including its reported properties and desired configuration.
- Cloud-to-Device (C2D) Messaging: Enables sending commands and messages from your cloud solution to devices.
- Device-to-Cloud (D2C) Telemetry: Allows devices to send telemetry data to your cloud solution.
- Direct Methods: Synchronous operations that allow your cloud solution to invoke a command on a device and receive an immediate response.
- File Upload: Facilitates secure and reliable uploading of files from devices to Azure Blob Storage.
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
- C
- C++
- Python
- Node.js
- Java
- .NET
- (And more...)
To get started, you'll typically need to:
- Create an IoT Hub instance in your Azure subscription.
- Register a device in the IoT Hub identity registry to obtain a device connection string.
- Install the appropriate SDK for your chosen language.
- Write code to connect your device or application using the connection string and interact 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: