I have a Raspberry Pi 3B (Raspberry Pi 3B Arm architecture 32-bit) at home, and I have been eating dust at home, because .NET Core programs can be cross-platform, so I am going to write a website to deploy on Raspberry Pi. The home broadband has a public IP address, but the IP address will change every time the router is restarted, and the free DDNS of the ASUS router is not very easy to use (the home IP has changed, and the domain name resolution has not taken effect in time). I have a DELL desktop and a DELL EMC server at home, so get ready to write a DDNS service and Wake-on-the-Internet tool with ASP.NET Core.
With DDNS, you canGet the IP address of the Internet at home in time, using the Wake-on-Network function is possibleWake up my DELL desktop computer, which is convenient for consulting information at home.
Sites written using ASP.NET Core 6 are deployed on Raspberry PiIt has been running steadily for more than 3 months, without any problems.
Install the AspNetCore runtime
First, the Raspberry Pi needs to be installed with the Raspberry Pi OS system, and the tutorial is as follows:
Then install AspNetCore Runtimes on top of the Raspberry Pi, log in to the Raspberry Pi host using SSH, and use itsudo -iSwitch to root and create a /usr/dotnet folder with the following command:
Download aspnetcore-runtime-6.0.1-linux-arm.tar.gz and unzip it with the following command:
To create a soft link, the command is as follows:
At this point, the running environment required by ASP.NET Core website is installed, and the installed runtime is checked, as shown in the figure below:
DDNS Dynamic Domain Name Service
Call the DNSPod interface to implement DDNS dynamic domain name service, interface document:The hyperlink login is visible.
Create a new MVC project ASP.NET Core 6 using VS 2022, create a new DNSPodOptions.cs file to configure the parameters required for the invocation interface, as follows:
appsettings.json Add the following configuration:
Modify the Program.cs file to map the configuration information to the DNSPodOptions class, the code is as follows:
Create a new DDNSWorker.cs file, create a background service, obtain an IP address once a minute, and call the DNSPod interface to update the domain name resolution if the IP address changes. (Note:If more than 5 requests to modify records without any changes are submitted within 1 hour, the records will be locked by the system for 1 hour and will not be allowed to be modified again。 For example, the original record value is already 1.1.1.1, and the new request also requires it to be changed to 1.1.1.1. )
The code is as follows:
Modify the Program.cs file and register the backend service with the following code:
The complete Program.cs code is as follows:
The debugger can call the DNSPod interface normally, as follows:
Wake On LAN
Wake-on-LAN is abbreviated as WOL or WoL, which is mostly translated into Chinese as "online wake-up" and "remote wake-up" technology. WOL is a technology, and it is also the specification of this technology, and its effect is to allow a computer that has entered a dormant or shutdown state to issue orders to it through the other end of the local area network (mostly Ethernet), so that it wakes up from hibernation, resumes to operating state, or switches from shutdown state to boot state. In addition, WOL-related technologies also include remote control mechanisms such as remote shutdown and remote restart.
Modify the HomeController controller and add the Wake-on-Network interface, the code is as follows:
Edit the Index.cshtml page, add the MAC address input box and button, and use Ajax to call the interface, the code is as follows:
Start the project as shown below:
Deployed on the Raspberry Pi
Using VS 2022 to release a project, upload the release package to the Raspberry Pi's /home/pi/wol folder, as shown below:
Create a new nbddns.service file under the /etc/systemd/system folder and register the project as a Linux service, as follows:
Start the nbddns service and set the boot to start auto-start with the following command:
View the service status as shown in the following figure:
Finally, in the router settingsPort mapping, and then access through the domain name and the mapped extranet port, my phoneUse 4G networksdirectYou can access ASP.NET Core apps deployed on top of the Raspberry Pi, as shown in the figure below:
(End)
|