I have never understood why this article was not approved. I hope it can be approved after modification, right

Just entered the job two days ago, in recent days busy rent a house to move, busy a few days finally is to live in their own hut, as a software engineer, how can not have a home server? There are many kinds of solutions, ranging from NAS costing thousands of yuan to obsolete old computers. However, old computers are noisy and consume high power, and the price of NAS at 3,000 or 4,000 yuan is really difficult for me, a recent college graduate, so I set my eyes on another gadget — raspberry PI.

The reason why I choose raspberries pie is also very simple, first is cheap, the second is access to the data very much, basically in the process of using after you problem has a solution on the network, so this article not introduce how to use raspberry pie, how burning system, these things are too many people have written, I write is nothing to cross, therefore the content I am one has brought, This article is my own home server solution, more is to provide a direction of guidance, if you think my article is helpful to you, welcome to pay attention to support oh ~

What is raspberry pie?

Type “Raspberry PI” into any search engine and you’ll get a lot of results. Essentially, the Raspberry PI is a small computer, the size of a credit card, with all the basic functions of a computer. Unlike your typical PC, the PI doesn’t have a screen, keyboard or mouse, but it does have a network port, USB port and video outlet.

Of course, one big difference between PI and mainstream PC is its chip. Unlike mainstream x86 desktop PC, PI uses low-power ARM chip, so its performance is still a little behind that of conventional PC. However, with the continuous development of ARM chip in recent years, Its performance is already comparable to that of traditional x86 processors, and in some cases far ahead, such as Apple’s M1 chip. Here I recommend reading two articles I wrote earlier πŸ‘‰ M1 beating Intel – x86 vs. ARM love hate and M1 Beating Intel – What’s the difference this time

Fortunately, during my years at school, I had some unused keyboards, mice and removable hard drives that I didn’t have time to sell, so I decided to use raspberry PI as my home server.

Raspberry pie of choice

Go to an e-commerce site and search for raspberry Pie.

It’s actually pretty easy to choose. There are many different types of raspberry PI, but it’s broken down into just three categories:

  1. Model B series: flagship version, full interface, strong performance
  2. Model A series: youth version, small shape, general performance, configuration and interface slightly castrated
  3. Zero series: Mini version, with a super small body, weak performance

At present, raspberry PI has developed into the fourth generation. If money is not very tight, I recommend buying Raspberry PI version 4B. The official website introduces raspberry PI as follows:

With a processor that’s much more powerful than its predecessor and supports up to 8 gigabytes of memory, 4K video output, and usB-C power, it’s perfectly capable of being used as a desktop computer, more than enough to be used as a home server.

Operating System Selection

After the hardware of the Raspberry PI, how can you leave the software? Another advantage of Raspberry Pi is that you can choose the operating system to burn compared to traditional computers. The official recommended Raspberry Pi OS is Raspberry Pi OS. There are too many tutorials online for system burning, so I recommend using the official software “Raspberry Pi Imager” directly. As you can see from the following figure is a very easy to use software.

The SD card of 16GB is ok, and it is also ok if the capacity is large, and the reading and writing speed is naturally as fast as possible. The system I burned here is officially recommended Raspberry Pi OS, which has optimized performance for Raspberry Pi. As it is an operating system developed based on Debian, Those of you who use Ubuntu a lot will have a little less difficulty getting started.

Of course, you can also choose to burn other operating systems, such as Ubuntu, Manjaro, Android, etc. Some people have even managed to burn Windows11 recently, which is linked here. Read πŸ‘‰How to Install Windows 11 on a Raspberry Pi 4

Home raspberry PI scheme points north

Having said the choice of raspberry PI hardware and software, we can finally get to the point of this article.

There are many ways to control raspberry PI. There are many ways to control robots and external light bulbs on the Internet. To be honest, these ways have more educational significance than practical significance.

One of the reasons for not using an old PC as a home server in the first place was power consumption. An online test of the Raspberry PI’s 4B power consumption: 2.7W when idle and 6.4W when loaded. According to the price of 0.7 yuan for one kilowatt hour of electricity at home, the electricity price for 24 hours of high load operation 365 days a year is only 6.4Γ—24Γ—365Γ·1000Γ—0.7=39.2448 yuan.

