Azure IoT Hub comes with 3 SDK's:
- Service SDK
- Device SDK
- Edge SDK
We can Establish Connection to Azure IoT Hub with MQTT,AMQP,HTTPS Protocols.
Sample Code:
#import iothub_client
from iothub_client import *
#confirmation_callback of the message
def send_confirmation_callback(message, result, userContext):
print "Confirmation[%d] received for message with result = %s" % (userContext, result)
#recieve_message_callback
def receive_message_callback(message, counter):
buffer = message.get_bytearray()
size = len(buffer)
print "Received Message"
print " Data: <<<%s>>> & Size=%d" % (buffer[:size], size)
return IoTHubMessageDispositionResult.ACCEPTED
#ConnectionString and Protocol here we have given MQTT you can give HTTPS/AMQP insted of MQTT
#Example: iotHubClient = IoTHubClient(connectionString, IoTHubTransportProvider.AMQP)
iotHubClient = IoTHubClient(connectionString, IoTHubTransportProvider.MQTT)
iotHubClient.set_message_callback(receive_message_callback, 0)
#sends messages Asynchronously to IoT Hub instance
iotHubClient.send_event_async(message, send_confirmation_callback, 0)