How to do it...

We will use the AMQP library to implement using a AMQP protocol directly with IoT Hub:

  1. Create a C# console application and add a class amqpClient.
  2. Open the Add new NuGet packages and search for AMQPNetLite:
A Nuget package installer for AMQP
  1. Declare the global variables:
string IoThubURI = "IoTHubCookBook.azure-devices.net";int port = 5671;
  1. We will create a SendEvent method which accepts the deviceId parameter.
  1. Initialize the variables required for AMQP connection with IoT Hub:
string to = Fx.Format("/devices/{0}/messages/events", deviceId);string entity = "/messages/events";string audience = Fx.Format("{0}/devices/{1}", ...

Get Azure IoT Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.