Odd technical guidelines

Author: Liu Guanyu, senior front end engineer and technical manager of 360 Qi Dance Group, has participated in many large front end projects such as 360 Navigation, 360 Film, 360 finance and 360 games. A member of the W3C CSS Working Group who focuses on the latest developments in W3C standards, IOT, artificial intelligence and machine learning.

This article is reprinted from Qiwu Weekly.

Where does China look? Full view of the north Solid building. How many events through the ages? Leisurely. The Yangtze River is still rolling. Young million doumou, sit off the southeast war did not rest. World hero who rival? Cao Liu. Son should be like Sun Zhongmou.

— Song xin Qiji, “The Son of The South village · Climbing the North Guting Of Jingkou with a Heart”

origin

Around 2016, WHEN I saw an AD for Raspberry Pi on a tech forum, I was deeply impressed by this small, cheap, portable device. Old habits invade slowly, and start with one without saying a word. After a brief period of tossing and turning, it was put aside. Recently, the tide of WoT is coming as fast as thunder, I think of this hiding in the corner to eat ash stuff, immediately turned out, blow a blow on the dust……

Half an hour later, as the dust clears, a new, clean Raspberry Pi 2 is unveiled. The model is a bit dated, but given the hardware architecture is similar, the middle-aged Raspberry Pi 2 can still make the most of its time. Yes, as the popular online opinion goes, “Don’t scold the young, they will quit immediately, but you can scold the middle-aged to death.” Well, if we’re here, we might as well grind this “middle-aged” raspberry pie to death.

But for all this, some purpose is needed. That way, we get positive feedback on our goal achievement, which gives us a solid reason to keep exploring — I thought as I mopped the floor.

Ideas abound, and a search on Zhihu.com turns up questions like this one: What are some interesting adaptations and extensions to raspberry PI? I found a lot of fun ideas here that I really wanted to bring to fruition in raspberry PI. To this end, I set up this series, hoping to record the implementation process of some small ideas, and give readers some reference for making these applications in the future.

Get to know raspberry Pie

The raspberry PI, which was developed by physicist Eben Upton in a Laboratory in Cambridge, UK, over the past six years, went on sale in March 2012. The Raspberry PI is the size of a credit card and has all the basic functions of a computer.

Most raspberry PI models support multiple USB ports, as well as Ethernet ports. The CPU architecture of the Raspberry PI is ARM, which is different from the x86 architecture of traditional PCS. This article 2 details the differences between the two architectures. ARM architecture CPU with small size, low power consumption and low cost has been widely used in mobile devices, microcontrollers and other devices. These advantages of ARM architecture are also highly compatible with the research and development purpose of raspberry PI.

The latest version of the Raspberry PI is the 3B+, with a more powerful processor, faster network support, and direct integration with a Bluetooth adapter that supports the Bluetooth 4.2 protocol. At present, many researches on the Internet of Things are also based on raspberry PI.

As a single board computer, the Raspberry PI has many operating systems available. We recommend Raspbian, the official Raspberry PI system, which is a linux-based distribution that has been deeply customized. With this system installed, your Raspberry PI gets Linux’s system power, infrastructure drivers, and a vast array of high-quality software packages.

The Raspberry PI contains 40 sets of GPIO input and output pins, which can be used with sensors to make a series of interesting applications by sensing high and low level changes. Many high-level languages (environments) such as C/C++, Python, and NodeJS support encapsulation of GPIO manipulation. This is also a very attractive feature of the raspberry PI.

In addition to raspberry PI, there are many similar single-board computer products, such as Banana PI, Arduino, etc. Readers who are interested can read on related information.

Minimum equipment to be purchased

Let’s start our raspberry PI tour.

Unlike other software practices, the first obstacle is the need to purchase a certain amount of equipment. It’s the same principle as before, novice on the road, you can step by step. Let the raspberry PI run first, then slowly sink into the pit with constant positive feedback.

In order to determine the minimum equipment investment, you need to identify what you are going to do and what you are going to achieve.

After some careful planning, the author decided to use raspberry PI to build a NodeJS website development environment accessible to the Intranet.

First, we need a raspberry PI mainframe, a single board, the latest version of which is the 3B+. Here’s the original Raspberry PI 2.

Secondly, in order to ensure that the host can be protected from the impact of the surrounding environment, but also to ensure easy access to place, so we need to give the host a shell.

Again, for heat dissipation convenience, you can purchase a few heat sink or heat dissipation fan. Considering the heat dissipation effect and operation convenience, it is recommended to purchase a heat dissipation fan.