Therefore, raspberry PI is suitable for some services that are suitable for being online 24 hours a day. Mine are:

  1. Offline download (Aria2, QbitTorrent)
  2. Mi, HomeKit and other smart home relay control
  3. LAN File sharing (Samba)
  4. Linux Server (Docker)
  5. Home Dashboard Central Control Panel (Flutter Web)

I will introduce them one by one.

Connect raspberry PI – Connectivity test

The first step to using a Raspberry PI is to connect to a Raspberry PI. There are many ways to connect to a Raspberry PI, including directly to a keyboard, mouse, monitor, or SSH/VNC/FTP, whichever way you can connect to the Internet. For convenience, you are advised to connect the monitor first and then enable SSH and VNC services. There are many detailed tutorials on the web that I won’t repeat here.

This section focuses on one of the key but neglected aspects of the network connectivity test between the Raspberry PI and the PC.

One of the most important features of LAN file sharing and offline downloading is that the transfer speed between the work PC and the Raspberry PI is fast. Otherwise, it would take me a long time to download the files offline and then transfer them to my computer.

Since most of the work computer and raspberry PI are connected via Wi-Fi rather than network cables in this tutorial, it is necessary to do a test of their network speed at the beginning. Here I recommend “iPerf3”, which is easy to install and use.

We need to install iPerf3 using APT on raspberry PI and then start the service of iPerf3.

# installation iPerf3
sudo apt install iperf3

# Start iPerf3 service
iperf3 -p 3005 -s
Copy the code
  • -pSet the listening port number. The client needs to use this port to communicate with the server.
  • -sSet to run in service mode.

Then iPerf3 can be installed on the work computer as well. Brew Install iPerf3 can be installed on the MAC directly, and then we just need to execute the following command.

# Test the Internet speed between Mac and Raspberry PI (my raspberry PI Intranet IP is 192.168.31.189)Iperf3 -c 192.168.31.189 -P 3005Copy the code

My test results are as follows:

Conversion, upload and download about 7MB/s speed, although the speed is not very fast, but the basic can be used.

PS: If your connection is a little slow after the test, check to see if your raspberry PI is connected to 5GHz Wi-Fi.

After confirming that the connection speed is working properly, we can install and use a very important tool – Docker.

Use Docker to empower raspberry PI

The existence of Docker enables developers to quickly build the development environment they need. They only need to specify the image to quickly generate the required container environment. In addition, because Raspberry PI uses chips of ARM architecture, many common software need to be compiled if they want to be installed and used normally, which is undoubtedly a burden for raspberry PI with poor performance. In order to let us focus on the actual development, rather than entangled with the problems of application running environment, This time, we use Docker to build the required development environment and enable raspberry PI.

For those who are not familiar with Docker, go to πŸ‘‰yeasy.gitbook. IO /docker_prac…

Docker installation on Raspberry PI and configuration of image acceleration have been given in the above links. It is worth mentioning that Docker Compose needs to be used if we want to fix the operation mode and configuration of multiple containers and apply it to container layout.

For example, we have an application container that needs mysql to store data, Nginx to forward data, and message queues to transform data. Before each startup, we need to start each container first, and then run the application container, which is itself a repetitive action. In addition, different configurations are required for each container during startup. Therefore, Docker Compose comes into being in order to realize the combination management of multiple containers, such as specifying the container startup sequence and specifying the configuration content.

Docker Compose can be installed in many ways, but due to the limitations of the ARM architecture, Docker Compose on raspberry PI recommends PIP installation.

sudo pip3 install -U docker-compose
Copy the code

!!!!!!!!! It must be Python3 PIP, so it is recommended to use PIP3 directly

Supervise your Docker — Portainer

Portainer is Docker’s lightweight, cross-platform and open source management UI. You can manage your Docker containers, images, networks, and volumes via WebUI. His installation is also very simple, directly execute the following command.

docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
Copy the code

After the installation is complete, the following figure shows πŸ‘‡

Monitoring panel — Pi Dashboard

With Docker, we can easily and quickly install various software. To make it easy to monitor our Raspberry Pi, one of the first is the Pi Dashboard.

The installation is as simple as executing the following one-line command πŸ‘‡

sudo docker run -d --name docker-pi-dashboard -e 'LISTEN=1024' --net=host ecat/docker-pi-dashboard
Copy the code

It can pass after starting

sudo docker ps | grep docker-pi-dashboard
Copy the code

To confirm whether our container is successfully started. If it is successfully started, enter < your IP address >:1024 in the browser to access the PI Dashboard. As shown in the following figure πŸ‘‡

