Why does my Pi Zero with Node-Red cannot take pictures

Hi, I am trying to take pictures with my Pi Zero and a simple Pi camera.
Flow is as below:

When I run it that is what I get on debug window:

object
_msgid: "d3493c077845a223"
payload: ""
topic: ""
filename: ""
fileformat: ""
filepath: ""

Now I tested the pi/camera from a pi terminal as below:

sudo raspistill -o testshot.jpg

And got:

-rw-r--r-- 1 root root 2415852 Sep 30 16:36 testshot.jpg

Have checked raspi-config and camera is enabled.

What might still be missing?

You could use an exec node configured with the raspistill command, for testing purposes. Which node exactly is the one that takes the picture (the one in the middle in your screenshot) ?

Do you really need sudo to run raspistill?
You are creating an image file owned by root, so any further processing of it, housekeeping etc, will need sudo as well.

1 Like

indeed - don't use sudo - it won't work inside an exec node either.

If it is this node - node-red-contrib-camerapi (node) - Node-RED - have you installed and checked the pre-reqs ?

1 Like

Hi, thanks for your feedback.
First I installed [node-red-contrib-camerapi ] from Node-Red manage palette, updated and run
sudo apt-get install python-picamera python3-picamera (according to instructions on: node-red-contrib-camerapi (node) - Node-RED and there is where I am now.

Now, what do you mean by not using sudo?
How I go back and repair it from where I am now?
Thanks

Just reinstalled the whole set:
Raspberry Pi, updated, Node-red, node-red-contrib-camerapi, updated again, sudo apt-get install python-picamera python3-picamera
Problem remains identical.
I must be missing something very simple, can't find a solution everywhere I looked.

A footnote on the instruction page I mention above says:
This node is tested on RASPBIAN (buster), Nodejs V12.x LTS and NPM 6.x on Node-Red 1.0.6
The script that installs Node-Red installed Nodejs v16.17.0
Installed NPM as well but no change.

You said "Now I tested the pi/camera from a pi terminal as below:"

sudo raspistill -o testshot.jpg

You used sudo to launch the command raspistill.
Apologies if you already know this but...
On the Bash command line you can run a command by just entering it's name.
For example the whoami command

pi@MyPi:~ $ whoami
pi

But sometimes the "pi"user does not have permission to use a command

pi@MyPi:~ $ fdisk -l
fdisk: cannot open /dev/sda: Permission denied
(etc)

So you can use sudo to run a command as the all powerfull "root" user
pi@MyPi:~ $ sudo whoami
root

Beginners occasionally think that they have to use sudo to run every command.
It is a really bad idea because your directories can get clogged up with files owned by root, whose presence can prevent normal operations.

Edit -
On your newly installed Pi run these commands:

cd 
raspistill -o anothertest.jpg
echo $?
ls -l anothertest.jpg

In Node-red, use an Exec node to execute raspistill -o yetanothertest.jpg
Use a debug node to show the returned message (the first output) and any error (the second output)

Show us the results
Does the file get created?

1 Like

That is me!
Thanks

Now, do you think this problem is caused by that?
In fact after I reinstalled everything I did not test the camera again.

I think what @jbudd is saying is try this command in a terminal window / command line...

raspistill -o testshot.jpg

And then perform an ls -al and see what the ownership is.

Just did that:

pi@picamera:~ $ raspistill -o testshot.jpg
pi@picamera:~ $ ls
testshot.jpg
pi@picamera:~ $ ls -l
total 2104
-rw-r--r-- 1 pi pi 2154070 Oct 1 16:11 testshot.jpg
pi@picamera:~ $

When I performed this test before I uploaded the testshot.jpg and chcked the image and it corresponds to what was expected.

Sorry, I did not know ls -al and used ls -l (that I am used to) but checked the info about this specific file was the same.

So that confirms that raspistill works without sudo.

I would expect that it works from Node-red using the exec node too.

If it does, then you can test the camerapi node.

Now, do you think this problem is caused by that?

It seems unlikely but it's not impossible.

And ls -al is the same as ls -l but it also shows ""hidden" files - those whose name starts with a dot

1 Like

ls -al means give me a long listing. Shows you the ownership, permissions, file size and creation date.

1 Like

pi@picamera:~ $ ls -l
total 4320
drwxr-xr-x 27 pi pi 4096 Oct 1 16:24 node_modules
-rw-r--r-- 1 pi pi 8338 Oct 1 16:24 package-lock.json
-rw-r--r-- 1 pi pi 2154070 Oct 1 16:11 testshot.jpg
-rw-r--r-- 1 pi pi 2251991 Oct 1 16:25 testshotNew.jpg

OK, it looks like the raspistill command doesn't give any useful success message - many Linux commands (deliberately) are silent if they succeed. So the empty output from the exec node isn't a sign of failure.

Probably the camerapi node actually calls raspistill, so it's blank output is not necessarily a bad sign either. But the node help does say this " msg.payload will give you the path and the filename including extension to the photo."
Has camerapi created an image file?

Has camerapi created an image file?

-rw-r--r-- 1 pi pi 2251991 Oct 1 16:25 testshotNew.jpg
Yes, it is there

That's the file created by the exec node. Same size, same time

You could try using a 'file-in' node and the image node to see if you can "see" the image you captured.
image_preview

Image preview node is... node-red-contrib-image-output (Really useful for doing quick tests).

You need to insert the path to where the file is located in the file-in node.
e.g. /home/pi/testshotNew.jpg

You also need to set the 'read-file' node settings to be a 'single Buffer object'
file_in_settings

Just to double check, which Rasberry Pi OS have you installed ? As far as I know the picamera library (which the installed node seems to use) would not run on 64-bits. So far we know that your hardware os good and you can capture picture with raspstill, which is good.

-rw-r--r-- 1 pi pi 2154070 Oct 1 16:11 testshot.jpg ------->from terminal prompt
-rw-r--r-- 1 pi pi 2251991 Oct 1 16:25 testshotNew.jpg ---> From Node-Red exec

Camera not precisely positioned in the same place .

So it would appear you have it working now?

Hi Andrei, did not know that.
I am rebuilding everything with 32bit Pi OS.
Thanks