Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Connect to Azure IoT Hub in browser ( using AMQP over WebSockets )

Azure provides simple ways to Connect to Iot Hub through azure-iot-sdk, but some developers would like to figure out what the sdk exactly did or integrate with their own services. In this situation, it is necessary to find out how to connect to Azure IoT Hub above protocol level.

AMQP is the only protocol to connect to IoT Hub ( You can find detailed spec of this protocol here, but trust me, it isn’t easy to go through this ). Since using browser to do this is quite convenient for developing and debugging, so we will choose AMQP over WebSockets to connect.

First we have to create a websocket tunnel. Here is the url:

wss://.azure-devices.net:443/$iothub/websocket

Sec-WebSocket-Protocol: AMQPWSB10

Then you will have to establish AMQP connection. Use the following parameters to connect, you need to use SASL.

Key Value
hostname .azure-devices.net
container_id “conn” +
max_frame_size 4294967295
channel_max 65535
idle_timeout 120000
outgoing_locales en-US
incoming_locales en-US
offered_capabilities null
desired_capabilities null
properties {}
connection_details
reconnect false
username @sas.root.
password

After connection is established and opened, we need to open a receiver and a sender. We use sender to send cloud-to-device message and use receiver to receive feedback message.(Unfortunately, currently we didn’t find a way to fetch device-to-cloud message, we guess we can only do this by connecting EventHub or ServiceBus)

Sender:/messages/devicebound
Receiver:/messages/serviceBound/feedback

OK, now we’re finished! You can test with your device to see if it works. If you don’t have a device in hand or feel troublesome to use device, you can try our Web-based Iot device simulator. It can simulator an Iot Device and communicate with IoT Hub. | Connect to Azure IoT Hub in browser ( using AMQP over WebSockets )

Share the post

Connect to Azure IoT Hub in browser ( using AMQP over WebSockets )

×

Subscribe to Msdn Blogs | Get The Latest Information, Insights, Announcements, And News From Microsoft Experts And Developers In The Msdn Blogs.

Get updates delivered right to your inbox!

Thank you for your subscription

×