diff --git a/docs/SCRIPT.md b/docs/SCRIPT.md index 12e81a4..63584cf 100644 --- a/docs/SCRIPT.md +++ b/docs/SCRIPT.md @@ -45,4 +45,37 @@ sudo pip3 install -r requirements.txt - Start the security camera script with the following command: ```bash python3 main.py - ``` \ No newline at end of file + ``` + +## Install Node.js +- Install Node.js with the following commands: + 1. Update the Raspberry Pi + ```bash + sudo apt update + sudo apt upgrade + ``` + 2. Check the Node.js Version Available + ```bash + apt-cache policy nodejs + ``` + The output should look like this: + ```bash + pi@raspberrypizero2:~ $ apt-cache policy nodejs + nodejs: + Installed: (none) + Candidate: 12.22.12~dfsg-1~deb11u4 + Version table: + 12.22.12~dfsg-1~deb11u4 500 + 500 http://raspbian.raspberrypi.org/raspbian bullseye/main armhf Packages + ``` + The apt-cache policy nodejs command shows that Node.js version 12.22.12 is available for installation from the Raspberry Pi repositories, but it hasn't been installed (Installed: (none)). + 3. Install Node.JS and npm on the Raspberry Pi + ```bash + sudo apt install nodejs + sudo apt install npm + ``` + 4. Check the version + ```bash + nodejs -v # Checks Node.js version + npm -v # Checks npm version + ``` \ No newline at end of file diff --git a/main2.py b/main2.py index 1f80d90..49a6c32 100644 --- a/main2.py +++ b/main2.py @@ -40,6 +40,9 @@ # Initialize the camera camera = picamera.PiCamera() +camera.annotate_background = picamera.Color('black') +camera.resolution = (1920, 1080) +camera.framerate = 24 recording = False # Set up GPIO @@ -61,29 +64,22 @@ # Function to stream frames -def stream_frames(): - global should_stream_frames, streaming_running - streaming_running = True - - with picamera.PiCamera() as camera: - camera.resolution = (1920, 1080) - camera.framerate = 24 - stream = io.BytesIO() - - for _ in camera.capture_continuous(stream, 'jpeg', use_video_port=True): - if not should_stream_frames: - break +def stream_frames(camera): + global should_stream_frames + stream = io.BytesIO() - # Send frame - stream.seek(0) - buffer = stream.read() - if should_stream_frames: - ws.send(buffer, opcode=websocket.ABNF.OPCODE_BINARY) + for _ in camera.capture_continuous(stream, 'jpeg', use_video_port=True): + if not should_stream_frames: + break - stream.seek(0) - stream.truncate() + # Send frame + stream.seek(0) + buffer = stream.read() + if should_stream_frames: + ws.send(buffer, opcode=websocket.ABNF.OPCODE_BINARY) - streaming_running = False + stream.seek(0) + stream.truncate() # WebSocket handlers