Take webcam image and tweet using Node-red

3,690 views
Skip to first unread message

Sumit Puri

unread,
Oct 3, 2015, 11:36:54 AM10/3/15
to Node-RED
Using Node-red, how can I have function to capture an image from webcam and get it tweeted? 

Nicholas O'Leary

unread,
Oct 3, 2015, 11:39:13 AM10/3/15
to Node-RED

If you let us know what you've tried, we can help fill in the gaps. Start by breaking the problem down into discrete steps and think about what nodes can help you achieve each step.

Nick


On Sat, 3 Oct 2015 16:36 Sumit Puri <er.sum...@gmail.com> wrote:
Using Node-red, how can I have function to capture an image from webcam and get it tweeted? 

--
http://nodered.org
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sumit Puri

unread,
Oct 3, 2015, 2:34:55 PM10/3/15
to Node-RED
I have the html code that does the same. See this- http://jsbin.com/dipalufuga/edit?html,output

I also have the node-red flow as shown below.  

So the step I am missing is how to extract the javascript part from the above html code and place it into my function node?

Nicholas O'Leary

unread,
Oct 3, 2015, 2:44:16 PM10/3/15
to Node-RED

The code you link to is for capturing images from a webcam in the browser.

A Node-RED flow runs in node.js runtime, not in the browser where you are editing the flow. So that code is not going to help.

A common pattern for capturing an image from a webcam is to use the Exec node to run whatever command line tool exists to trigger the webcam, then use the file node to load whatever file that tool created.

Nick

Dave C-J

unread,
Oct 3, 2015, 3:10:35 PM10/3/15
to node...@googlegroups.com

... Or to use an http request to get a picture using a web call to the camera then a function and/or change node to setup the correct parameters for the tweet... Depends on whether the camera is network attached our local to the PC.

Sumit Puri

unread,
Oct 3, 2015, 4:56:04 PM10/3/15
to Node-RED
It makes sense now.. I tried the same using inject -> Exec -> File ->Tweet

And I think I am close- it did tweet the image in text format. I also got the error that truncated tweet longer than 140 characters.

I am using Node-red on Raspberry Pi. The webcam is attached to USB port on Raspberry Pi. From the terminal, the command is >fswebcam sumit.jpg  where "sumit.jpg" is the filename. 

The screenshots for Exec and File nodes are below. In the File node, I also tried changing it to Buffer instead of UTF8 string, then I got this error in the debug- HTTP Error 401: Unauthorized, API, code 32, message "could not authenticate you".


Sumit

Nicholas O'Leary

unread,
Oct 3, 2015, 5:00:06 PM10/3/15
to Node-RED Mailing LIst
From the help text of the twitter out node:

    Tweets the msg.payload.
    If msg.media exists and is a Buffer object, this node will treat it as an image and attach it to the tweet.

The File In node loads the file into msg.payload. You need to use a Change node to move the that over to msg.media and then set msg.payload to whatever text you want to appear with the image.

Dave C-J

unread,
Oct 3, 2015, 5:01:42 PM10/3/15
to node...@googlegroups.com

Have you read the info page or the tweet node. It tells you what property the image needs to be called. So you will need a function or change node to rename the msg.payload property to msg.media

Sumit Puri

unread,
Oct 3, 2015, 5:20:00 PM10/3/15
to Node-RED
Awesome!!! It worked.. :)  Thank you very much.. this is my first-ever RaspberryPi project..!! really happy to make this work!! 

Nicholas O'Leary

unread,
Oct 3, 2015, 5:20:42 PM10/3/15
to Node-RED Mailing LIst
Well done!

Dave C-J

unread,
Oct 3, 2015, 5:59:30 PM10/3/15
to node...@googlegroups.com

Great stuff ! Feel free to share it on flows.nodered.org !

Sumit Puri

unread,
Oct 4, 2015, 2:12:12 PM10/4/15
to Node-RED
Hi Dave, I have posted my flow here- https://gist.github.com/sumitpuri/3acea22db01b2b76d46d

Dave I was thinking to experiment your method of using HTTP request to call web camera and then use function to send tweet. Do you have any pointers on how that http request can be made, I did not find much on the web. I am using raspberry pi and webcam is connected to it as USB. 

Dave C-J

unread,
Oct 4, 2015, 2:31:24 PM10/4/15
to node...@googlegroups.com
Hi Sumit

Excellent- thanks - I'm sure others will find that useful .

if it's a USB web cam then it much easier to do what you are doing...  It may also come with some software to turn the Pi into a web server to make it into a webcam then you could possibly grab it from that web server application... - but I'd stick with the simple local grab if it's all on the same Pi.

Nicholas O'Leary

unread,
Oct 4, 2015, 2:34:58 PM10/4/15
to Node-RED Mailing LIst
And of course, you can use Node-RED to create just such a web server that will trigger the camera using the exec node on http request and return the image

Nick

--

Csongor Varga

unread,
Sep 19, 2017, 1:05:27 PM9/19/17
to Node-RED
Hi Sumit,

Are you still using the above flow? Or has anything changed on the Twitter side? I use the same method, the file node reads the file, I put it into msg.media and the tweet itself to msg.payload. I can see the data going into the tweet node just fine, still my tweet is only appearing as text only.

Regards,
Csongor

Olivier Denis

unread,
Sep 20, 2017, 7:57:00 AM9/20/17
to Node-RED
Bonjour
thanks for the node. i just do the test with a file and it is ok.
now i just want in my tweet add an image with the text. Add an image it is ok, add a text is ok, but the both :-( i didn't find the solution.

Thanks.
Ps sorry for english :-)
Reply all
Reply to author
Forward
0 new messages