Building an IoT and Azure demo - Part 11: Using AMQP from the Raspberry Pi

 (Jump to part 1)

There are two ways to send data to an Azure Event Hub: HTTPS and AMQP.  Advanced Message Queuing Protocol is an international standard protocol that sends the data in binary format and is very efficient.  So far, my demo code used HTTPS to send the telemetry data.  Why not use AMQP?  Well, I would need using the Azure Service Bus API library that supports AMQP but it is not compatible with PCL and Universal Windows Apps.  Stuck?  Of course not, thanks to Twitter!

Paolo Patierno, a Microsoft MVP on Windows Embedded & IoT, saw one of my tweets and asked me if I used Azure SB Lite:

Paolo wrote Azure SB Lite to facilitate sending messages using AMQP to Azure Event Hub on the .NET Micro Framework, .NET Compact Framework, Mono (on Linux) and WinRT,  It's a wrapper on AMQP.Net Lite, a lightweight AMQP 1.0 client library.  Sweet!  

As Paolo suggests, let's try using it in my Xamarin.Forms project.  Well, it didn't worked because of an issue with System.Net.Sockets in AMQP.Net Lite.  Clearly, it's not PCL compatible.  Bummer but how about my Universal Windows App running on the Pi?

I added the Azure SB Lite package, and started adding code to support both HTTPS and AMQP by adding a Toggle Switch on the UI so that I can select either protocols during the demo.

Install-Package AzureSBLite

Sending data using HTTPS requires the use of a shared access signature while AMQP requires the use of a connection string.  Retrieving it is easy, simply select the event hub in the Azure portal and locate the Connection Information button at the bottom of the screen.


 This will display the connection strings.  I grabbed the one for my SendRule.

And added a new method to my Web API controller so I can return the connection string to the client from the Web server instead of hardcoding it:

public string GetConnectionString(string id)
	if (!IsDeviceActive(id))
		throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized));

	string connectionString =
	return connectionString;

I modified the client code a little bit to handle both protocols.  Here's the modified portion of the buttonStart_Click event initializing the Azure SB Lite objects:

private MessagingFactory _factory;
private EventHubClient _client;
private EventHubSender _sender;

if (AmqpSwitch.IsOn)
	_connectionString = await _svc.GetConnectionString(_id);
	TextBlockSas.Text = _connectionString;

	ServiceBusConnectionStringBuilder builder = new ServiceBusConnectionStringBuilder(_connectionString);
	builder.TransportType = TransportType.Amqp;
	_factory = MessagingFactory.CreateFromConnectionString(_connectionString);
	_client = _factory.CreateEventHubClient("iotdemo");
	_sender = _client.CreateSender(_id);
	_sas = await _svc.GetSas(_id);
	TextBlockSas.Text = _sas;

Sending the data only takes a couple of lines.  Note however that the Send method is not asynchronous.

public void EventHubSendToPublisher(Telemetry telemetry)
	if (_sender == null) return;

	var payloadJson = JsonConvert.SerializeObject(telemetry);

	EventData data = new EventData(Encoding.UTF8.GetBytes(payloadJson));
	data.Properties["time"] = DateTime.UtcNow;


 Voilà!  Telemetry sent to the Azure Event Hub using the AMQP protocol thanks to Paolo Patierno's Azure SB Lite library.  Thanks Paolo!

Shortcut keys for Windows 10

Looking for a list of all the Windows 10 shortcut keys?  Microsoft has created a Word document listing them all.

Azure SDK 2.7: Visual Studio toolbox enhancements

The newest version of the Azure SDK offers a bunch of very cool enhancements to the Visual Studio toolbox.  Watch this Channel 9 video to learn all about the new and shinny Cloud Explorer:

Direct link

Lost JavaScript support in VS2015 after updating TypeScript

I've been hit by an install bug after updating to the latest TypeScript breaking JavaScript in Visual Studio.  Select Tools/Options/Text Editor and JavaScript is nowhere to be found!


Good thing I saw Bill Wagner's post on Facebook.  He was hit with the same issue and found a solution:

  1. Launch the Visual Studio Installer
  2. Click on Modify
  3. Deselect and select again (yes, I know) the Universal Windows App Development Tools and click on Update

The JavaScript support should come back.

However, I still had an issue, this time with the JavaScriptWebExtensionsPackage

A quick search on the InterTubes led me to this solution:

  1. Close Visual Studio Open the Users\<CurrentUser>\AppData\Local\Microsoft\VisualStudio\<version>\ folder
  2. Rename or delete the ComponentModelCache folder
  3. Restart Visual Studio

Oh well!

Nugot: a better Nuget front end?

Nugot is a Website created by Richard Astbury that acts as a better front end to Nuget by providing more information.  Let's take a look at Json.NET on both sites.  First

And next,

I highlighted a few interesting features:

  1. Github readme file
  2. Package information
  3. Stats
  4. Github information
  5. Packages dependent on this one
  6. Dependencies on other packages
  7. A Disqus discussion board
Pretty cool if you ask me.  Note that the site in currently in Alpha.

Mark your calendar for AzureCon

Microsoft announced that the next AzureCon will take place on September 29, 2015.  AzureCon is a free online event with tons of Azure content:

  • Live keynotes delivered by Scott Guthrie, Jason Zander, Bill Staples, and other executives.
  • Interactive Q&As with keynote speakers, technical leaders, and partners.
  • Technical lap-around sessions presented by Mark Russinovich, Scott Hanselman, and other technical leaders.
  • More than 50 on-demand deep-dive technical sessions

Register here

We're trying to organize a viewing party at the Microsoft office here in Montreal...stay tuned!

Free Xamarin Subscriptions for Windows Phone Developers

This is a nice (and limited, expires August 31st, 2015) offer to all Windows Phone developers: get Xamarin community-supported subscriptions of Xamarin.iOS and Xamarin.Android, including our Visual Studio extensions, for personal use. for free!


Read the announcement here

Free virtual machines with Microsoft Edge

Yep, there's a new browser in town and already, it has an installed base of more than 50 million.  That's Microsoft Edge found in Windows 10.  If you're doing Web development and haven't installed Windows 10 yet, Microsoft provides free Windows 10 virtual machines for testing Edge.  Just select your OS, the VM and the platform.


Read the announcement from the Edge team.

Visual Studio Talk Show: Le futur de l'intelligence artificielle

Lors de la dernière visite de Mario à San Francisco, il a profité de l’opportunité pour rencontrer Gregory Renard chez lui dans la Silicon Valley et discuter du futur de l’intelligence artificielle. Pour cette entrevue impromptue autour d’un bon repas et de quelques bonnes bouteilles de vin, Erik Renaud a remplacé Guy Barrette dans le rôle de co-animateur.

Gregory Renard Grégory Renard, mieux connu sous le pseudo de Rédo, est un entrepreneur en série « geek », un architecte logiciel et un visionnaire technologique. Co-Fondateur de xBrain, sa nouvelle startup propose une plateforme de reconnaissance vocale, notamment adaptée à l'automobile, qui prend en charge les communications naturelles. Spécialiste de l’intelligence artificielle, Gregory est passionné par un monde connecté où il espère que l'accès universel à l'information et la connaissance pourra libérer les gens et leur permettre de réaliser leur plein potentiel. Suivez-le sur son blog.

Windows Core IoT and Raspberry Pi 2 keyboard

I had a Logitech K400 keyboard gathering dust in a corner so I tried it on my Raspberry Pi 2 running Windows Core IoT and yes, it's working fine, no drivers needed.  Sweet!

Page List

Month List