Using a RPI 3b+ to create a PT camera accessible through Windows browser and controllable through MQTT

Overview

web-camera_PT

A Web flask server converts the MJPEG stream from RPI to JPG img using opencv, then display in browser. Controls added to move Camera in Pan and Tilt directions by sending MQTT commands

Stuff Needed

  1. RPI 3B+ with Bullseye arm64 lite
  2. Raspberry Pi Camera v2.1
  3. Windows Machine

Setup in RPI

Check if libcamera works/stream setup correctly

  1. Create mjpeg stream
  2. View in windows machine using VLC

Creating mjpeg stream

Run this command on RPI, add -v to view verbose log

Send with 144p

libcamera-vid -t 0 --width 256 --height 144 -q 100 -n --codec mjpeg --inline --listen -o tcp://192.168.XX.XX:XXXX

Send with 240p

libcamera-vid -t 0 --width 352 --height 240 -q 100 -n --codec mjpeg --inline --listen -o tcp://192.168.XX.XX:XXXX

Send with 360p

libcamera-vid -t 0 --width 480 --height 360 -q 100 -n --codec mjpeg --inline --listen -o tcp://192.168.XX.XX:XXXX

Send with 480p (Fails! Not sure why)

libcamera-vid -t 0 --width 858 --height 480 -q 100 -n --codec mjpeg --inline --listen -o tcp://192.168.XX.XX:XXXX
XXX
terminate called after throwing an instance of 'std::runtime_error'
  what():  failed to send data on socket
Aborted

View in Windows using VLC

At this point, the mjpeg stream should be viewable from your Windows PC. Download vlc from https://www.videolan.org/vlc/download-windows.html Navigate to Media > Open Network Stream This is the stream address

tcp/mjpeg://192.168.XX.XXXX:XXXX

You should see the video stream, but it will have a 2 seconds delay. We can reduce this delay by using opencv to read the stream.

Create systemd to auto restart service

cd /lib/systemd/system/
sudo nano libcamera_stream.service
[Unit]
Description=Runs the Libcamera Streaming Service
After=multi-user.target

[Service]
Type=simple
ExecStart=libcamera-vid -t 0 --width 256 --height 144 -q 100 -n --codec mjpeg --inline --listen -o tcp://192.168.XX.XX:XXXX
Restart=on-abort

[Install]
WantedBy=multi-user.target
sudo chmod 644 /lib/systemd/system/libcamera_stream.service
sudo systemctl daemon-reload
sudo systemctl enable libcamera_stream.service
sudo systemctl start libcamera_stream.service
sudo systemctl status libcamera_stream.service

Setup in Windows

Setup Env Variables

Create var to store the address of the rpi Since I use venv, I edit my env/Scripts/activate with export ENV_VAR=XXX to create my env variable Or you can just do export MJPEG_ADDRESS=XXX everytime you create a new terminal

MJPEG_ADDRESS=192.168.XX.XXXX
MJPEG_PORT=XXXX

Install python libraries

Use pip to install flask and opencv-python

pip install flask
pip install opencv-python

If some libraries are missing, just check my requirements.txt

Check if opencv works

Run simple script to view image stream from opencv

python read_mjpeg_opencv.py 

Run Flask Server

Chrome does not support showing http mjpeg stream directly. (I think) To view stream in browser, need to convert the mjpeg stream into a browser compatible format The way I did it is to host a server that does the conversion from mjpeg stream into jpg. I wrote app.py that converts it into a constantly updating jpg image

python app_basic.py
$ python app_basic.py 
 * Serving Flask app 'app_basic' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://127.0.0.1:5000 (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 119-083-471
127.0.0.1 - - [08/May/2022 13:48:47] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [08/May/2022 13:48:47] "GET /static/style.css HTTP/1.1" 304 -
127.0.0.1 - - [08/May/2022 13:48:50] "GET /video_feed HTTP/1.1" 200 -

The site should be accessible on your localhost at http://127.0.0.1:5000

NOTE that if you refresh the page, libcamera will die and need to be restarted.

If you have already setup the systemd service to auto restart it then just need to just refresh the page twice every time.

You might also like...

🎒 Accessible and extremely useful website for public school in Poland, built on fun and modern stack.

🎒 Accessible and extremely useful website for public school in Poland, built on fun and modern stack.

✨ Strona Szkolna 🎯 Zadania · 💡 Pomysły Struktura 📁 apps 📁 backend: headless CMS (API) używający Strapi, które umożliwia dowolne typy contentu, np.

Dec 21, 2022

jQuery Tabs Plugin. CSS Tabs with Accessible and Responsive Design. Lot of Tab Themes with Vertical and Horizontal Orientation.

Macaw Tabs Macaw Tabs is jQuery tabs plugin. It helps you to create accessible and responsive jQuery tabs by implementing the W3 design patterns for t

Dec 8, 2022

A modern ebook manager and reader with sync and backup capacities for Windows, macOS, Linux and Web

A modern ebook manager and reader with sync and backup capacities for Windows, macOS, Linux and Web

