From 9e4a217b5fe3c1a2439996d8cd1752b10d507fb2 Mon Sep 17 00:00:00 2001 From: localhorst Date: Tue, 23 May 2023 21:50:25 +0200 Subject: [PATCH] inital working version --- README.md | 26 ++++++++++++++++++ config.py | 8 ++++++ msv-webcam-backend.service | 14 ++++++++++ msv_webcam_backend.py | 55 ++++++++++++++++++++++++++++++++++++++ www/index.html | 14 ++++++++++ 5 files changed, 117 insertions(+) create mode 100644 config.py create mode 100644 msv-webcam-backend.service create mode 100644 msv_webcam_backend.py create mode 100644 www/index.html diff --git a/README.md b/README.md index 92389b7..3a9e278 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,28 @@ # msv-webcam-backend + +useradd --system msvwebcambackend -m +passwd -l msvwebcambackend + + +- `mkdir /opt/msv-webcam-backend/` +- `cd /opt/msv-webcam-backend/` +- import `msv_webcam_backend.py` and `config.py` +- Set the constants in `config.py` +- `chmod +x /opt/msv-webcam-backend/msv_webcam_backend.py` +- `chown -R msvwebcambackend /opt/msv-webcam-backend/` +- `nano /etc/systemd/system/msv-webcam-backend.service` +- `systemctl daemon-reload && systemctl enable --now msv-webcam-backend.service` + + +mkdir /var/www/html/msv-buehl-moos.de/webcam/ + +chown -R wwwrun:wwwrun /var/www/html/msv-buehl-moos.de/ + + + + + location /webcam { + root /var/www/html/msv-buehl-moos.de; + index index.html; + } diff --git a/config.py b/config.py new file mode 100644 index 0000000..e2c1a84 --- /dev/null +++ b/config.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" Author: Hendrik Schutter, mail@hendrikschutter.com +""" + +image_search_path = "./test_images/" +destination_image_full_path = "./www/data/still.jpg" +update_interval = 10 # 10sec diff --git a/msv-webcam-backend.service b/msv-webcam-backend.service new file mode 100644 index 0000000..fdf0d64 --- /dev/null +++ b/msv-webcam-backend.service @@ -0,0 +1,14 @@ +[Unit] +Description=MSV-Webcam-Backend +After=syslog.target +After=network.target + +[Service] +RestartSec=2s +Type=oneshot +User=msvwebcambackend +WorkingDirectory=/opt/msv-webcam-backend/ +ExecStart=/usr/bin/python3 /opt/msv-webcam-backend/msv_webcam_backend.py + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/msv_webcam_backend.py b/msv_webcam_backend.py new file mode 100644 index 0000000..42893a5 --- /dev/null +++ b/msv_webcam_backend.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" Author: Hendrik Schutter, mail@hendrikschutter.com +""" + +import config +import glob +import os +import time +import shutil + +def copy_image(src): + shutil.copy(src, config.destination_image_full_path) + os.chmod(config.destination_image_full_path, 644) + +def main(): + print("starting ...") + + newest_file_path = "" + newest_file_size = 0 + + while True: + + while True: + try: +# print(config.image_search_path) + list_of_files = glob.glob(config.image_search_path+"/**/*.jpg", recursive=True) + # print(list_of_files) + newest_file_path_tmp = max(list_of_files, key=os.path.getctime) + newest_file_size_tmp = os.stat(newest_file_path_tmp).st_size + + if (newest_file_path_tmp == newest_file_path) and (newest_file_size_tmp == newest_file_size): + # already found the newest file + print("no newer file found") + break + + time.sleep(1) # wait 1sec to see if the upload is still in progress + + list_of_files = glob.glob(config.image_search_path+"/**/*.jpg", recursive=True) + newest_file_path = max(list_of_files, key=os.path.getctime) + newest_file_size = os.stat(newest_file_path).st_size + + if (newest_file_path_tmp == newest_file_path) and (newest_file_size_tmp == newest_file_size): + print("Found new file:") + print("Name: "+str(newest_file_path)) + print("Size: " + str(newest_file_size)) + copy_image(newest_file_path) + break + except Exception as e: + print(e) + #break + time.sleep(config.update_interval) + +if __name__ == "__main__": + main() diff --git a/www/index.html b/www/index.html new file mode 100644 index 0000000..087b180 --- /dev/null +++ b/www/index.html @@ -0,0 +1,14 @@ + + + + + + +

MSV Webcam

+

You are connected!

+ + +still webcam image + + +