Azure IoT Code Samples

Explore a comprehensive collection of code samples and SDKs designed to help you build robust and scalable Internet of Things solutions on Microsoft Azure.

Getting Started: For a quick start, check out our "Hello World" examples for connecting a device to Azure IoT Hub.

Device SDK Samples

Samples demonstrating how to connect various devices (from microcontrollers to industrial gateways) to Azure IoT Hub using our official SDKs.

Python SDK Samples

# Example: Basic device connection in Python from azure.iot.device import IoTHubDeviceClient CONNECTION_STRING = "YOUR_DEVICE_CONNECTION_STRING" def main(): client = IoTHubDeviceClient.create_from_connection_string(CONNECTION_STRING) client.connect() print("Device connected to IoT Hub") client.disconnect() if __name__ == "__main__": main()

.NET SDK Samples

// Example: Basic device connection in .NET using Azure.Messaging.IotHub.Device; var connectionString = "YOUR_DEVICE_CONNECTION_STRING"; var client = new IoTHubDeviceClient(connectionString); await client.ConnectAsync(); Console.WriteLine("Device connected to IoT Hub"); await client.DisconnectAsync();

Node.js SDK Samples

// Example: Basic device connection in Node.js const { Client } = require('azure-iot-device'); const { Mqtt } = require('azure-iot-device-mqtt'); const connectionString = 'YOUR_DEVICE_CONNECTION_STRING'; const client = Client.fromConnectionString(connectionString, Mqtt); client.open(err => { if (err) { console.error('Could not connect: ' + err.message); } else { console.log('Device connected to IoT Hub'); client.close(); } });

Solution & Service Samples

Samples for building end-to-end IoT solutions, integrating with other Azure services, and implementing advanced IoT scenarios.

Security Note: Always manage your device connection strings securely. Consider using Azure Key Vault or managed identities where appropriate.

Azure IoT Edge Samples

Samples for deploying and managing custom modules on Azure IoT Edge devices.