inital working version
This commit is contained in:
parent
219bb304a9
commit
9e4a217b5f
26
README.md
26
README.md
@ -1,2 +1,28 @@
|
|||||||
# msv-webcam-backend
|
# 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;
|
||||||
|
}
|
||||||
|
8
config.py
Normal file
8
config.py
Normal file
@ -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
|
14
msv-webcam-backend.service
Normal file
14
msv-webcam-backend.service
Normal file
@ -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
|
55
msv_webcam_backend.py
Normal file
55
msv_webcam_backend.py
Normal file
@ -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()
|
14
www/index.html
Normal file
14
www/index.html
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<meta http-equiv="refresh" content="5" />
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>MSV Webcam</h1>
|
||||||
|
<p>You are connected!</p>
|
||||||
|
|
||||||
|
|
||||||
|
<img src="data/still.jpg" alt="still webcam image">
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user