First experience with Win10 IoT and UWP on Rasberry Pi 2

For Christmas I got a “Rasberry Pi 2 B” which is also supported by Windows 10 IoT core. I wanted to replace my old Windows server in my heating room, which monitors my heating unit, with this Rasberry Pi ๐Ÿ˜‰

The project

  1. I have a heating unit which has a serial port (or better OptoLink-Adapter) for reading data and also setting some values. Currently I use an “old” server which is placed beside my heating unit and is connected via USB to the heating unit.
  2. On the same server, I also monitor the “state” of our network TV. It just logs the online-time into a file ๐Ÿ˜‰ so I can see how long the TV is on… this is simply done by sending a query to the HTTP port; if the TV responds, it is ON, if not it is OFF ๐Ÿ˜‰

The programs are currently written in C# (VS2010).
Win10Iot_01

The goal

  • The goal was to remove this server from my heating room and replace it with my Raberry Pi 2 B ๐Ÿ˜‰

The project can be found on GitHub: https://github.com/JochenKalmbach/Win10IoT

The experience

The installation was very simple.

Now I tried to develop some applications with C#. I used the “easiest” way, by doing this with Visual Studio 2015 Update 1 and a “Universal App” (UWP)

Here are some experience with this programming model and Win IoT Core:

  • Everything should be “async” and using “await”. The whole classes are build for this programming model. If you get used to it, it is also a very good way of doing it… the main reason for this seems to be “battery lifetime” ๐Ÿ˜‰
  • If you want to return Task / Task the compiler always complained, that this return type is not compatible with the Windows Runtime… (error WME1038: Method 'xyz' has a parameter of type 'System.Threading.Tasks.Task' in its signature. Although this type is not a valid Windows Runtime type, it implements interfaces that are valid Windows Runtime types. Consider changing the method signature to use one of the following types instead: ''.) I searched a couple of minutes to find out, that this is really the case… but this is only a restriction, if you want to expose your classes to other programs. So after making the method/class “internal” everything was ok ๐Ÿ˜‰
  • I had some code which uses the XmlSerializer. I moved it to the UWP App which was very easy (besides of the StorageFolder/StorageFile classes which must be used to access folders/files). But after I tested the deserialization (to read my configuration data), I was not able to read my list of entries… after a hour I found out, that the XmlSerializer has one limitation in UWP apps (or maybe only in IoT core): It has no supported for “Lists” ;( This means that it is not usable for UWP Apps. If you take a deeper look, you see that the “normal” XmlSerializer is supporting “IEnumerable”, even if it is not possible to add entries to it… this is done by calling a named function “Add(T)”; maybe this is the reason, that it is not supported in IoT core ๐Ÿ˜‰
  • Ok, XmlSerializer is not the only solution for serializing data… here is a good overview for UWP app: Choosing the right serialization engine for your Windows Store app
  • After moving to “DataContractSerializer”, which is almost the same as “XmlSerializer”, I again run into problems… it now supports “lists” but now I need to specify a namespace and also need to put the elements into a specific order (alphabetical). If the elements are not in this order, then it cannot be read… also it does not support XML attributes… but Ok, it worked… one simple XML configuration I moved to this new “DataContractSerializer”.
  • A second part of the program uses also some configuration files. I now switches immediately to the “DataContractJsonSerializer” (JSON) (I didn’t want to add a new dependency to my project). I thought this would be easier… ok, I found out, it isnยดt…. the serialization and deserialization (data format) is easier, because I do not need to put a special namespace or special ordering. But I was not able to deserialize the json file I have created… after several minutes I found out, that the UTF8-BOM was the problem…. this is either a bug or a feature… I have not found an easy way to specify a proper encoding or detect the encoding automatically, like in normal .NET StreamReader. It always assumes to have UTF-8 without BOM. After removing the BOM, the JSON file could also be read…
  • Debugging: I was not able to debug “out of a function”. If I pressed “F10” and the end of the function, Visual Studio was not able to step to the next instruction, instead it seems to hang-up the application… hopefully this will be fixed…
  • SerialDevice: It seems that the method “FlushAsync” is not implemented… at least it throws this exception ๐Ÿ˜‰ maybe we do not need it…
  • SerialDevice: I am missing a function like “DiscardInBuffer”; as a work around, I open and close the port each time, which has the same effect… but it seems that after about 100 open/close, the port hangs… so the function of discarding the input buffer is really missing… I implemented it by my own, so I now read until the ReadTimeout is reached…
  • WebServer: I wanted to add a web-server in my application… but it seems that there is no implemented base-class for doing this… of course, I could move to ASP.NET5 and CoreCLR, but I had not yet the time to do this… but this is also supported on Win 10 IoT ๐Ÿ˜‰

The conclusion

It took me about two days, to migrate my two projects to Windows 10 IoT core. I had several problems, I didn’t expect.
But now, it is running like expected and it replaced my old server in the heating room ๐Ÿ˜‰
Win10IoT_02

The project can be found on GitHub: https://github.com/JochenKalmbach/Win10IoT

Next steps

  • The name “IoT” needs to be expressed in an additional project: Publish my heating unit data (Asset) into an IoT hub (like Amazon IoT Hub, Azure-IoT-Suite, …) by using MQTT or AMQP… the best would be to host in on my Docker-System on my QNAP/Synologie NAS ๐Ÿ˜‰
  • Because I am running the Win 10 IoT in the “headless” mode, I wanted to add some ETW provider for my application… I was not yet able to add this provider, so I can diagnose it via the web interface. This needs to be done.
  • I want to add an own web server to my application… therefor I will try to migrate my new application to CoreCLR ๐Ÿ˜‰

Leave a Reply

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

Captcha *