X

Real-time talk between Windows 10 IoT Core background task and ASP.NET Core web application

My previous blog post introduced how to make ASP.NET Core 2 web application run on Windows 10 IoT Core. It was default web application created on Visual Studio and published as an executable. But this is not enough for IoT scenarios. When we build web application that runs on IoT board we need this application to do something. Be it displaying sensor data or controlling some hardware. This blog post shows how to make Windows 10 IoT background task talk with web application using WebSocket.

Problems

As my way to this solution has been troublesome I list here the main problems I faced so my dear readers have better idea about dead-end streets on this way:

  • I was not able to make ASP.NET Core web application run under Windows 10 IoT background service.
  • I found no information about when or if it will be supported in near future.
  • ASP.NET MVC and ASP.NET Core have different SignalR implementations.
  • I was not able to make SignalR client for .NET Core work with SignalR hosted on we application.

I was able to make things work using WebSocket directly. It’s not as nice solution as I had in my mind but it works until things get better.

Making background task and web application talk

I worked out simple and not very well polished solution to make Windows 10 IoT Core background task to communicate with ASP.NET Core web application hosted on Raspberry. I implemented two types of communication on same WebSocket end-point. The following image illustrates what is supported.

To make my sample more informative I also implemented some primitive functionalities to demonstrate how data moves:

  1. Windows 10 IoT Core background task reports random number to web application after every ten seconds.
  2. Web application has simple console to send commands to Windows 10 IoT Core background task. Supported commands are:
    – opsys: returns operating system information from background task
    – machine name: returns machine name where background task runs

Here is the fragment of web application front page when background service runs.

Source code and references

I made my work available at GitHub repository gpeipman/Windows10IoTWebControl.There are background service and web application. Web application must be built and then deployed to Raspberry. Here are some links to help getting started:

Please feel free to give me feedback about better solutions available.

Liked this post? Empower your friends by sharing it!

View Comments (5)

  • Have you tried following, I have tried this and it works for me.
    1. Create a UWP Class Library project and Compile ARM version. This will create the .dll.
    2. Then you can directly reference .dll inside a .Net Core .Exe Project. You can then compile the dotnet for ARM by using the runtime win10-arm from the commandline.
    3. Then you will have to copy the files manually.

    I wish .net core or uwp would support this out of the box.

  • the website didn't load after all the setup working correctly, so run the below command:
    $env:ASPNETCORE_URLS="http://0.0.0.0:5000"

    Worked like a charm!!!

  • You noted that "this solution temporary until SignalR client for ASP.NET Core is usable and works stable on Windows 10 IoT Core." It has been over a year since you published this excellent example, do you have any insight as to if the SignalR may have evolved to be stable on Windows 10 core?

    Thanks in advance!

  • I just have to make a new experiment to find it out. Hope to find time for this over coming weeks.

Related Post