I recently felt it was time to update my domoticz equipment and bought a Raspberry pi 4.
Previously I used a Raspberry pi 2 so its quite an upgrade.
I also got myself a Raspberry Pi 7" touchscreen for seeing status of my devices and also being able to control some lights.
I already have an e-Paper screen for showing some data, only its not a touchscreen no I can't control anything with it.
Because of the touchscreen I started looking into dashboards that will fit my needs.
My needs are quite simple
- See the status of the doors
- Control some of the lights in the room where the touchscreen will be located
- See the status of lights in other rooms
- See the Solar yield of my solar panels
- See the feed from my 4 camera's
I quickly noticed the following
- aurora is not worked on anymore
- video image refreshrate is 20 seconds
- Changing it to every second results in a flashing image
After searching around how to enable this custom page I found Dashticz. Because I am a lazy developer I rather use something that is already available instead of building it myself from scratch. (I am not a frontend devver)
Dashticz provides everything I need and I just done the automatic docker version and installed it on my raspberry pi 4. It handles the extra load without any problems.
While configuring Dashticz I came to nearly the same conclusion as with aurora. It just refreshes an image from an url. But because in Dashticz its in a image html element it does not flash while refreshing the image as in aurora. I played around with the refreshtime but could not get satisfactory results.
I started again to search around how to make the video feed realtime. After some hours I found a good working solution that is also free. I did find the Media Server software solutions that can convert the rtsp stream from my ip camera's to webrtc/websockets/etc. But I wasn't willing to pay the amount they charge.
Here is how I implemented it by using uv4l with the mjpegstream driver. I installed this also on the raspberry pi 4.
Too long didn't read. Start here if you skipped the story
Prerequisites
- Have a ip cam that sends a HTTP MJPEG stream
- Know the url to the MJPEG stream. Search the camera ui or documentation for it.
- Use basic authentication
Digest authentication should also be possible. I haven't spend any time on it yet.
Other type of stream might also work. I don't have a need to research it so I haven't spend time for that.
It needs a HTTP stream. One that is prefixed with rtsp:// did not work for me even when its MJPEG
My setup
- Raspberry pi 4 running domoticz and dashticz (Buster)
- 4x Y-cam Cube HD720 White
- Raspberry pi 3 with touchscreen for showing Dashticz dashboard (Buster)
Code: Select all
curl http://www.linux-projects.org/listing/uv4l_repo/lpkey.asc | sudo apt-key add -
Code: Select all
deb http://www.linux-projects.org/listing/uv4l_repo/raspbian/stretch stretch main
Code: Select all
sudo apt-get update
sudo apt-get install uv4l uv4l-server uv4l-mjpegstream
Code: Select all
uv4l --driver mjpegstream --auto-video_nr --uri "http://<username>:<password>@<ip/hostname camera>/live/1/mjpeg.jpg" --server-option '--user-password=<pasword for user>' --server-option '--port=9001' --server-option '--admin-password=<password for admin>'
Code: Select all
http://<username>:<password>@<ip/hostname>:9001/stream
- username is user (or admin)
- password is specified in the uv4l command: --server-option '--user-password=<pasword for user>' (Use the admin pwd if you use the admin user)
- hostname or ipaddress of the machine you ran the uv4l command on
When the test is successful, congratz you are nearly there!
Update your Dashticz CONFIG.js
Code: Select all
buttons.camera_garage = {
width: 6,
isimage: true,
refresh : 60000,
btnimage: 'http://user:<pwd>@<ip/host>:9002/stream/video.mjpeg'
}
- Here I used port 9002 because I got 4 camera's. Just make sure you use the correct port that matches how you have configured it.
- I still added the refresh to make sure it recovers itself when something happens
My findings
- 7" touchscreen only give very little space to work with
- A raspberry pi 3 cannot handle 4 streams of 1280 x 720 30 fps. It made the raspberry crash. I had to switch to the secondary lower quality stream.
- uv4l just passes along the stream without impacting resolution, image quality and fps.
So it does not work in Chrome because of cors.
The internal php cors solution does not handle streams.
I'll update it here when I find a solution. But I might just accept the fact that Chrome cannot be used or just disable the cors policy on chrome.
Update 2
I found a solution. In order to prevent cors problems I have put Dashticz and the video streams behind a nginx reverse proxy.
I will not explain here how to setup a nginx. But here is my configuration I have used.
Code: Select all
server {
listen 80;
server_name dashticz.local.lan;
location / {
proxy_pass http://<raspberrypi4 ip>:8082/;
access_log /var/log/nginx/dashticz.access.log;
error_log /var/log/nginx/dashticz.error.log;
}
location ~ ^/cam-([1-4])/ {
set $cam "$1";
rewrite /cam-[1-4]/(.*) /$1 break;
proxy_pass http://<raspberrypi4 ip>:900$cam;
proxy_set_header Authorization "Basic <The basic auth base64>";
access_log /var/log/nginx/dashticz.access.log;
error_log /var/log/nginx/dashticz.error.log;
}
}
The first location if for dashticz
The 2nd location handles the camera feeds.
it assumes that cam-1 uses port 9001, cam-2 port 9002, etc
In Dashticz you configure
Code: Select all
buttons.camera_voordeur_binnen = {
width: 6,
isimage: true,
refresh : 60000,
btnimage: 'http://dashticz.local.lan/cam-3/stream/video.mjpeg'
}