Smart home — Home Sistant

Smart home is one of the hottest fields at present. Xiaomi, Apple and Huawei are all in this field, and their Mi Home and HomeKit have provided very perfect services. So why do we build a smart home system on raspberry PI?

In fact, the reason is very simple, although there are many smart home products, but there is not yet a smart home solution to meet the characteristics of multiple types of equipment, good interactive experience and low cost, so in many cases we will choose some products of a certain company, This can lead to a mess of Xiaomi lamps, Huawei sensors, Apple speakers and other things in your home, and then you have to install multiple apps, which is definitely a very bad experience.

There is a saying in computing that all compatibility problems can be solved by adding a layer of abstraction, and all performance problems can be solved by removing a layer of abstraction. In this case, why not pull out another layer on top of these smart home platforms to provide a unified control entrance?

The answer, of course, is yes, and someone has already made the solution open source, which is HomeAssistant in this section.

Both Mijia and HomeKit can only be used in their respective ecosystems. Mijia only has mobile apps. Although HomeKit covers tablets, phones, computers, watches, etc., it is also limited to Apple’s ecosystem. (The Internet has developed for so many years, but it has forgotten its original form. I don’t know whether it is progress or a tragedy.)

Having said that, getting back to business, the installation and use of HomeAssistant is very simple, and the website has been written in great detail πŸ‘‰www.home-assistant.io/installatio…

Docker Compose installation is recommended.

version: "3"
services:
  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/raspberrypi4-homeassistant:stable"
    volumes:
      - /PATH_TO_YOUR_CONFIG:/config
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    privileged: true
    network_mode: host
Copy the code

Specify the path to volumes and run the docker-compose up -d command.

Access to the Mi family

Once installed, your home should be empty. If you want to bind MIoT devices, you can access MIoT plugin, document πŸ‘‰github.com/al-one/hass…

After filling in your Mi account and password, you can view and use your MI device in HomeAssistant on the web page, so as to achieve the purpose of cross-platform. Below is my own configuration of the control page πŸ‘‡

Open Capabilities — REST APIS

Providing only a web page for control is essentially optimizing the interactive experience and not worth a separate section. As an open source product, the biggest advantage of HomeAssistant is that it provides an open ability for each user to change Settings according to their own ideas. We can fully customize according to the REST API provided by HA for our own needs. (For example, make your own home hub, which will be covered later)

HomeAssistant does not enable REST API functionality by default. You will need to configure the API options in configuration.yaml, as shown below πŸ‘‡

There are many other configurable options for HomeAssistant. For details, see πŸ‘‰developers.home-assistant. IO /

Offline download — Aria2

Some resources take a long time to download and are not suitable for the computer to hang up for downloading for a long time. In this case, we can turn raspberry PI into an offline download server. When it comes to downloads, one of the most compelling is the Aria2.

Aria2 is a free, cross-platform command line interface download manager. Unlike downloaders like Wget, Aria2 not only supports BitTorrent but also can multipath retrieve requested files from a variety of sources. Including HTTP, HTTPS, FTP and BitTorrent protocols.

For those of you interested in how seed downloading works, you can read my article at πŸ‘‰ “Everyone is LSP?

Aria2 is already installed on Raspbain by default. Run apt-cache show Aria2 to check the installation information, so you need to find a graphical interface for Aria2. One of the great things about using Docker is that you can go directly to someone else’s image file, which makes it easy to install and use.

Simply execute the following command to launch an Aira2 graphical interface πŸ‘‡

docker run -d --name aria2-ui-pi -p 8888:80 -p 6800:6800 -v /data:/data --restart=always huangzulin/aria2-ui-pi
Copy the code

The default download path is in the /data folder within the container. It is best to specify a volume map for ease of use

LAN file sharing — Samba

Today, phones are Android/iOS and computers are Win/Mac, and despite the Apple ecosystem, file transfer from device to device remains a major issue to this day.

Samba is a piece of free software that implements the SMB protocol on Linux and UNIX systems. SMB (Server Messages Block) is a communication protocol for sharing files and printers over a LAN. It provides file and printer sharing services between different computers in the LAN. With this protocol, you can quickly and easily share files between Windows and Linux/Unix, instead of transferring files online via QQ.