In addition, raspberry PI’s system is usually burned on an SD card. The reading speed of the card will affect the efficiency of the whole raspberry PI, so it is recommended to use a high-speed card. The size of the card should be greater than 4GB (you rarely see cards with less than that, and you rarely see low-speed cards), and you need a card reader. If the laptop is already equipped with a card reader, this expense can be left over.

To connect the raspberry PI to the Internet for the first time, prepare a network cable.

At the same time, if there is a wireless router, it is recommended to purchase a wireless network card for convenient operation.

Finally, if you don’t want to grab a power supply every time you turn it off, buy a power supply with a switch.

OK, that’s enough for the purpose.

Readers can search for relevant products to purchase from a certain treasure or click on the corresponding purchase page from the purchase 3 link on the official website. In principle, these things can be done for 200-400 dollars.

All right, let’s get a picture of all this stuff up there.

It is very appropriate to save them up.

Of course, sensors, jumpers, and other gadgets will appear later in our series. I feel that the periodic purchase of those, is the most expensive link 🙂

Install the system

Are your raspberry PI and your universe ready to explode? Get the operating system in place before it explodes.

As mentioned earlier, it is recommended to install the official recommended Raspbian first. Readers can download the installation package here. At present, there are two versions, one includes the desktop version, the installation package is relatively large, if you have configured the relevant monitor, keyboard and mouse can consider this version. If you don’t need desktop support for now (you can install it again if you need it), consider downloading the Lite version.

Here, let’s take the Lite version as an example.

We have downloaded a Zip package, and using the package view tool, we can see that the package contains a.img file, which we will burn to the SD card.

To do this, we need some tools. Here, the official recommendation is Etcher. The software is a graphical card writer tool available for Mac, Linux and Windows. Readers follow the following steps to complete the burning.

  1. Download the Etcher for your system and install it from here.

  2. Connect the card reader and insert the SD card to be written

  3. Run Etcher and select the Zip file you just downloaded or the unzipped.img file.

  4. Select the SD card to be written.

  5. Click “Flash”, then make a cup of tea or coffee and wait for the record to finish.

Initializing the system

Confirm the IP

Once the system is installed, we connect it to the router through a network cable. At this point, the raspberry PI automatically connects to the network. Since you did not purchase a display screen or a keyboard and mouse, you can use SSH to remotely connect to the Raspberry PI. The problem now is how to identify PI’s IP.

