Raspberry Pi realizes remote monitoring motion (via ngrok)

Recently, I did a small monitoring while learning the Raspberry Pi. Let me introduce the process:

1. Hardware preparation

        (1) Prepare a raspberry pie (I use the 4B version, the system is bulllseye)

        (2) A CSI or USB camera

2. Raspberry Pi configuration 

(1) Install motion

 sudo apt-get install motion

 (2) Open the motion daemon daemon process so that motion can always run in the background.

 sudo nano /etc/default/motion打开配置文件并添加 start_motion_daemon=yes

                 

(3) Edit /etc/motion/motion.conf

          After sudo nano /etc/motion/motion.conf, the following interface will appear. This is the default configuration file of motion, modify the configuration parameters inside.

  • 将daemon修改为on
    target_dir /home/pi/Motion  设置图像保存路径设置
    stream_port 8081                确认视频流接口是8081
     width 800 height 600         设置分辨率
    stream_localhost off            关闭localhost本地限制
    为了防止视频流畅最好设置  stream_maxrate 70    framerate 100
    //可以使用ctrl+w查询逐个修改 nano自带功能

    (The interface is as follows)

                       

(4) Turn on or off the motion service

sudo motion   //开启motion服务
sudo kilall -TERM motion  //关闭motion服务

(5) Turn on or off the motion service

ifconfig查看电脑的ip地址

(6) Log in to the ip address + port number on a computer or other device on the intranet (LAN)

Log in to http://192.xxx.xx.xxx: port number on chorm.

                         

 3. External network control Raspberry Pi

        First of all, a tool for intranet penetration is needed. That is, when you are not at home, you can use the Internet to connect to the Raspberry Pi (or computer) that is connected to the router at home. The penetration tool I choose here is ngrok. I saw that many people also choose peanut shells, but it is really a bit too expensive.

The download URL of ngrok: Setup - ngrok , please download it yourself. (When visiting  ngrok.com  , an Ngrok account will be created. Here, it is recommended to use github to register an account, because I cannot register in other ways...)

(1) After the peanut shell is downloaded, it can be installed by itself according to the steps on the website. (Here I installed the arm64 version of linux)

 Once the download is complete you can use the following command to extract ngrok from the terminal. Or on Windows, just double-click ngrok.zip to unzip it.

unzip /path/to/ngrok.zip

(2) When registering an account, you will be given an identity code, which can be bound to your Raspberry Pi. (You only need to bind once, and your ngrok account is connected to the Raspberry Pi) Enter the following command in the Raspberry Pi terminal.

ngrok config add-authtoken 2F9xtsemWGRiX3ui1E7euwP6Nml_xxxxxxxxxxxxxxxx

ps: I spent a long time here. Because it always says there is no ngrok command. . . . . But I have downloaded it according to the steps, and finally I found that I have two important but mentally handicapped problems. The first one is that you have not switched to the ngrok directory, and you can cd wherever ngrok is downloaded. . The second is to add ./ in front of the command line. If you don’t add this, the shell will not be able to find the path of your program.

Command search rules in terminal

  • If there are characters in the pathname  ./ , then no search is done  $PATH.
  • If  ./ not in the pathname, then only  $PATH search in .

 (3) Run the command to develop the port as needed

   ngrok http 8081

        It should be noted that the ports here 8081can be replaced with other ports as needed. This command means to expose the service corresponding to the local port 8081 to the external network . (And my 8081 port is just turning on the camera now) After the execution is completed, the code is as follows, and the forward should be noted.

In this way, all requests to visit http://xxxxxxxxxxxx will be sent to localhost:8081.

Finally, you can watch your home camera from outside.

 

Guess you like

Origin blog.csdn.net/weixin_45348216/article/details/127023363