A first experience with Windows IoT Core

NOVEMBER 2, 2015 // By Eric Anderson

Over the past few years a new trend has been the emergence of small single board computers that serve as the basis for electronics projects ranging from the hacker space all the way up to the commercial sphere. One of the most popular boards for these purposes are the Arduino boards which contain a micro-controller, small amounts of random access memory and headers to be used as electronics interfaces. As the years have gone on, prices have come down and more powerful single board computers have become available in the consumer price range. One of these boards is called the Rasberry PI. While there are certainly other boards of comparable capabilities to the PI, this one has seemingly become the most popular.

In my personal opinion, what really sets these moderately powerful boards apart is the ability to run full operating systems on them and use them for functions that are typically not associated with electronics. Examples include PLEX media servers, file servers, web servers, amateur weather balloons, etc. Up until recently the only option for running an operating system on one of these boards was a Linux flavor. With the release of Windows 10, Microsoft has now released a POSIX based operating system called Windows IoT. Presently this is able to run on the Rasberry PI and the MinnowBoard Max. This brings the capability of running applications developed using Visual Studio via universal applications.

The following is a very simple guide for deploying a Windows IoT core application that runs on a Rasberry PI and talks via WCF using NetTcpBinding to another computer. I was originally hoping to develop a sample application in which the PI acts as a server using WCF but I found out that the API's presently do not include ServiceHost capability.

The Rasberry PI package I chose to purchase is the CanaKit presently available from Amazon for $69.99. The package includes the following components:

Per description from Amazon.com:

  • Includes New Raspberry Pi 2 (RPi2) Model B Quad-Core 900 MHz 1 GB RAM
  • 8 GB Micro SD Card (Class 10) - Raspberry Pi Recommended Micro SD Card pre-loaded with NOOBS
  • CanaKit WiFi Adapter 150 Mbps - Supports Access Point Mode (AP) to allow for WiFi Hotspot hosting
  • CanaKit 2.5A USB Power Supply with Micro USB Cable and Noise Filter - Specially designed for the Raspberry Pi 2 (UL Listed)
  • High Quality Raspberry Pi 2 Case, Premium Quality HDMI Cable, Heat Sink, GPIO Quick Reference Card, CanaKit Full Color Quick-Start Guide

I specifically chose this kit because of the included WiFi adapter. Unfortunately the default implementation of Windows IoT does not recognize this specific WiFi adapter.

Assembly took approximately 10 minutes. For installing Windows IoT core I followed the directions located at https://ms-iot.github.io/content/en-US/win10/SetupRPI.htm. Setup was extremely simple and Windows IoT loaded with no problems with the exception of the failure to recognize WiFi adapter.

Once that was complete I followed the directions located at https://ms-iot.github.io/content/en-US/win10/samples/HelloWorld.htm while adding my own code for the WCF communications. The layout of the code is as follows:

I have a contracts project that is serving as a housing container for my WCF contracts. This project is referenced by the server side console application as well as the Windows Universal IoT client side application. The project is a portable class library targeting .Net Framework 4 and Windows 8. The contract is a straight forward contract and looks like the following:

using System.ServiceModel;

namespace IoTWcfTest.Contracts
{
    [ServiceContract]
    public interface IService
    {
        [OperationContract]
        void SendMessage(string message);
    }
}

The service is hosted in a .NET 4.5 console application and looks like the following:

using IoTWcfTest.Contracts;
using System;

namespace IoTWcfTest
{
    public class Service : IService
    {
        public void SendMessage(string message)
        {
            Console.WriteLine("Message is {0} received at {1}", message, DateTime.Now);
        }
    }
}


using IoTWcfTest.Contracts;
using System;
using System.ServiceModel;