The installation process is also very simple, you can choose apt installation or docker installation directly, there are many online tutorials, for details, please refer to πŸ‘‰ to configure Samba service on raspberry PI tutorial

Create your own home hub

Whether it’s HomeAssistant or Aria2, these are all written by other people, and if you want to make the Raspberry PI more customized, you can write your own little programs along the way (which is why the REST API open to HomeAssistant was mentioned earlier).

If you want your application to run on raspberry PI, there are several ways to go πŸ‘‡

Hub in order to build a our own family, my idea is in a can touch screen control their home smart home devices (with the help of a HomeAssistant), to check the weather (wind weather), visually track delivery schedule (spider), clock, day/day/photos from bottom wall, etc., so it is a complete web page, The technology stack I chose was SpringBoot + Flutter Web + Nginx and then started the whole service using Docker packaged as an image.

Part of the page is πŸ‘‡

I am doing Java related work. There is nothing wrong with SpringBoot as a backend. The reason why Flutter Web is chosen instead of traditional Vue or React, On the one hand, because of the Flutter declarative UI really than traditional Web page read write more comfortable, more efficient, on the other hand, nine because written in Flutter Web pages can be seamlessly into the Android/iOS/PC/Linux/macOS native App on these platforms, It will help with multiple platform coverage later (more because I’ve forgotten about Vue and React).

At present, this webpage is relatively simple, and THERE are still many functions I want to do, but I plan to keep updating this code in the future. If it runs well at home in the future, I even have the idea to open source, but that’s another story.

Anytime, anywhere access – Intranet penetration

Have you found one big problem with all these things?

Yes, all of these things require that your computer and the Raspberry PI live on the same network, or LAN. Although I started the usage scenario is used in the home, but if I suddenly want to watch a TV show in the company, but the use of company computers to download video is obviously unrealistic, if by this time I can net direct access to the home of raspberries pie offline download service, then after I come home from work not can see oneself want to see the movie?

So the best way to do this is to contact your broadband operator and apply for a public IP address that will allow you to access your Raspberry PI.

As far as I know, at present only some areas of telecom provide public IP, and most operators will not provide public IP, and the application process is very troublesome. Therefore, in order to access files or other services of the home server from the Internet anytime and anywhere, we can make an “Intranet penetration” for raspberry PI.

“Most problems in the computer world can be solved by adding a layer.” Intranet penetration is nothing more than adding a relay server between the internal network and the Internet, which takes your requests and forwards them to the internal server, the “proxy.”

Of course, the principle of Intranet penetration is definitely not so simple, here is just a popular explanation, if there is a chance to elaborate later. Therefore, in order to achieve Intranet penetration, we need to have a server that can be accessed by the public network as a transfer bridge. At this moment, I suddenly thought that the student computer I bought before graduation has not expired, and now it happens to be eating ashes. Wouldn’t it be the best to use it for transfer?

There are many choices for Intranet penetration server, FRP is the most used, but HERE I choose πŸ‘‰ NPS, the reason is also very simple, beautiful page, simple interaction, performance is adequate.

NPS is a lightweight, high-performance, powerful Intranet penetrating proxy server. Supports TCP and UDP traffic forwarding, and supports any TCP and UDP upper-layer protocols (access to Intranet websites, local payment interface debugging, SSH access, remote desktop, Intranet DNS resolution, and so on). In addition, it also supports Intranet HTTP proxy, Intranet SOCKS5 proxy, P2P, etc., and has a powerful Web management terminal.

We only need to install the server on the cloud host, install the client on the raspberry PI as prompted, and simply set the port to forward to achieve Intranet penetration.

The official documentation is at πŸ‘‰ehang-io.github. IO/NPS /#/? Id = n…

The last

The best thing about owning a raspberry PI is that you can give full play to your inspiration and creativity. If you have the ideas, the ability and the time, let the raspberry PI be your vehicle to realize your ideas.

Finally pulled a little outside of the article, was certainly a lot less time after work, this article from start to finish the took nearly a week now, ali’s work strength is very big, every day and get home from work most is something after 10 o ‘clock, can stay out of the code word time is limited, a rare free weekend, the recent move me write down the thoughts of our own home, It’s the beginning of a new phase. During this period of time, I have read many excellent internal documents. I also hope that my future articles can be more professional like the gods on the Intranet. Come on for the new journey!

The above is all the content of this article, if you feel good, you might as well give me a thumbs-up attention to support oh πŸ‘