Windows Azure and SignalR with Gadgeteer

I’ve been playing with Gadgeteer ( for a while now and I am a big fan of the simple way we can build embedded hardware applications with high functionality. We have a proof of concept device that includes a Colour touch screen, RFID reader and an Ethernet connections. This device is capable of connecting to a web api REST service which we have hosted in Windows Azure and we can use this service to retrieve data from our service depending upon the RFID code that is read. This works well but there are times when we would like to notify the device when something has changed. SignalR seems to be the right technology for this as it removes the need to write polling code in your application.

Gadgeteer uses the .Net Micro framework which is a cut down .Net framework and doesn’t support the ASP.NET SignalR libraries. As we can use web api using the micro framework using the WebRequest classes,  I wondered what was involved to get SignalR working on my Gadgeteer device.

The first problem was to work out the protocol used by SignalR and after a short while trawling the web for details of the protocol I gave up and got my old friend fiddler out to see what was really happening.

After creating a SignalR service I connected my working example to the signalR hub running on my local IIS..

The first thing that pleased me was that the protocol looked fairly simple. It starts with a negotiate which is used to return a token which is needed for the actual connection.

GET /signalr/negotiate?_=1369908593886

Which returns some JSON:


I used this JSON to pull out the connection id and connection token. This was the first tricky part with the .Net Micro framework. There is not the same support for JSON serialisation you get with the full framework plus the string functions are limited as well. For this I used basic string functions using Substring and IndexOf as follows:

int index = negJson.IndexOf("\""+token+"\":\""); if (index != -1) {     // Extracts the exact JSON value for then name represented by token     int startindex = index + token.Length + 4;     int endindex = negJson.IndexOf("\"", startindex);     if (endindex != -1)     {         int length = endindex - startindex;         stringToExtract = negJson.Substring(startindex, length);     } }

With the correct token received Fiddler led me to the actual connection of signalR:

GET /signalr/connect?transport=webSockets&connectionToken=yourtoken&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D&tid=2 HTTP/1.1

Looking at this I could determine that I needed to pass in the token I retrieved from negotiate, the transport type and the name of the hub I want to connect to. After a bit of investigating I used the transport of longPolling.

Now as I think I understood the protocol, I tried to implement it in SignalR. The first issue that arose was what to send with the negotiate call. I figured that this was some sort of id of the client that is trying to connect so I decided to use the current tick count. This seemed to work and I guess that as long as my devices don’t connect at exactly the same time then Signal R would work. I’ve had no problems so far with this.

Upon connecting to the hub I needed to create a separate thread to handle signalR so that the main device wouldn’t stop running whilst the connection to the SignalR hub was waiting for a response. Once a response is received the response returns with a block of JSON data appropriate to the SignalR message being received. This needs to be decoded and passed onto the application. You then need to reconnect back to the SignalR hub. The period between receiving data and then reconnecting back to the hub needs to be small. Whilst the message is being processed it cannot receive any more message and may miss some data. I retrieve the response stream and then pass the processing of the stream to a separate thread so that I can reconnect to the hub as fast as possible.

This is not a full implementation of SignalR on the .Net Micro-framework but it is the implementation of a simple client and can be used fairly successfully on the Gadgeteer device. I still need to do a little more work to try to speed up the connections as it is possible to miss some data.

The SignalR hub is hosted on a Windows Azure website along side the web api service which allows both web, Windows 8 and Gadgeteer applications to work side by side.

Gadgeteer has opened up another avenue for development and helps us to provide more variety of devices in a solution

30 Replies to “Windows Azure and SignalR with Gadgeteer”

  1. Have you done anymore with SignalR and .NET MF? I am looking at doing a similar project. I have looked at MQTT protocol which is pretty simple but I can't find a broker that will run on Azure. SignalR seems to be a good fit if I can get a client to run on .NET MF. Any advice or samples that you could pass along would be great. Thanks

  2. I have SignalR working on .Net MF but I had to build it from scratch as described in this blog post. I used HttpWebRequest and HttpWebResponse methods to do the negotiate and connect protocols. I also only used long polling. The other issue I had was that there were not any JSON helpers so I had to do it all using string manipulation. Here's an example of the code HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); if (resp.StatusCode == HttpStatusCode.OK) { Stream webstream = resp.GetResponseStream(); StreamReader reader = new StreamReader(webstream); string json = reader.ReadToEnd(); // Code here to parse the JSON // Code here to do the SignalR actions }

  3. Recreational vehicles have held an enduring fascination for many people lured in recent decades to the road, we spied a little campsite with spaces right down by the sea. Afterwards, he defended himself for his comment and said:" It was a fine enough scenario that we decided to put our infamy behind us and head off in search of surf. motorhome insurance – motorhome insurance; , [ – ] campervan insurance – campervan insurance ( – ) motorhome insurance; , motorhome insurance –

  4. My coder is trying to convince me to move to .net from PHP. I have always disliked the idea because of the costs. But he's tryiong none the less. I've been using Movable-type on a number of websites for about a year and am concerned about switching to another platform. I have heard good things about Is there a way I can transfer all my wordpress posts into it? Any help would be greatly appreciated! My webpage – Rochii –

  5. The creator thinks that the facebook marketing and twitter advertising and marketing has modified the face of the web advertising and marketing and promotion. The advertising methods of assorted companies are together with the advertising on twitter and facebook facebook advertising tactics [ ]

  6. Hello there, I discovered your site by way of Google at the same time as searching for a related topic, your site came up, it seems good. I've bookmarked it in my google bookmarks. Hello there, just became aware of your blog via Google, and located that it is really informative. I am going to be careful for brussels. I will be grateful if you happen to continue this in future. Numerous people shall be benefited from your writing. Cheers! my web site – Kaffeevollautomat Test –

  7. Hi there, just became aware of your blog through Google, and found that it's really informative. I am going to watch out for brussels. I will appreciate if you continue this in future. Lots of people will be benefited from your writing. Cheers! Stop by my homepage … website – Reva –

  8. One of the first areas to gain efficiency in is water heating. UK mail order company Bromleighs sells a huge variety of switches and faceplates to suit all tastes. If you are in search of Hello Kitty wallpaper for your computer's desktop, take a look at the five wallpapers in this guide. But things might change when the respective operating system reach retail stores. By default Calendar is selected, you will receive pop up notifications related to your calendar entries. t want to delay the closing and risk losing your commission. My webpage: windows 8 wallpapers, ,

  9. Playing to an overpacked house that spilled out across the street and he was forced to delay its hoped-for publishing date after a £3. An accessible retrofit of the Taxi and Limousine Commission, said yesterday that they had had" minor contact" with the media you don't understand how there are no motoring ­convictions on it. If they had cigars, they would cheap taxi insurance ( http://www.istosovisto.com ) have been driven to such a crime and how he chose his victims.

  10. This era also allowed web content to be created in a more open and democratic way with wiki-based sites allowing users to manage the content on the website. Through the SM Foundation, solutions to social problems for health, education and spiritual assistance have been extended to people in remote areas, by way of mobile health and dental clinics, scholarship awards, and contributions for building public schools, Catholic chapels and youth centers. Every time, more energy efficient and money-saving electrical products are hailing to the market and people are attracted towards them without knowing their basics and associated advantages. Also visit my blog … Baca selengkapnya → –

  11. We're a group of volunteers and starting a new scheme in our community. Your web site offered us with valuable information to work on. You have done a formidable job and our whole community will be thankful to you. my web blog The Renegade Diet Reviews ( Tyrell – )

  12. I have been exploring for a little bit for any high quality articles or weblog posts in this kind of area . Exploring in Yahoo I ultimately stumbled upon this web site. Studying this information So i am satisfied to convey that I've an incredibly just right uncanny feeling I discovered just what I needed. I most without a doubt will make sure to do not forget this site and give it a look regularly. Here is my web-site :: John Barban's Venus Factor Review –

  13. Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You definitely know what youre talking about, why waste your intelligence on just posting videos to your weblog when you could be giving us something enlightening to read? my web-site … Capture His Heart Reviews – http://Capture-His-Heart–– ,

  14. The Numbers Helpline has sourced 1000's of customer service contact <a href=";>Phone numbers</a> in the UK. We know how hard it can be to find those <a href=";>Phonenumbers</a> at times that why we have made a directory with them all in one place so you will never have waste long periods of time looking for a customer service contact <a href=";>Phonenumbers</a> again.

  15. The Numbers Helpline has sourced 1000's of customer service contact <a href=";>Phone numbers</a> in the UK. We know how hard it can be to find those <a href=";>Phonenumbers</a> at times that why we have made a directory with them all in one place so you will never have waste long periods of time looking for a customer service contact <a href=";>Phonenumbers</a> again.

Leave a Reply

Your email address will not be published. Required fields are marked *