简体中文 | English Koodo Reader A cross-platform ebook reader Download | Preview | Roadmap | Document Preview Feature Format support: EPUB (.epub) Scanned

Dec 29, 2022

Basic, accessible, responsive and freely restyleable tabs.

Skeletabs · Skeletabs is an open source jQuery plugin that provides tabbed browsing feature to your web contents. It is focused on accessibility and s

Nov 13, 2022

A prototype on how web3 technology can enable us to build an open, immutable, reproducible, and permanently accessible scientific record.

A prototype on how web3 technology can enable us to build an open, immutable, reproducible, and permanently accessible scientific record.

Web3 Research A prototype on how web3 technology can enable us to build an open, immutable, reproducible, and permanently accessible scientific record

Nov 27, 2022

A beautiful, responsive, highly customizable and accessible replacement for JavaScript's popup boxes. Zero dependencies.Alerts ,dialogs

AsgarAlert (v1) for JS Install script defer src="/asgar-alert.js"/script Examples The most basic message: asgar("Hello world!"); A message signali

Dec 20, 2022

Simple click-triggered navigation submenus. Accessible and progressively enhanced.

Clicky Menus! A project by Mark Root-Wiley, MRW Web Design Clicky Menus lets you create a progressively-enhanced, accessible one-level dropdown menu t

Dec 6, 2022

Smart Auto Move learns the size and position of your application windows and restores them to the correct place on subsequent launches. Supports GNOME Wayland.

Smart Auto Move learns the size and position of your application windows and restores them to the correct place on subsequent launches. Supports GNOME Wayland.

smart-auto-move smart-auto-move is a Gnome Shell extension which keeps track of all application windows and restores them to the previous position, si

Dec 23, 2022

Inter Process Communication Module for node supporting Unix sockets, TCP, TLS, and UDP. Giving lightning speed on Linux, Mac, and Windows. Neural Networking in Node.JS

Inter Process Communication Module for node supporting Unix sockets, TCP, TLS, and UDP. Giving lightning speed on Linux, Mac, and Windows. Neural Networking in Node.JS

Inter Process Communication Module for node supporting Unix sockets, TCP, TLS, and UDP. Giving lightning speed on Linux, Mac, and Windows. Neural Networking in Node.JS

Dec 9, 2022
Owner
null
A tool for collecting data and access camera, microphone and location and clipboard via link.

Snow Build malicious links. A tool for collecting data and access camera, microphone and location and clipboard via link.

Msf 14 Dec 12, 2022
Blockchain, Smart Contract, Ganache, Remix, Web3, Solidity, Java Script, MQTT, ESP32, RFID, DHT11,

Blockchain, Smart Contract, Ganache, Remix, Web3, Solidity, Java Script, MQTT, ESP32, RFID, DHT11,

Hajar OUAAROUCH 5 May 24, 2022
Camera plugin for Obsidian.md

Obsidian Camera Camera plugin for Obsidian(https://obsidian.md). Features Take photo and video recordings and have them saved in vault Create and past

Aldrin Jenson 13 Dec 23, 2022
MQTT broker that can run on any stream server

Nest.js MQTT broker that can run on any stream server Topics What is MQTT ? Installation Usage Handlers Events Methods Packets Middleware & Plugins De

Behnam Nasehi 6 Nov 26, 2022
This is an unofficial front end for Hacker News, reminiscent of the Windows XP era Outlook email client on a Windows XP default desktop

Hacker XP Hacker News styled as the Windows XP Outlook email client. Try out Hacker XP here! Description This is an unofficial front end for Hacker Ne

null 19 Jul 12, 2022
An open-source boat display cockpit for navigation, speed, heading, and tide tables running on Raspberry Pi and accessible as a webapp through any smartphone.

An open-source boat display cockpit for navigation, speed, heading, and tide tables running on Raspberry Pi and accessible as a webapp through any smartphone

Andy 44 Dec 30, 2022
🖼 A jQuery plugin to view images just like in Windows. Browser support IE7+!

⚠️ Attention! This repository will be maintained just in small iteration. The plugin is easy to use, but its customization can be troublesome. To impr

Zongbin 191 Dec 30, 2022
Journeys is a django based community-focused website that allows users to bookmark URLs (through chrome extension) and share their journeys through timelines.

Journeys is a django based community-focused website that allows users to bookmark URLs (through chrome extension) and share their journeys through timelines. A timeline is a collection of links that share a common topic or a journey of building and learning something new. Users can create timelines, share them publicly, and explore resources.

Students' Web Committee 14 Jun 13, 2022
Make drag-and-drop easier using DropPoint. Drag content without having to open side-by-side windows

Make drag-and-drop easier using DropPoint! DropPoint helps you drag content without having to open side-by-side windows Works on Windows, Linux and Ma

Sudev Suresh Sreedevi 391 Dec 29, 2022
Windows 11 clone made with 💛 using NextJS and TailwindCSS by Vishwa Gaurav.

Windows 11 Windows 11 made with ?? using NextJS and TailwindCSS by Vishwa Gaurav. ScreenShots *In Development Mode Our Social Links PageSpeed Insights

Vishwa Gaurav 29 Nov 9, 2022