There are several options, but here’s one of the easiest: use your phone or PC (if not……) Go to your router’s management screen (if you don’t know this screen, consult your router’s manufacturer. http://192.168.0.1/admin if not specified), and go to the device management page, you’ll find a device named Raspberry, and write down its IP (e.g., 192.168.0.10).

User Settings

Now you can use SSH client to connect to raspberry PI. If you use Mac or Linux, the system comes with SSH connection terminal. If you use Windows, please download and install SSH connection software such as Putty.

If the SSH service of raspberry PI is not enabled, create a folder named SSH in the boot partition after the image is burned. After normal boot, you can connect to raspberry PI through SSH.

By default, PI is assigned a user, PI, with the default password: Raspberry. Since it is the default, the first step for security is to log in and change its password.

SSH [email protected]

Copy the code

At the prompt you can type raspberry to log in. Change the password immediately.

passwd

Copy the code

Change the default password as prompted. This, to some extent, improves the safety of the raspberry pie.

In addition, it is recommended to create a user as a common account, for example:

sudo adduser leon

sudo passwd leon

Copy the code

This creates a new user named Leon and allows you to set an account password for Leon.

For system-level operations, Leon can be added to Sudoer.

sudo visudoer

Copy the code

On the edit screen, add Leon to the list and save. In the future, SSH login raspberry PI will be able to use Leon as the username.

The configuration tool

The Raspberry PI itself comes with a configuration tool interface. From the command line, type the command sudo raspi-config. The following figure is displayed.

Change the source

For students in mainland China, it is recommended to change the domestic source to ensure faster download speed. Ali’s source is used here, and readers can similarly switch if they have a better source.

The system we installed was based on the Debian distribution. So Debian’s package management tools are available here. Similarly, the way to switch sources is similar.

Backup first, repent later

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

Open the software source list file

sudo vim /etc/apt/sources.list

Copy the code

Next, comment out the original source and add the following two lines

deb http://mirrors.aliyun.com/raspbian/raspbian/ wheezy main non-free contrib

deb-src http://mirrors.aliyun.com/raspbian/raspbian/ wheezy main non-free contrib

Copy the code

Note that depending on the Raspbian version, the Wheezy column can become Jessies. The reason for this change is that the name of the system varies depending on the Debian system. A safe bet is to go back to the original source and just change the domain name.

After the modification is complete, you can run sudo apt-get upgrade to complete the upgrade of the software package resource index. After the successful update, you can download the corresponding software at high speed.

About Chinese gibberish

The solution is to install the Chinese character library and input method, and modify the default character set of the system.

sudo apt-get install ttf-wqy-zenhei

sudo apt-get install scim-pinyin

Copy the code

In the configuration tool described above, select item 5 and configure as prompted. For the next screen, choose Change Locale

In the next screen, remove en_gb.utF-8 UTF-8 and select en_US. Utf-8 UTF-8, zh_CN. Utf-8 UTF-8, and zh_CN.GBK GBK. And select zh_cn.utF-8 as the default language on the next screen.

Restart the raspberry PI for the results to take effect.

Change the time zone

By default, PI’s time zone is UTC0, which can be problematic for time-dependent applications. Mainland China is in zone 8 east, which can be set by sudo Raspi-config.

Select Asia > ShangHai and click Finish to save and exit. The setup is complete.

Wireless Network Adapter Configuration

If you don’t have the need to move a raspberry PI, plugging in an Internet cable is enough to solve the Internet problem. In that case, readers can skip this section. However, if you want to do mobile applications in the future, or do not like to plug in the network cable, it is recommended to install a wireless card.

First, you need to make sure your wireless card is properly powered. You can connect to raspberry PI and enter the ifconfig command to view all raspberry PI network devices. It is rare to fail to find a network card. If you do, make sure the network card is available and find the corresponding driver to install.

Now, prepare the corresponding WIFI information. Edit the wpa_supplicant.conf file. Sudo vim /etc/wpa_supplicant/wpa_supplicant.conf

network={

Name ssid = "WIFI"

  key_mgmt=WPA-PSK

PSK = "WIFI password"

}

Copy the code

Note here:

  1. The SSID name is not recommended in Chinese

  2. It is better not to have special symbols such as

Run the /etc/init.d/networking restart command to restart the network

You can use ifconfig again to view the network. You can also open the router management page mentioned above to check whether a new device is added. If your wireless card is found, you can:

  1. Unplug the network cable without worry

  2. Connect to the IP address that uses the wireless network card.

Install the Web server software

Above we have configured the main functions of the system. Let’s start configuring the Web server software. Here we use Nginx as the server software.

Because the system is Based on Debian and the faster software source has been configured, the following is pleasant.

sudo apt-get install nginx -y

Copy the code

At this point, the default WWW root of Nginx is /usr/share/nginx/www. You can modify /etc/nginx/sites-available/default to configure the directory, port, proxy, etc.

Configure the NodeJS development environment

Sudo apt-get install nodejs However, the NodeJS version installed this way may be older. If installed from source, raspberry PI processing power is relatively weak, so not recommended.

Here is recommended a more labor-saving and perfect method.

  1. Run the uname -a command to query the system version and find arm***.

  2. Open https://nodejs.org/dist/latest/ in accordance with the “arm” package, download it.

  3. The decompression.

  4. Move the decompressed node folder, such as node-v10.10.0-linux-armv7l, to the /usr/local/ directory and rename it node.

  5. Run echo PATH=$PATH:/usr/local/node/bin >> ~/. Bashrc; source ~/.bashrc

This completes the NodeJS installation.

Once installed, we were free to be creative and build nodeJs-based websites. I recommend ThinkJS NodeJS, the latest version of which is 3.2.8. The official website is https://www.thinkjs.org/. We can build websites quickly based on this framework.

Look, here is the ThinkJS show time, delightfully 🙂

summary

In this article, the author took you to understand the raspberry PI, and detailed the system installation and some system initial configuration, the installation of the website server environment and NodeJS development environment, the establishment of a NodeJS website development environment. Completes the raspberry PI’s debut. More interesting topics, such as sensors, will continue to appear in future installments. I’ll also hurry up and show you a more interesting raspberry pie.

Thank you

Thanks to Wenli He for his suggestions. Stylist Wang Xuan mm, for this article design exquisite picture, express sincere thanks together here.

Text links in

  1. https://www.zhihu.com/question/20697024/answer/15888489

  2. http://m.elecfans.com/article/678193.html

  3. https://www.raspberrypi.org/products/#buy-now-modal

  4. https://www.raspberrypi.org/downloads/raspbian/

  5. https://etcher.io/

World of you when not

Just your shoulder

There is no


360 official technical official account

Technology of dry goods | | hand information activities

Empty,