Skip to content

Instantly share code, notes, and snippets.

@dceejay
Created February 27, 2018 11:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dceejay/2b6c2f0d7a316f1a6831782d33a0d40c to your computer and use it in GitHub Desktop.
Save dceejay/2b6c2f0d7a316f1a6831782d33a0d40c to your computer and use it in GitHub Desktop.
Pi Camera Stills to Dashboard

A simple flow to grab a still image from a directly attached Pi Camera (using raspistill) and push it to a ui_template widget on a dashboard.

[{"id":"56677cb7.9840b4","type":"inject","z":"6fd852c2.a76acc","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":110,"y":160,"wires":[["f7696701.4cf1e8"]]},{"id":"f7696701.4cf1e8","type":"exec","z":"6fd852c2.a76acc","command":"raspistill","addpay":false,"append":"-w 320 -h 240 -o -","useSpawn":"false","timer":"","oldrc":false,"name":"","x":240,"y":160,"wires":[["e7f06c8d.c0a3b"],[],[]]},{"id":"e7f06c8d.c0a3b","type":"base64","z":"6fd852c2.a76acc","name":"","action":"str","property":"payload","x":400,"y":160,"wires":[["9e6ed9dc.f64ba8"]]},{"id":"9e6ed9dc.f64ba8","type":"template","z":"6fd852c2.a76acc","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<img width=\"320px\" height=\"240px\" src=\"data:image/jpg;base64,{{{payload}}}\">","output":"str","x":530,"y":160,"wires":[["28439a97.39e7a6"]]},{"id":"28439a97.39e7a6","type":"ui_template","z":"6fd852c2.a76acc","group":"c7a43587.2944e8","name":"","order":0,"width":"6","height":"5","format":"<div ng-bind-html=\"msg.payload\"></div>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":660,"y":160,"wires":[[]]},{"id":"c7a43587.2944e8","type":"ui_group","z":"","name":"Default","tab":"fbd536a.22bf9c8","disp":true,"width":"6","collapse":false},{"id":"fbd536a.22bf9c8","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]
@baqwas
Copy link

baqwas commented Jan 28, 2020

Hello @dceejay,

Don't know whether this would be a better place to post this inquiry (or the Node-RED forum) but let me give it a try at at least.

I followed your example above as follows:

[{"id":"42405e4c.fd92f8","type":"inject","z":"79d93680.e2a8a8","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":130,"y":180,"wires":[["e657e835.dd7678"]]},{"id":"e657e835.dd7678","type":"exec","z":"79d93680.e2a8a8","command":"raspistill","addpay":false,"append":"-w 320 -h 240 -o -","useSpawn":"false","timer":"","oldrc":false,"name":"","x":300,"y":180,"wires":[["be7eadbb.841a1"],[],[]]},{"id":"be7eadbb.841a1","type":"base64","z":"79d93680.e2a8a8","name":"","action":"str","property":"payload","x":540,"y":180,"wires":[["b90914f7.24b718"]]},{"id":"b90914f7.24b718","type":"template","z":"79d93680.e2a8a8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<img width=\"320px\" height=\"240px\" src=\"data:image/jpg;base64,{{{payload}}}\">","output":"str","x":740,"y":180,"wires":[["98ec9daa.0d285"]]},{"id":"98ec9daa.0d285","type":"ui_template","z":"79d93680.e2a8a8","group":"c7a43587.2944e8","name":"","order":0,"width":"6","height":"5","format":"<div ng-bind-html=\"msg.payload\"></div>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":960,"y":180,"wires":[[]]}]

After I click the Inject node, I receive an Error: 70 status message at the raspistill node.

My platform is running Buster with latest update/upgrades as follows:

`$ uname -a
Linux raspbari1 4.19.93+ #1290 Fri Jan 10 16:34:37 GMT 2020 armv6l GNU/Linux
pi@raspbari1:~ $ cat /proc/cpuinfo
processor : 0
model name : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS : 697.95
Features : half thumb fastmult vfp edsp java tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xb76
CPU revision : 7

Hardware : BCM2835
Revision : 0010
Serial :
Model : Raspberry Pi Model B Plus Rev 1.2
$
`
When I run raspistill from the command line, I get the following error messages at the tail of the output:

mmal: mmal_vc_component_enable: failed to enable component: ENOSPC mmal: camera component couldn't be enabled mmal: main: Failed to create camera component mmal: Failed to run camera app. Please check for firmware updates
The camera interface has been set (verified from raspi-config and Preferences/Interface UI) and the cable connection is tight. I know that the issue is at my end but if you can provide some alternate debug ideas, I would appreciate it very much.

Kind regards.

@dceejay
Copy link
Author

dceejay commented Jan 29, 2020

Well looks like the camera isn't working correctly... did you try googling that error ? ENOSPC mmal

eg
https://raspberrypi.stackexchange.com/questions/13764/what-causes-enospc-error-when-using-the-raspberry-pi-camera-module

@baqwas
Copy link

baqwas commented Jan 30, 2020

Yes! Operator error!!! Sorry for the bad report on my part that wasted a few cycles at your end.

I forgot all about motion (running as a service) that I had installed for a comparison test. I attributed the always on LED to some 3rd party (pan-tilt servoblaster) driver issue. After stopping the motion service (and the LED went off :)), the flow (your suggested demo test) started working. I've now connected the PIR sensor too as a trigger.

I was trying to self-study a [tutorial](Developing a Machine Learning IoT App with Node-RED and TensorFlow.js). I have a Rube Goldberg solution on the same box (my first RPi with OpenCV/MariaDB/multi-server/etc.) and I had installed TensorFlowLite previously with some workarounds but this article looked like a good opportunity to practice some N-R and with your help I'm back on track.

Appreciate the follow up. Kind regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment