.NET Core on Raspberry Pi

Introduction

All .NET editions of /n software toolkits include libraries compiled for .NET Standard 1.4 and up. This article focuses on using the HTTP component from the IPWorks toolkit on a Raspberry Pi 3 running Raspbian Stretch.

For more information about .NET Core/.NET Standard support in /n software products, be sure to check out our Getting Started with .NET Core and .NET Standard article.

Installing the .NET Core Runtime on the Raspberry Pi

At the time this article is being written, only the .NET Core runtime is available on 32-bit ARM platforms. Since 32-bit ARM SDK builds aren't available, you'll need to use another machine to actually create and publish the .NET Core project. Please refer to this page on the .NET Core GitHub repo for the most up-to-date information.

To install the .NET Core Runtime on the Raspberry Pi, follow the instructions from Step 3 onwards in this MSDN blog post.

Code

After getting a new .NET Core console application project set up on your development machine, and adding the IPWorks library to it, you should be able to copy the following code to the auto-generated Program.cs file.

You'll need to supply your own value for http.RuntimeLicense in order for the program to run successfully after you transfer it to your Raspberry Pi. Refer to the Getting Started with .NET Core and .NET Standard article for information about how to do this. You may also need to change the namespace.

using nsoftware.IPWorks; using System; using System.IO; namespace DotNetCoreTest { class Program { static int percentage = 0; static void Main(string[] args) { Http http = new Http(); http.RuntimeLicense = ""; // Put your RuntimeLicense value here! http.OnConnected += (s, e) => Console.WriteLine($"Connected {e.Description}-{e.StatusCode}"); http.OnDisconnected += (s, e) => Console.WriteLine($"Disconnected {e.Description}-{e.StatusCode}"); http.OnStartTransfer += (s, e) => Console.WriteLine($"Start Transfer {e.Direction}"); http.OnEndTransfer += (s, e) => Console.WriteLine($"End Transfer {e.Direction}"); http.OnTransfer += (s, e) => { if (e.PercentDone % 5 == 0) { if (e.PercentDone != percentage) Console.WriteLine($"On Transfer {e.PercentDone}%-{e.BytesTransferred}"); percentage = e.PercentDone; } }; http.OnHeader += (s, e) => Console.WriteLine($"Header {e.Field}: {e.Value}"); http.OnConnectionStatus += (s, e) => Console.WriteLine($"Connection Status {e.StatusCode}-{e.Description}-{e.ConnectionEvent}"); Console.WriteLine("Start? Press enter"); Console.ReadLine(); http.LocalFile = Path.Combine(AppContext.BaseDirectory, "dotnet.tar.gz"); http.Get("https://dotnetcli.blob.core.windows.net/dotnet/Runtime/release/2.0.0/dotnet-runtime-latest-linux-arm.tar.gz"); Console.WriteLine("Done! (press enter to exit)"); Console.ReadLine(); } } }

The program is quite simple, it just downloads a file and shows various messages as the download progresses. After building the project, you should publish it using the "Folder Profile" (Build > Publish...). Make a note of the "Target Location" in the "Publish" pane that comes up, because you'll need to copy that whole folder to your Raspberry Pi using your method of choice after publishing.

Running the Code on the Raspberry Pi

After you've copied the whole published folder to your Raspberry Pi, you should be able to navigate to it in a terminal and run dotnet DotNetCoreTest.dll (replacing "DotNetCoreTest" with your project name), and that's it! Below shows what the output should look like:

DotNetCoreTest code running on Raspberry Pi.

We appreciate your feedback.  If you have any questions, comments, or suggestions about this article please contact our support team at kb@nsoftware.com.