From 5c6207f3bf859c6c5677364222b5968b752863ca Mon Sep 17 00:00:00 2001 From: Georgios Gerontakis Date: Mon, 20 Jan 2020 11:26:49 +0200 Subject: [PATCH] Adding service install to setup shell-script --- camera module/camera_module.service | 12 ++++++++++++ camera module/setup.sh | 7 +++++++ camera module/streamer.py | 29 ----------------------------- 3 files changed, 19 insertions(+), 29 deletions(-) create mode 100644 camera module/camera_module.service delete mode 100755 camera module/streamer.py diff --git a/camera module/camera_module.service b/camera module/camera_module.service new file mode 100644 index 0000000..a6220da --- /dev/null +++ b/camera module/camera_module.service @@ -0,0 +1,12 @@ +[Unit] +Description=Camera Module Service +After=multi-user.target +Conflicts=getty@tty1.service + +[Service] +Type=simple +ExecStart=/usr/bin/python3 /usr/bin/main.py +StandardInput=tty-force + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/camera module/setup.sh b/camera module/setup.sh index 2680651..8a59753 100755 --- a/camera module/setup.sh +++ b/camera module/setup.sh @@ -4,3 +4,10 @@ sudo apt install python3-pip sudo apt-get install rpi.gpio sudo apt-get install python3-opencv sudo pip3 install pyzmq +sudo cp servo.py /usr/bin/servo.py +sudo cp main.py /usr/bin/main.py +sudo cp camera_module.service /lib/systemd/system/camera_module.service +sudo systemctl daemon-reload +sudo systemctl enable camera_module.service +sudo systemctl start camera_module.service +sudo systemctl status camera_module.service \ No newline at end of file diff --git a/camera module/streamer.py b/camera module/streamer.py deleted file mode 100755 index 9875e63..0000000 --- a/camera module/streamer.py +++ /dev/null @@ -1,29 +0,0 @@ -import base64 -import cv2 -import zmq - -context = zmq.Context() - -socket = context.socket(zmq.REP) -socket.bind("tcp://*:4444") -while True: - client_ip = socket.recv() - break - -footage_socket = context.socket(zmq.PUB) -footage_socket.connect('tcp://' + client_ip.decode() + ':5555') - -camera = cv2.VideoCapture(0) # init the camera - -while True: - try: - grabbed, frame = camera.read() # grab the current frame - frame = cv2.resize(frame, (640, 480)) # resize the frame - encoded, buffer = cv2.imencode('.jpg', frame) - jpg_as_text = base64.b64encode(buffer) - footage_socket.send(jpg_as_text) - - except KeyboardInterrupt: - camera.release() - cv2.destroyAllWindows() - break