Node or nodes which takes pictures with an ip camera with username and password each time when it have an request

Hello.
I'm new on Node-RED and I don't know how it works all nodes.
I want to take a picture with an IP camera and save it in (ex: /home/pi/Pictures foleder) on Raspberry each time when I have an request from an "rpi-gpio in node" or an "inject node" with the same name and overwrite it each time.
The problem is that when I'm accessing the camera IP with my laptop for ex, I need to use a username and password and I don't know how to insert them with nodes. (I have an dahua camera)
Can somebody tell me if it's possible and how can I do it?

Thank in advance !!!

It depends on what you camera supports. The brand I have support RTSP and with that you can use the live stream like this rtsp://84.27.12.000:554/user=admin&password=123456&channel=1&stream=0.sdp?
Note, the url is not for all the camera's the same. Read you manual or google for it.

Bart made a nice example in this topic how to capture 1 frame from the stream;

This works great for me.

And here is a discussion how to overlay text over your image; Overlay text onto image

1 Like

I'm pretty sure they use digest authentication.

Try a http request node with digest authentication set.

Inject>http request node>debug

See what comes back.

1 Like

I'm getting something like :
buffer[48]
[0 … 9]
[10 … 19]
...
and in this case where is image stored?

The buffer you’re seeing is the data representing the image.

P.S. Here is some extra information from Vlad about his project, to make sure everybody can see the whole 'picture' :wink:

The idea of all those things are that I create a project with openalpr which open my gates by processing my license plate using a raspberry pi and it's camera, but that camera has a low quality and it doesn't work when is very sunny because of reflections and I want to use a IP camera instead, or a CCTV digital camera but I think it's easier with an IP one.
I Followed this tutorial for this project: Car Plate Recognition System with Raspberry Pi and Node-RED | Random Nerd Tutorials

The others have already given good information, but will try to summarize it:

  1. You inject a random message to start the image capture
  2. Via a http-request node you can capture an image from the ip camera. Enter the snapshot url from your camera (you need to have a look in the manual because it differs from device to device). As Steve explained a lot of camera's use digest authentication, but some use basic authentication. Pick whatever your need ... The output should return a Buffer (see last option) in the msg.payload, not a string!!!!
  3. The file node will write the msg.payload to the specified file path.

When you want to do license plate recognition, you can add a wire from the output (of the http-request node) to the input of one of the following nodes:

I wrote the openalpr node a few years ago, and it is based on some older technology. Personally I would use the plate-recognizer node, which has very good recognition results! Please look on this forum and on my readme page for examples of the plate-recognizer node. It should be enough information to get started...

1 Like

It's really helpful, Thank you a lot !!!

I tried with your example and when I'm trying to open the image or to use "image info node" I'm getting this error : ("Unknown image format: TypeError: unsupported file type: undefined (file: undefined)") ... I tried to use also a "base64 converter" node " edit image node" and I couldn't get a different result. Should I have something installed on my raspberry, like an IP camera viewer software? Because I can't also to see what my cameras can see from raspberry, only from Windows because I have installed some plug-ins but I couldn't find them for ubuntu..

For an ip cam nothing extra is needed. Can you please share your flow (see here).

