Hello everyone,
I’m going to start modifying the camera module to add features, and before I start, I have a few questions:
I saw in blog articles about V4 that Gladys supports USB cameras, but I haven’t seen anywhere in the interface or documentation how to proceed. Is this really supported?
I would like to add a button on the camera box in the dashboard that will take us to the camera’s real-time stream. Is there a way to create additional pages in Gladys? (If there’s an example module that does this, I’d be happy to take a look )
I will also add native support for the official Raspberry Pi photo/camera module. For now, I see different ways to do this, but I haven’t studied these possibilities in detail yet:
A Docker container that launches (in the manner of the MQTT container) an RTSP server with the camera stream. The advantage is that we simply get the video stream from /dev/video0, so we could use other cameras (USB, CSI, etc.).
If you have other ideas about the camera module, don’t hesitate to share them. Once I know the module well, it will go faster
ps: I might be quite slow in making these changes. I’ve only been doing Python for about 2 years now, and I sometimes have long periods of unavailability due to my PhD.
In the documentation, I added this some time ago: USB Camera
Eventually, I unplugged my Logitech USB camera because Gladys was crashing regularly.
With the help of the community, we found that the problem was with the camera, which must have been drawing too much power from my Raspi. Since I unplugged it, everything has been running smoothly.
I wanted to test with a 220V-powered USB hub, but I haven’t done it yet.
Hmm how do you want to do that? I’m interested in your technical tip It’s a very technical subject, to be discussed before implementation.
You should know that in Gladys we want everything to go through Gladys on the Pi, we never connect from the browser to the devices directly, because we want all the home automation equipment not to be open on the internet (to stay secure), and that Gladys is the proxy between the user’s browser and the camera.
I have some ideas in mind on my side but it requires a lot of testing (real-time is very very resource-intensive).
I would rather favor this option, no need to pop a docker container that does exactly what this lib does
I must admit I haven’t finished testing yet, so I have no idea about the resources
I was thinking of retrieving the camera stream with the pi-camera-connect module and sending it to the client side with web-RTC instead of MJPEG, which seems much more resource-intensive if I understand correctly. The problem with web-RTC is that it requires a recent browser, I think
I’m not a fan of making a clean solution just for the Pi camera. If we want to add live streaming to cameras in Gladys, we might as well add it to all cameras In Gladys 4, the management of each « type of object » is native, we avoid making specific hacks for each device. This allows for deep integration (in discussions, the dashboard)
In fact, the mechanism we currently use for cameras could work in live mode (we use WebSockets, permanent connection so it’s efficient)
We just need to tweak the whole process to ensure that the image capture process is less than 100ms/50ms (to have 10/20 fps). WebSocket transport works perfectly with these latencies, the problem is more on the capture side.
After, from what I’ve seen in the pi-camera-connect library, they are within these times with this code:
import { StreamCamera, Codec } from "pi-camera-connect";
import * as fs from "fs";
const runApp = async () => {
const streamCamera = new StreamCamera({
codec: Codec.H264
});
const videoStream = streamCamera.createStream();
const writeStream = fs.createWriteStream("video-stream.h264");
// Pipe the video stream to our video file
videoStream.pipe(writeStream);
await streamCamera.startCapture();
// We can also listen to data events as they arrive
videoStream.on("data", data => console.log("New data", data));
videoStream.on("end", data => console.log("Video stream has ended"));
// Wait for 5 seconds
await new Promise(resolve => setTimeout(() => resolve(), 5000));
await streamCamera.stopCapture();
};
runApp();
In this example, you just need to send the data from videoStream.on(‹ data ›) to the front end via Gladys image capture functions. It will be propagated to the front end.
And all of this will work via the Gladys Gateway too!
Yes, you are completely right!
I’m starting to get the hang of their library, but I can’t get a development version of gladys running on a raspberry pi..
I had no issues with the installation and server launch, but when I try to launch the front end, I get a huge error:
Summary
You can view the application in browser.Local: http://localhost:1444
On Your Network: http://192.168.0.21:1444<— Last few GCs —>
fa[5372:0x20a9450] 260735 ms: Mark-sweep 222.0 (226.8) → 221.6 (226.8) MB, 433.3 / 0.2 ms (+ 43.5 ms in 7 steps since start of marking, biggest step 7.9 ms, walltime since start of marking 529 ms) (average mu = 0.175, current mu = 0.099) allocation fail[5372:0x20a9450] 261255 ms: Mark-sweep 221.9 (226.8) → 221.7 (226.8) MB, 459.6 / 0.1 ms (+ 25.9 ms in 6 steps since start of marking, biggest step 7.0 ms, walltime since start of marking 520 ms) (average mu = 0.123, current mu = 0.067) allocation fail<— JS stacktrace —>
==== JS stack trace =========================================
0: ExitFrame [pc: 0xee3360]
Security context: 0x3984ea21
1: fnModule(aka fnModule) [0x30b9091d] [/home/pi/gladys/front/node_modules/webpack/lib/Stats.js:~321] [pc=0x32d449d4](this=0x56f40279 ,0x568ecead )
2: map [0x3984716d](this=0x2b67f10d <JSArray[1144]>,0x30b9091d <JSFunction fnModule (sfi = 0x4d7457fd)>)
3: /* anonymous /(aka / anonymous */) [0x30b9163d] [/hom…FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Aborted
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! gladys-front@ start:development: npm run -s dev
npm ERR! Exit status 134
npm ERR!
npm ERR! Failed at the gladys-front@ start:development script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/pi/.npm/_logs/2020-11-21T17_16_06_339Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! gladys-front@ start: per-env
npm ERR! Exit status 134
npm ERR!
npm ERR! Failed at the gladys-front@ start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/pi/.npm/_logs/2020-11-21T17_16_06_432Z-debug.log
Any ideas @pierre-gilles to launch the front end on my test raspberry?
The stack trace says « out of memory » error, there’s probably no more RAM available on your Pi.
Running the dev front end on the Pi is ambitious. At most, you could run the back end on the Pi (lighter), and the front end on your laptop, and point the front end to the Pi’s back end.
Launching the front in dev mode is launching webpack (a very, very heavy JS tool that does live transpilation and hot reload), it’s unfortunately very resource-intensive ^^ You’ll let us know.
Otherwise, unrelated, but someone converted ffmpeg to WASM to be able to use ffmpeg natively in Node.js.
It’s only possible for now with experimental flags, but it’s very promising and as soon as it’s possible without flags it will surely allow us to have the performance we are looking for for live.
There is codecov/patch that didn’t pass and asks me to add tests but I don’t know what to add, I don’t see how to test only the few lines I added to the file server/services/rtsp-camera/lib/getImage.js
@pierre-gilles What do you advise for this test to pass?
As you can see in your file (the coverage summary): Codecov
The coverage says (in red) that the tests do not go through the if statement you added if (cameraUrlParam.value === 'pi-camera') {
So the idea is to manually add a device where the cameraUrlParam.value is equal to pi-camera.
Hello everyone,
I have a Chinese camera that is compatible with RTSP stream, but here’s the thing, when I install it on my smartphone with the Yosee app, I no longer have access to the camera stream on Gladys. Is this normal, or am I not using the correct video stream? Here is my stream: rtsp://admin:pwd@192.168.1.100:554/onvif1. (I have indeed replaced the admin and the pwd). With this stream, I do get an image, but either on Yosee or on Gladys. It’s a Kerui Z05H-20 camera.
Thank you for your help
@Psoy It would be worth checking the model online to see if other users have similar issues, it seems like the camera can only handle a single stream
Otherwise, you can connect it only to Gladys, and view the stream on your phone or via the Telegram integration (in mode: « Show me the living room camera » I don’t know if you’ve already tested it)
I didn’t specify, but it’s a motorized camera and I need the app. But I wanted to know if single-stream cameras exist, or if I’m not taking the right stream.
I don’t necessarily think it’s a « single-stream » camera, I think it’s a fairly low-end camera with very little power, and therefore it can’t respond quickly enough to 2 clients at the same time!
Thank you Pierre Gilles,
I did some research on the streams, but I didn’t come across the topics you found. I thank you again for the time you give us. I will delve deeper into this
Have a nice day