Raspberry PI
- Start a script as a service
- Enable Filesharing
- Fix DNS (apt-get doesn't work)
- Enabled dual camera (Raspberry pi 5)
- Access files over HTTP quickly
- Set HTTPS to bypass browser constraints
- stream camera feed
- Fixing blurry 8-50mm Zoom Lens for Raspberry Pi High Quality Camera
Start a script as a service
sudo nano /etc/systemd/system/ptcam-app.service
Create an ini file
[Unit] Description=PanTilt Camera Web App After=network-online.target Wants=network-online.target [Service] User=sophior WorkingDirectory=/home/sophior/pt_rpi ExecStart=/home/sophior/pt_rpi/venv/bin/python -u /home/sophior/pt_rpi/app.py Restart=always RestartSec=5 [Install] WantedBy=multi-user.target
Start
sudo systemctl daemon-reload sudo systemctl enable ptcam-app.service sudo systemctl start ptcam-app.service
Check logs
journalctl -u ptcam-app.service -f
Stop/restart
sudo systemctl restart ptcam-app.service
sudo systemctl restart ptcam-headtracker.service
Enable Filesharing
Install samba
sudo apt update sudo apt install -y samba
Set password
sudo smbpasswd -a sophior
edit config
sudo nano /etc/samba/smb.conf [pt_rpi] path = /home/sophior/pt_rpi browseable = yes read only = no guest ok = no valid users = sophior force user = sophior create mask = 0664 directory mask = 0775
Restart Samba
sudo systemctl restart smbd
Fix DNS (apt-get doesn't work)
When apt-get update times out or you can't reach servers that you know are online
sudo rm -f /etc/resolv.conf
echo "nameserver 1.1.1.1" | sudo tee /etc/resolv.conf
echo "nameserver 8.8.8.8" | sudo tee -a /etc/resolv.conf
ping -c 2 deb.debian.org
Enabled dual camera (Raspberry pi 5)
When you can only see one of both cameras:
rpicam-hello --list-cameras
https://docs.arducam.com/Raspberry-Pi-Camera/Pivariety-Camera/Libcamera-User-Guide/#introduction 123 to do:
install_pivariety_pkgs.sh -p libcamera_dev
install_pivariety_pkgs.sh -p libcamera_apps
install_pivareity_pkgs.sh -p kernel_driver
Access files over HTTP quickly
python3 -m http.server 8080
Current folder will now be accessible over http
Set HTTPS to bypass browser constraints
cd ~/pt_rpi
openssl req -x509 -newkey rsa:2048 -nodes \
-keyout ssl.key \
-out ssl.crt \
-days 365 \
-subj "/CN=192.168.178.123"
socketio.run(
app,
host='0.0.0.0',
port=5000,
ssl_context=('ssl.crt', 'ssl.key'),
allow_unsafe_werkzeug=True
)
stream camera feed
Broadcast from Raspberry pi:
rpicam-vid --camera 0 --inline --width 2028 --height 1080 --listen --timeout 0 --profile high --intra 1 -o tcp://0.0.0.0:8888
Receive on PC:
ffplay -fflags nobuffer -flags low_delay -probesize 32 tcp://192.168.178.123:8888
Fixing blurry 8-50mm Zoom Lens for Raspberry Pi High Quality Camera
When you mounted the lense with C-mount, it might be that everything is extremely blurry.
To adjust it, might feel like a daunting task.
The issue is the focal point when you attach the lense too close to the sensor. For this, you have the lock-screw on the C-mount and should not screw in the lense all the way to the end.
Ideally you'd open a video stream and watch it with the near/far focal ring in the middle and the tele/wide ring in the middle.While you adjust the C-mount screw depth.
You'd want to reach a point where either focal rings will have impact on sharpness with very tiny mainpulations (1/10th of a mm will be blurry or not blurry).
You could make such a program and then refresh the page after every manipulation to focus the lens.
@app.route('/hq_snapshot')
def hq_snapshot():
path = "/tmp/hq_snapshot.jpg"
subprocess.run([
"rpicam-still",
"--camera", "0",
"--nopreview",
"--timeout", "300",
"--width", "1920",
"--height", "1080",
"-o", path
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
return send_file(path, mimetype="image/jpeg")
After you're done, lock the lockscrew.
Now, you should be able to focus with the focal rings, you'd set the tele/wide ring to approximately the object you want to have in focus and adjust the "near/far" until it becomes sharp.
Opeing the shutter (open/close) ring has some effect on sharpness or image bleed. It reduces or increases the amount of light that hits the sensor. In bright shiny days, fully open shutter will create fuzzy overexposed images.