[{"id":"23795431.4338cc","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"716ae1e9.9f25c","type":"inject","z":"23795431.4338cc","name":"Start","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":90,"y":40,"wires":[["7391a304.a462ec"]]},{"id":"38cd9ebd.6db0f2","type":"file","z":"23795431.4338cc","name":"111111","filename":"/home/pi/Pictures/bun/image.jpg","appendNewline":false,"createDir":true,"overwriteFile":"true","encoding":"none","x":110,"y":200,"wires":[["43298460.6b3a1c"]]},{"id":"43298460.6b3a1c","type":"debug","z":"23795431.4338cc","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":130,"y":260,"wires":[]},{"id":"c407c8c7.56cfe8","type":"debug","z":"23795431.4338cc","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":330,"y":140,"wires":[]},{"id":"7391a304.a462ec","type":"http request","z":"23795431.4338cc","name":"camera image request","method":"GET","ret":"bin","paytoqs":false,"url":"http://192.168.0.111","tls":"","persist":false,"proxy":"","authType":"digest","x":160,"y":80,"wires":[["55489135.56b5b","a907b3dc.36c0d","c407c8c7.56cfe8","38cd9ebd.6db0f2"]]},{"id":"55489135.56b5b","type":"moment","z":"23795431.4338cc","d":true,"name":"","topic":"","input":"headers.date","inputType":"msg","inTz":"Etc/GMT+2","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYYMMDD hhmmss","locale":"C","output":"datetimeFormatted","outputType":"msg","outTz":"America/Winnipeg","x":440,"y":60,"wires":[[]],"info":"tried to find the timezone code for 0\nhttps://github.com/moment/moment-timezone/blob/develop/data/packed/latest.json\nand convert to local"},{"id":"a907b3dc.36c0d","type":"base64","z":"23795431.4338cc","d":true,"name":"","action":"","property":"payload","x":120,"y":140,"wires":[["38cd9ebd.6db0f2"]]}]

and

[{"id":"7560039.90485fc","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"c7028be8.634588","type":"jimp-image","z":"7560039.90485fc","name":"Kitten from placekitten.com","data":"payload","dataType":"str","ret":"img","parameter1":"","parameter1Type":"msg","parameter2":"","parameter2Type":"msg","parameter3":"","parameter3Type":"msg","parameter4":"","parameter4Type":"msg","parameter5":"","parameter5Type":"msg","parameter6":"","parameter6Type":"msg","parameter7":"","parameter7Type":"msg","parameter8":"","parameter8Type":"msg","parameterCount":0,"jimpFunction":"none","selectedJimpFunction":{"name":"none","fn":"none","description":"Just loads the image.","parameters":[]},"x":240,"y":180,"wires":[["abdc5ac3.f453f8","99335dc4.d6255"]]},{"id":"d2e9a3fb.d848b","type":"http request","z":"7560039.90485fc","name":"camera image request","method":"GET","ret":"bin","paytoqs":false,"url":"http://192.168.0.111","tls":"","persist":false,"proxy":"","authType":"basic","x":380,"y":120,"wires":[["21c61fde.46433","934d0469.063648"]]},{"id":"c55bb245.83d01","type":"inject","z":"7560039.90485fc","name":"Start","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":330,"y":40,"wires":[["d2e9a3fb.d848b"]]},{"id":"21c61fde.46433","type":"base64","z":"7560039.90485fc","name":"","action":"","property":"payload","x":640,"y":160,"wires":[["c7028be8.634588","8ce0658b.7227f8"]]},{"id":"abdc5ac3.f453f8","type":"debug","z":"7560039.90485fc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":490,"y":240,"wires":[]},{"id":"934d0469.063648","type":"image-info","z":"7560039.90485fc","name":"","x":650,"y":60,"wires":[[]]},{"id":"8ce0658b.7227f8","type":"imageSimple","z":"7560039.90485fc","imageData":"payload","imageType":"str","autoresize":false,"original":true,"localfile":false,"flipX":false,"flipY":false,"width":200,"height":200,"rotate":0,"crop":false,"cropX":0,"cropY":0,"cropWidth":200,"cropHeight":200,"x":540,"y":360,"wires":[[]]},{"id":"99335dc4.d6255","type":"jimp-image","z":"7560039.90485fc","name":"Set Quality 90%","data":"payload","dataType":"msg","ret":"img","parameter1":"99","parameter1Type":"num","parameter2":"true","parameter2Type":"bool","parameter3":"0","parameter3Type":"str","parameter4":"RESIZE_NEAREST_NEIGHBOR","parameter4Type":"Jimp","parameter5":"","parameter5Type":"","parameter6":"","parameter6Type":"","parameter7":"","parameter7Type":"","parameter8":"","parameter8Type":"","parameterCount":1,"jimpFunction":"quality","selectedJimpFunction":{"name":"quality","fn":"quality","description":"Set the quality of the image. Useful for reducing size of image before calling the write function.","parameters":[{"name":"quality","type":"num","required":true,"hint":"Quality value 1 ~ 100"}]},"x":180,"y":260,"wires":[["f7d319d6.6ba548","abdc5ac3.f453f8"]],"icon":"font-awesome/fa-image"},{"id":"f7d319d6.6ba548","type":"image viewer","z":"7560039.90485fc","name":"","width":"200","data":"payload","dataType":"msg","x":190,"y":340,"wires":[[]]}]

In one flow you use basic authentication, in the other flow you use digest authentication. If you don't setup your authentication (with username/password) correctly, there will never be a valid image in the output of the http-request node...

Add a node-red-contrib-image-output after your http-request node. As long as you don't have an image previewed there, it has no use to add all kind of image processing nodes in your flow. You have to focus on the http-request node only at this point. When you don't enter the correct security settings there, nothing will ever work ...

Not sure at all what you are doing here...

As @BartButenaers says, keep is simple.
e.g.
image

[{"id":"ffb8a714.ea9888","type":"http request","z":"4d512b28.912bc4","name":"camera image request","method":"GET","ret":"bin","paytoqs":false,"url":"https://picsum.photos/200/300","tls":"","persist":false,"proxy":"","authType":"","x":380,"y":120,"wires":[["1f1afe2.af8eb02"]]},{"id":"d2c53e2b.f0046","type":"inject","z":"4d512b28.912bc4","name":"Start","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":190,"y":120,"wires":[["ffb8a714.ea9888"]]},{"id":"1f1afe2.af8eb02","type":"image viewer","z":"4d512b28.912bc4","name":"","width":"200","data":"payload","dataType":"msg","x":590,"y":120,"wires":[[]]}]

Then you can get more adventurous...

[{"id":"ffb8a714.ea9888","type":"http request","z":"4d512b28.912bc4","name":"camera image request","method":"GET","ret":"bin","paytoqs":false,"url":"https://picsum.photos/200/300","tls":"","persist":false,"proxy":"","authType":"","x":380,"y":120,"wires":[["733d290b.b183d8","55aaaa98.bce024"]]},{"id":"d2c53e2b.f0046","type":"inject","z":"4d512b28.912bc4","name":"Start","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":190,"y":120,"wires":[["ffb8a714.ea9888"]]},{"id":"1f1afe2.af8eb02","type":"image viewer","z":"4d512b28.912bc4","name":"","width":"200","data":"payload","dataType":"msg","x":870,"y":120,"wires":[[]]},{"id":"733d290b.b183d8","type":"jimp-image","z":"4d512b28.912bc4","name":"","data":"payload","dataType":"msg","ret":"img","parameter1":"45","parameter1Type":"num","parameter2":"RESIZE_NEAREST_NEIGHBOR","parameter2Type":"resizeMode","parameter3":"","parameter3Type":"msg","parameter4":"","parameter4Type":"msg","parameter5":"","parameter5Type":"msg","parameter6":"","parameter6Type":"msg","parameter7":"","parameter7Type":"msg","parameter8":"","parameter8Type":"msg","parameterCount":2,"jimpFunction":"rotate","selectedJimpFunction":{"name":"rotate","fn":"rotate","description":"rotate the image clockwise by a number of degrees. Optionally, a resize mode can be passed. If `false` is passed as the second parameter, the image width and height will not be resized.","parameters":[{"name":"deg","type":"num","required":true,"hint":"the number of degrees to rotate the image by"},{"name":"mode","type":"resizeMode|bool","required":false,"hint":"resize mode or a boolean, if false then the width and height of the image will not be changed"}]},"x":570,"y":120,"wires":[["a03d832d.0ec7","730f902c.24f16"]]},{"id":"a03d832d.0ec7","type":"jimp-image","z":"4d512b28.912bc4","name":"","data":"payload","dataType":"msg","ret":"img","parameter1":"3","parameter1Type":"num","parameter2":"RESIZE_NEAREST_NEIGHBOR","parameter2Type":"none","parameter3":"","parameter3Type":"none","parameter4":"","parameter4Type":"none","parameter5":"","parameter5Type":"none","parameter6":"","parameter6Type":"msg","parameter7":"","parameter7Type":"msg","parameter8":"","parameter8Type":"msg","parameterCount":1,"jimpFunction":"blur","selectedJimpFunction":{"name":"blur","fn":"blur","description":"fast blur the image by r pixels","parameters":[{"name":"r","type":"num","required":true,"hint":"the pixel radius of the blur"}]},"x":710,"y":120,"wires":[["1f1afe2.af8eb02"]]},{"id":"730f902c.24f16","type":"image viewer","z":"4d512b28.912bc4","name":"","width":"200","data":"payload","dataType":"msg","x":670,"y":240,"wires":[[]]},{"id":"55aaaa98.bce024","type":"image viewer","z":"4d512b28.912bc4","name":"","width":"200","data":"payload","dataType":"msg","x":530,"y":400,"wires":[[]]}]
1 Like

I tried with basic and digest to check both ways if it's working...
I set usernam and Password as I set them for accessing the camera.

[{"id":"535ad2b6.10ba0c","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"29229f97.984c4","type":"base64","z":"535ad2b6.10ba0c","name":"Encode","x":420,"y":40,"wires":[["e7e9e370.3f42","8f7d82e0.49da2"]]},{"id":"699e2847.a6d938","type":"http request","z":"535ad2b6.10ba0c","name":"","method":"GET","ret":"bin","paytoqs":false,"url":"http://192.168.0.111","tls":"","persist":false,"proxy":"","authType":"digest","x":237.63544845581055,"y":39.39583969116211,"wires":[["29229f97.984c4"]]},{"id":"e7e9e370.3f42","type":"ui_template","z":"535ad2b6.10ba0c","group":"8176f0be.ba7bf","name":"Display image","order":1,"width":"6","height":"6","format":"<img width=\"16\" height=\"16\" alt=\"mjpeg test...\" src=\"data:image/jpg;base64,{{msg.payload}}\" />\n","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":620,"y":40,"wires":[[]]},{"id":"d1f1fddf.1f68e","type":"inject","z":"535ad2b6.10ba0c","name":"Start","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":90,"y":40,"wires":[["699e2847.a6d938"]]},{"id":"6eb9bb6b.3539c4","type":"http request","z":"535ad2b6.10ba0c","name":"","method":"GET","ret":"bin","paytoqs":false,"url":"http://192.168.0.111","tls":"","persist":false,"proxy":"","authType":"digest","x":270,"y":140,"wires":[["d565baf1.afdb08","25c047cd.5a8628"]]},{"id":"d565baf1.afdb08","type":"image","z":"535ad2b6.10ba0c","name":"","width":160,"data":"payload","dataType":"msg","thumbnail":false,"active":true,"pass":false,"outputs":0,"x":540,"y":140,"wires":[]},{"id":"eddea2ac.181f3","type":"inject","z":"535ad2b6.10ba0c","name":"Start","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":90,"y":140,"wires":[["6eb9bb6b.3539c4"]]},{"id":"ed5f0030.4f33a","type":"image viewer","z":"535ad2b6.10ba0c","name":"","width":"200","data":"payload","dataType":"msg","x":470,"y":260,"wires":[[]]},{"id":"3301f248.97339e","type":"http request","z":"535ad2b6.10ba0c","name":"","method":"GET","ret":"bin","paytoqs":false,"url":"http://192.168.0.111","tls":"","persist":false,"proxy":"","authType":"digest","x":270,"y":260,"wires":[["ed5f0030.4f33a","365d95a.b4a926a"]]},{"id":"104aa59d.1826ea","type":"inject","z":"535ad2b6.10ba0c","name":"Start","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":90,"y":260,"wires":[["3301f248.97339e"]]},{"id":"8f7d82e0.49da2","type":"debug","z":"535ad2b6.10ba0c","name":"First tried","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":740,"y":100,"wires":[]},{"id":"25c047cd.5a8628","type":"debug","z":"535ad2b6.10ba0c","name":"second tried","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":720,"y":240,"wires":[]},{"id":"365d95a.b4a926a","type":"debug","z":"535ad2b6.10ba0c","name":"third tried","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":650,"y":340,"wires":[]},{"id":"8176f0be.ba7bf","type":"ui_group","z":"535ad2b6.10ba0c","name":"Kitchen","tab":"6334a962.ce9008","order":1,"disp":true,"width":"6"},{"id":"6334a962.ce9008","type":"ui_tab","z":"535ad2b6.10ba0c","name":"Cameras","icon":"camera_alt","order":2}]

Capture1

And you are sur that the url in the http request node returns an image? Because a buffer of size 341 seems so small. When you enter that same url (which you have used in the http-request node) in your browser's address bar, then your browser shows an image from your camera?

that data is NOT an image.

I believe 77u/ is XML.

Its certainly NOT an image mime type.

My guess is you are not accessing the correct URL of the camera.

try these URLs...

1 Like