I bought a raspberry pie earlier. I bought Raspberry Pi3 Modle B.

The PI doesn’t come with a hard drive, so if you want to install the system, you need to get your own TF card or USB flash drive.

Next, go to the Raspberry PI website to download the system. The official installation system tool, NOOBS, is very simple.

Download address

Once the download is complete, we can follow these steps to install the system.

1. Decompress the downloaded ZIP package to a TF card

2. Insert the TF card into the raspberry PI, connect the monitor, mouse and keyboard with HDMI, and connect the power supply.

That’s when the raspberry PI lights up.

3. Press the Shift key to enter the system recovery interface

Select the system you want to install and click Install.

Wait a few minutes and the system will be installed.

When you reboot and enter the desktop, the desktop operating system is called PIXEL OS; Based on the Debian.

PIXEL stands for “Pi Improved Xwindows Environment, Lightweight”.

Use SSH to connect to your raspberry PI

Open command line in Raspberry PI:

Enter sudo raspi – config

Select Advanced Options

Select SSH

Select yes

SSH has been enabled

Then open the PC command line (I use a MAC, command line can directly use SSH)

Input:

SSH [email protected]Copy the code

The address is raspberry PI’s IP address. If you don’t know it, type ifconfig on the Raspberry PI command line to see it

Then enter the password, which, if you haven’t changed the password for user PI, is raspberry by default

Then you can have fun

Install Nodejs

Download Nodejs

Nodejs download page

We selected the Linux Binaries (ARM) ARMv7 version and copied the download link

Wget https://nodejs.org/dist/v12.18.4/node-v12.18.4-linux-armv7l.tar.xz tar - XZF node - v12.18.4 - Linux - armv7l. Tar. Xz / / install package sudo mv node - v12.18.4 - Linux - armv7l/usr/local/bin/node/sudo ln/usr/local/bin/node/bin/node/usr/local/bin/node  sudo ln -s /usr/local/bin/node/lib/node_modules/npm/bin/npm /usr/local/bin/npmCopy the code

Ok, at this point we will type in any directory:

node -v
npm -v 
Copy the code

Node is up to date and NPM is available

Because in China, using NPM to download packages will often be unstable, at this time we can use CNPM, enter the following command:

$ npm install -g cnpm --registry=https://registry.npm.taobao.org
Copy the code

After downloading, when we install the module:

$ cnpm install [name]
Copy the code

Raspberry PI boot pM2

Next, here’s how to get the PM2 to boot on the raspberry PI

First download pM2

cnpm install pm2 -g
Copy the code

Run the code that needs to run

pm2 start app.js
Copy the code

Save the running state of pM2 so that pM2 can run app.js again after startup

// The system will generate a file '/home/ PI /.pm2/dump.pm2'Copy the code

(Important) Next we will lock the file and not allow any modification

sudo chattr +i /home/pi/.pm2/dump.pm2
Copy the code

Setting boot

Sudo pm2 startup systemd -u PI -- HP /home/pi sudo reboot //Copy the code

Through the above steps, we can successfully boot pM2 and run app.js

If we want to change the pM2 startup configuration later, we need to unlock the dump.pm2 file,

Pm2 start xxx.js // Run another program sudo chattr -i /home/pi/.pm2/dump.pm2 // Unlock file sudo pm2 save // save configuration sudo chattr + I Pm2 // Relocks the OS sudo pm2 startup systemd -u PI -- HP /home/pi/ / sudo reboot Restarts the OSCopy the code

This is how to change the PM2 startup configuration. Is it as simple as can be?

The time calibration

It’s probably the Raspberry PI version of the system. Many of the Internet methods used to turn on the Network time protocol (time autocalibration) have failed. For such a white person as me, I have tried many ways, but have not succeeded.

Today, the correct opening position;

Raspberry PI doesn’t have auto-calibrate by default. You need to enable Network Time Protocol (NTP) to ensure Time accuracy as much as possible.

Enable the NTP:

sudo timedatectl set-ntp true
Copy the code

Let’s see if the time is right:

pi@raspberrypi:~ $date Mon mar 20, 2017 21:38:41 CSTCopy the code

Obviously the time is right. If the time difference is less than 24 hours, it’s probably the wrong time zone.

That’s all for today.