Giter Club home page Giter Club logo

raspbian-motioneye's Introduction

raspbian-motioneye

Guide for setting up Rasbian lite running MotionEye headless for the Raspberry Pi 4

  1. Preface
  2. Preparation
  3. Setup
  4. Installation
  5. Configuration
  6. HTTPS / TLS (Optional)
  7. Troubleshooting

0. Preface

While reading the guide, replace all instances of <T3xtT0R3pl4ce> (including the < and > symbols) with the appropriate value for your usage

It's highly recommended that you setup https with DDNS (afraid org) + Lets Encrypt (certbot) if you would like to access the web client remotely.

USB Boot

If you would like to boot off a USB, HDD, or SSD, follow this guide (use [gnu] dd rescue to clone the sdcard) then use fdisk delete + new (make sure to start new partition on same sector as before) then e2fsck and fsresize, all while being on the sdcard, then reboot.

1. Preparation

  1. Download and install PuTTY

  2. Download and install Rufus

  3. Download Raspbian lite

  4. Plug in a micro SD card of at least 4GB

  5. Run Rufus, select the Raspbian Lite image, select the micro SD card, and click start

  6. Open a file explorer and navigate to the micro SD card (if micro SD card doesn't show, see Troubleshooting 1)

  7. Open config.txt in an editor and add the following lines to the end of the file:

    # Use gpu_mem=128 if a camera is attached to the device
    boot_delay=0
    disable_splash=1
    
    gpu_freq_min=250
    arm_freq=1600
    h264_freq=600
    
  8. If using ssh, create a new file named ssh in the micro SD card's root directory and put a single space in it

  9. If using wifi, create another new file named wpa_supplicant.conf and set it's contents to:

    country=<iso alpha-2 code>
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    
    network={
    	scan_ssid=1
    	ssid="<network name>"
    	psk="<network password>"
    }
    

    Valid ISO Alpha 2 codes examples: US DE GB CA

  10. Eject the micro SD card from the computer

  11. Insert the micro SD card into the Raspberry Pi

  12. Plug in the Ethernet cable if available and power on the Raspberry Pi

2. Setup

  1. Run PuTTY

  2. Enter hostname raspberrypi and click "Open" (if PuTTY raises error "Host does not exist", see Troubleshooting 2)

  3. Login to the shell with login pi and password raspberry

  4. Change root password with sudo passwd root the enter the new root password

  5. Create a new user sudo adduser alice

  6. Add user to sudo group sudo usermod -aG sudo [new user name]

  7. Switch to new user sudo su - [new user name]

  8. Stop user "pi" processes sudo pkill -u pi

  9. Delete the "pi" user sudo deluser -remove-home pi

  10. Set a static IP by running sudo nano /etc/dhcpcd.conf and adding the following lines (can be skiped with static dhcp on your router):

    interface wlan0
    static ip_address=<static ip>
    static routers=<gateway ip>
    
    interface eth0
    static ip_address=<static ip>
    static routers=<gateway ip>
    

    Press Ctrl + O then Ctrl + X to save and exit

  11. Update and upgrade software and firmware by running the following commands then reboot:

    sudo apt update
    sudo apt full-upgrade
    sudo rpi-update
    sudo apt autoremove --purge
    sudo apt clean
    sudo reboot
    
  12. Reconnect to the Raspberry Pi with PuTTY

  13. Run sudo raspi-config then run Update then change network hostname and localization options

  14. Reboot and reconnect to the Raspberry Pi with PuTTY using the new hostname/IP address

  15. Setup fail2ban for added security

3. Installation

Run the following commands

sudo apt install python-pip python-dev libssl-dev libcurl4-openssl-dev libjpeg-dev libz-dev libavcodec58 libavdevice58 libavformat58 libavutil56 libmariadb3 libmicrohttpd12 libpq5 libswscale5 libwebp6 libwebpmux3 ffmpeg
mkdir -p ~/Downloads ; cd ~/Downloads
wget https://github.com/Motion-Project/motion/releases/download/release-4.2.2/pi_buster_motion_4.2.2-1_armhf.deb
sudo dpkg -i pi_buster_motion*
sudo pip install motioneye

4. Configuration

Run the following commands

sudo mkdir -p /etc/motioneye /var/lib/motioneye
sudo cp /usr/local/share/motioneye/extra/motioneye.conf.sample /etc/motioneye/motioneye.conf
sudo cp /usr/local/share/motioneye/extra/motioneye.systemd-unit-local /etc/systemd/system/motioneye.service
sudo systemctl daemon-reload
sudo systemctl enable motioneye
sudo systemctl start motioneye

Access MotionEye by going into your browser and going to <hostname>:8765 or <raspberry pi ip>:8765. The default login is admin with no password

Configure MotionEye to your liking using sudo nano /etc/motioneye/motioneye.conf

Periodically upgrade MotionEye using with the following commands:

sudo pip install -U motioneye
sudo systemctl restart motioneye

5. HTTPS / TLS and AUTH (Optional)

  1. Acquire a [sub]domain via https://freedns.afraid.org/ (free) or some other domain / DNS service and point it to your IP (DDNS is recommended instead)

  2. Run the following commands

sudo apt install nginx certbot python-certbot-nginx
sudo rm /etc/nginx/sites-available/default
sudo rm /etc/nginx/sites-enabled/default
sudo nano /etc/nginx/conf.d/<my.d0m41n.0rg>.conf
  1. Insert the following lines
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name <my.d0m41n.0rg>;
    location / {
    	proxy_set_header Host $host;
    	proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://127.0.0.1:8765/;
    }
}
  1. Portforward 80 to 80 on your [sub]domain aquired in step 5.1

  2. Run the follow commands

