Fun times with SignalR Part 2: Windows Store and Lego Mindstorms
- Chris Wallace
- Thu Jan 07 2016
The beauty of SignalR is the platform support, most of the libraries are portable and can be used across Console Applications, WPF, Windows Forms and Windows Store Apps (which opens up a lot of opportunities thanks to Windows 10). So the next part of my project was to port part of the code over to a Windows Store App.
The app itself is fairly simple (and not that different from a WPF solution). There's a simple Xaml listview with some connect buttons and text fields. This allows me to connect to a specific 'context' (i.e. a chatroom or a 'channel'), give myself a name and join as a 'Finster' user (remember Finsters can send/receive all messages/events to/from all clients aka 'Randalls').
The underlying SignalR code isn't that different from a console application, the handling and sending is just refactored into more ideal places (and has to deal with async because of the UI layer).
So I have a (slightly) nicer looking UI to view events. So what? Well, the next part is the real reason I wanted to do this!
A couple of years ago, Santa sent me a lego Mindstorms EV3 robotics kit for Christmas (if you see where I'm going with this, you might as well scroll to the end!) Unlike previous versions, the latest version of the lego Mindstorms brick has Wifi support and (more importantly) class libraries for use with .NET!
The libraries for the EV3 were a few years old now and intended for the original WinRT, but still work perfectly fine with 'file -> new' Windows 10 apps. The libraries themselves allow you to talk to your creation either using the built-in Bluetooth connection or over a LAN Wifi connection (if you plug in a supported USB WiFi dongle).
Again using little extra code I was able to establish a connection with my Lego Robot (sadly on the shelf gathering dust) and get it moving around the floor. After a few attempts at controlling the motors (and working out how to stop them!) I had a little dancing robot!
The final part was to hook up the integration between the SignalR messages/events and the EV3 brick. Here are the results!
So what's happening?
Nothing that different from my console application really:
- A user visits a page on the site (either entering the address directly or clicking a link)
- The Windows Store App logs the message/event to a listview
- The Windows Store App tells the connected EV3 brick to run the leg motors on the robot for 6 seconds at 100%/-100% power (making it spin).
And that's it! Again just a fun example of integrating different devices altogether. There's still more devices I want to explore with this SignalR project but it depends on how many other SignalR clients libraries I can find out in the wild!