I have been writing about Azure IOT Hub and Raspberry Pi 4. So far, I bought a Raspberry Pi 4. I registered it as Azure IOT Edge device. Now, I am ready to write some code in Raspberry Pi. In this post, I will show you how install .NET Core 3.1 to Raspberry Pi so we can write some code to generate some data and push this data to Azure IOT Hub.
First, you need to go to the .NET Core homepage to get the latest version's url. Following page lists all .NET Core version, 3.1 was the latest when I was writing this blog. Pick the latest one from this list.
In the following page, you will see the links for .Net Core SDK and Runtime libraries. Since we want to install .Net Core to Raspberry Pi, I will pick the ARM32 Linux version from the list. You might ask, why not 64 bit? Raspberry Pi Operation system is 32 bit, Hardware can handle 64 bit but you are stuck with 32 bit unless you want to change the operation system. Also, I am happy with 32 bit because of limited resources. 64 bit applications requires more resources than 32 bit applications.
When you click on these links, browser might start to download the files. You can stop downloads; all you need is the URL of the files. To download these files, we will use the command wget. Wget is a computer program that retrieves content from web servers. Let's get the installation files first. Run the following commands to get the files. These will download the version 3.1
wget https://download.visualstudio.microsoft.com/download/pr/67766a96-eb8c-4cd2-bca4-ea63d2cc115c/7bf13840aa2ed88793b7315d5e0d74e6/dotnet-sdk-3.1.100-linux-arm.tar.gz
wget https://download.visualstudio.microsoft.com/download/pr/8c839c0e-a5ae-4254-8d8b-c012528fe601/c147e26bad68f97eacc287a71e01331d/aspnetcore-runtime-3.1.0-linux-arm.tar.gz
After getting files by wget, we are ready to extract files by running the following commands. I create a new folder named core32 and extract the files into this folder
pi@raspberrypi:~ $ mkdir core32
pi@raspberrypi:~ $ tar zxf aspnetcore-runtime-3.0.1-linux-arm.tar.gz -C $HOME/core32
pi@raspberrypi:~ $ tar zxf dotnet-sdk-3.0.101-linux-arm.tar.gz -C $HOME/core32
Next, I need to add core32 folder location to path so I can run dotnet commands from any folder.
pi@raspberrypi:~ $ export DOTNET_ROOT=$HOME/core32
pi@raspberrypi:~ $ export PATH=$PATH:$HOME/core32
All should be working now, you can run the following command to get information about the .Net Core in your Raspberry Pi.
pi@raspberrypi:~ $ dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.0.101
Commit: bc5f8df0f5
Runtime Environment:
OS Name: raspbian
OS Version: 10
OS Platform: Linux
RID: linux-arm
Base Path: /home/pi/core32/sdk/3.0.101/
Host (useful for support):
Version: 3.0.1
Commit: 32085cbc72
.NET Core SDKs installed:
3.0.101 [/home/pi/core32/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.App 3.0.1 [/home/pi/core32/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.0.1 [/home/pi/core32/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
Let's create Hello World C# console application in Raspberry Pi. In the following example, I create a new folder named hello-world. Then I go in that folder and create a new console .Net Core 3.0 C# application. Raspberry Pi is ready to run C# in .NET Core 3.0.
pi@raspberrypi:~/Desktop $ mkdir hello-world
pi@raspberrypi:~/Desktop $ cd hello-world
pi@raspberrypi:~/Desktop/hello-world $ dotnet new console
Welcome to .NET Core 3.0!
---------------------
SDK Version: 3.0.101
Telemetry
---------
The .NET Core tools collect usage data in order to help us improve your experience. The data is anonymous. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.
Read more about .NET Core CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry
----------------
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Find out what's new: https://aka.ms/dotnet-whats-new
Learn about the installed HTTPS developer cert: https://aka.ms/aspnet-core-https
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli-docs
Write your first app: https://aka.ms/first-net-core-app
--------------------------------------------------------------------------------------
Getting ready...
The template "Console Application" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on /home/pi/Desktop/hello-world/hello-world.csproj...
Restore completed in 225.92 ms for /home/pi/Desktop/hello-world/hello-world.csproj.
Restore succeeded.
Do you want to know What is new in dot net Core 3.0? Technology Crowds is always there for you. You can know What is new in dot net Core 3.0 better.
ReplyDeleteReally you have been shared very informative post. before i read this blog i didn't have any knowledge about this but now i got some knowledge. so keep on sharing such kind of an interesting blogs.
ReplyDelete.net online training hyderabad
Visit us: dot net training
Very interesting blog.Thanks for sharing.
ReplyDeleteVisit us: ui path online training
Visit us: uipath training in hyderabad
Visit us: ui path course in bangalore