namespace IoTWcfTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var serviceHost = new ServiceHost(typeof(Service));

            serviceHost.Opening += ServiceHost_Opening;
            serviceHost.Opened += ServiceHost_Opened;
            serviceHost.Closing += ServiceHost_Closing;
            serviceHost.Closed += ServiceHost_Closed;

            var tcpBinding = new NetTcpBinding();
            tcpBinding.TransactionFlow = false;
            tcpBinding.Security.Transport.ProtectionLevel =
               System.Net.Security.ProtectionLevel.None;
            tcpBinding.Security.Transport.ClientCredentialType =
               TcpClientCredentialType.Windows;
            tcpBinding.Security.Mode = SecurityMode.None;

            serviceHost.AddServiceEndpoint(typeof(IService), tcpBinding, URLs.URL);

            serviceHost.Open();

            Console.WriteLine("Host is open. Hit enter to close");

            Console.ReadLine();

            serviceHost.Close();
        }

        private static void ServiceHost_Closed(object sender, EventArgs e)
        {
            Console.WriteLine("Closed");
        }

        private static void ServiceHost_Closing(object sender, EventArgs e)
        {
            Console.WriteLine("Closing");
        }

        private static void ServiceHost_Opened(object sender, EventArgs e)
        {
            Console.WriteLine("Opened");
        }

        private static void ServiceHost_Opening(object sender, EventArgs e)
        {
            Console.WriteLine("Opening");
        }
    }
}

Notice that instead of using a more typical BasicHttpBinding, I used a NetTcpBinding. I used it simply because I like it and I was curious if I could use it in Windows IoT. As you can see from the code below, it is possible. The Windows IoT client side code looks like the following:

<Page x:Class="IotClient.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:IotClient"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <TextBlock FontSize="16">Hello World</TextBlock>

        <Button Grid.Row="1"
                x:Name="btnClick"
                Click="btnClick_Click">Connect</Button>
    </Grid>
</Page>


using IoTWcfTest.Contracts;
using System;
using System.ServiceModel;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace IotClient
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

        private void btnClick_Click(object sender, RoutedEventArgs e)
        {
            SendMessage();
        }

        private void SendMessage()
        {
            var tcpBinding = new NetTcpBinding();
            tcpBinding.Security.Transport.ClientCredentialType =
              TcpClientCredentialType.Windows;
            tcpBinding.Security.Mode = SecurityMode.None;

            var endpointAddress =
                   new EndpointAddress(URLs.URL);

            var channelFactory = new ChannelFactory<IService>(tcpBinding, endpointAddress);
            var proxy = channelFactory.CreateChannel();

            proxy.SendMessage(string.Format("{0}", Guid.NewGuid()));

            using (proxy as IDisposable)
            {

            }
        }
    }
}

While extremely simplistic the coding example above is working and it gave me a good start with developing Windows IoT Core applications in C# and XAML. It is interesting to note that deployment of this code example did take several seconds each time. The purpose of this project was simply to introduce myself to the new abilities Microsoft has created for deploying code to IoT devices. Some of the pros that I see from this are as follows:

  1. I am able to deploy code written in C# using Visual Studio 2015. Being a .NET developer this is a significant win for me.
  2. The Windows IoT Core platform is relatively simple to install.
  3. Remote management as described at https://www.hackster.io/windowsiot/powershell-to-connect-to-a-machine-running-windows-10-16a479 seems to work extremely well. This is functionality that I've longed for since college when I was working with SSH and Linux. According to https://ms-iot.github.io/content/en-US/win10/samples/SSH.htm, I should be able to SSH to my device as well, although I haven't tried that yet.

 Some of the cons I see are as follows:

  1. Compared to Rasbian, it seems like Windows IoT is extremely simplistic. This is probably fine in instances in which the device is being used as an electronics interface.
  2. Right now Windows IoT only supports a small number of one WiFi device for the Rasberry PI and five WiFi devices for the MinnowBoard Max. These are listed here: https://ms-iot.github.io/content/en-US/win10/SetupWiFi.htm
  3. Rasbian has a very rich community. Right now this appears to not be the case for Windows IoT. That may yet change.

If you’d like to contact Magenic directly, email us or call us at 877-277-1044.

Categories // Custom Application Development
Tags // IoT, Windows10, RaspberryPI, C#

Get Started

Contact Us