sudo systemctl enable nginx
sudo systemctl start nginx
sudo certbot --nginx
  1. Disable portforward for port 80 to 80, and enable it for port 443 to 443

  2. See auth setup here

  1. This should result in a NginX config like the following:
server {
    server_name nvr4.us.to;

    auth_basic "restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;

    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://127.0.0.1:8080/;
    }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/nvr4.us.to/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/nvr4.us.to/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = nvr4.us.to) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80 default_server;
    listen [::]:80 default_server;
    server_name nvr4.us.to;
    return 404; # managed by Certbot
}

6. Troubleshooting

1. Micro SD card not showing

  1. Press Win + R
  2. Type diskpart then press Enter then run list disk
  3. Select the appropriate disk with select disk <x> where <x> is the disk number
  4. Run list partition
  5. Select the appropriate partition with select partition <y> where <y> is the partition number (usually partition 1, ~256MB)
  6. Run assign letter=i
  7. Check for drive I in your file explorer

2. PuTTY host does not exist

  1. Check router (or use NMap) to get IP address of the Raspberry Pi (sort by access time if needed)
  2. Connect to the Raspberry Pi with PuTTY using the IP address

raspbian-motioneye's People

Contributors

andrevallestero avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

raspbian-motioneye's Issues

Install fails

Below command produces python error.
3. Installation
Run the following commands
sudo apt install python-pip python-dev libssl-dev libcurl4-openssl-dev libjpeg-dev libz-dev libavcodec58 libavdevice58 libavformat58 libavutil56 libmariadb3 libmicrohttpd12 libpq5 libswscale5 libwebp6 libwebpmux3 ffmpeg
mkdir -p ~/Downloads ; cd ~/Downloads
wget https://github.com/Motion-Project/motion/releases/download/release-4.2.2/pi_buster_motion_4.2.2-1_armhf.deb
sudo dpkg -i pi_buster_motion*
sudo pip install motioneye

When replacing with python3 install finishes but systemctl status motioneye.service shows:
motioneye.service - motionEye Server
Loaded: loaded (/etc/systemd/system/motioneye.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2022-03-15 02:58:54 GMT; 2min 53s ago
Process: 1547 ExecStart=/usr/local/bin/meyectl startserver -c /etc/motioneye/motioneye.conf (code=exited, status=1/FAILURE)
Main PID: 1547 (code=exited, status=1/FAILURE)
CPU: 112ms

Mar 15 02:58:54 raspberrypi systemd[1]: Started motionEye Server.
Mar 15 02:58:54 raspberrypi meyectl[1547]: Traceback (most recent call last):
Mar 15 02:58:54 raspberrypi meyectl[1547]: File "/usr/local/bin/meyectl", line 5, in
Mar 15 02:58:54 raspberrypi meyectl[1547]: from motioneye.meyectl import main
Mar 15 02:58:54 raspberrypi meyectl[1547]: File "/usr/local/lib/python3.9/dist-packages/motioneye/meyectl.py", line 28, in
Mar 15 02:58:54 raspberrypi meyectl[1547]: import settings
Mar 15 02:58:54 raspberrypi meyectl[1547]: ModuleNotFoundError: No module named 'settings'
Mar 15 02:58:54 raspberrypi systemd[1]: motioneye.service: Main process exited, code=exited, status=1/FAILURE

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.