Getting Node Red/MQTT Data into web page

2,318 views
Skip to first unread message

Paul Reed

unread,
Feb 28, 2014, 6:16:27 PM2/28/14
to node...@googlegroups.com
I'm running Node-Red from a Raspberry Pi alongside a web-server, and wondered how I can integrate data from either Node-Red or the MQTT broker into a web-page?
For example, I've created a flow to predict weather frosts which sends a push message to my phone, but it would be great if I could also include the msg.payload in a web-page too.

Nicholas O'Leary

unread,
Feb 28, 2014, 6:38:03 PM2/28/14
to node...@googlegroups.com
Hi Paul,

there was some discussion of this in this thread: https://groups.google.com/forum/#!topic/node-red/3oJ5qp0aV7o


Cheers,
Nick


On 28 February 2014 23:16, Paul Reed <paul...@gmail.com> wrote:
I'm running Node-Red from a Raspberry Pi alongside a web-server, and wondered how I can integrate data from either Node-Red or the MQTT broker into a web-page?
For example, I've created a flow to predict weather frosts which sends a push message to my phone, but it would be great if I could also include the msg.payload in a web-page too.

--
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/groups/opt_out.

Paul Reed

unread,
Feb 28, 2014, 6:59:29 PM2/28/14
to node...@googlegroups.com
Thanks Nick.
Sorry about my ignorance, but as my website is currently running on a Apache server, can I ignore the first part of that post, ie "in settings.js, set httpStatic to point to..." and still use websockets to make the data connection?

Paul

Nicholas O'Leary

unread,
Feb 28, 2014, 7:02:44 PM2/28/14
to node...@googlegroups.com
Hi Paul,

yes that will work.

Nick


Paul Reed

unread,
Mar 3, 2014, 4:26:55 PM3/3/14
to node...@googlegroups.com
I'm finding 'websockets' confusing to say the least, despite spending a lot of time trying to get it working, even using the linked post.

As a 'plan B', I've used the 'file' node to write the msg to a txt file, and reading it server side using;
<?php
$f = fopen("mydata/rain.txt", "r");
echo fgets($f);
fclose($f);
?>
Which works OK, but if anyone has an example of websocket use, it would be great if it could be posted to use as a template.

Thanks

Paul

Dave C-J

unread,
Mar 3, 2014, 5:14:47 PM3/3/14
to node...@googlegroups.com

Paul

has a simple static web page example - I called it test.html
the only line you should need to mess with is 
       "ws://"+server+":1880/admin/ws/myapp";

to change the last part to wherever your node red server is...
I changed settings.js so that

    httpStatic: '/home/{myid}/node-red/web/',
    httpRoot: '/admin',

then put that web page in the   web   directory
and just use an inject to websocket out node like this - (copy the block below and import it to node-red -  ctrl-i - ctrl-v

[{"id":"69ca9946.963568","type":"websocket-listener","path":"/ws/myapp","wholemsg":"false"},{"id":"84f7890.f7b0878","type":"inject","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":183,"y":395,"z":"4e8dadf1.abecb4","wires":[["1d6d02b7.e292fd"]]},{"id":"1d6d02b7.e292fd","type":"websocket out","name":"","server":"69ca9946.963568","x":422,"y":401,"z":"4e8dadf1.abecb4","wires":[]}]

Then I can browse to  localhost:1880/test.html
then click the inject and the numeric timestamp should appear on the web page

Paul Reed

unread,
Mar 3, 2014, 5:27:22 PM3/3/14
to node...@googlegroups.com
Thanks Dave, however my existing website is running in Apache.
I'm running node-red on the same Raspberry Pi as the web server, and wanted to include some of the node-red data msg's within the existing pages.
That's why I'm having trouble with the example.

Paul

Dave C-J

unread,
Mar 3, 2014, 5:44:53 PM3/3/14
to node...@googlegroups.com
So what happens when you serve that web page from apache ?
the web socket line above still needs to point back to the node red instance not apache (so like above - but without the admin/ if using default node-red settings, rather than mine) - as it's the browser that makes the web socket connection to Node-RED - you need Chrome or recent(ish) Firefox that supports web sockets.



--
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/groups/opt_out.



--
regards

Dave Conway-Jones

Paul Reed

unread,
Mar 3, 2014, 5:49:14 PM3/3/14
to node...@googlegroups.com
Aaah, I follow that!
I can't believe I didn't see it before...
Thanks for your patience, I'll try again tomorrow.

Paul
Reply all
Reply to author
Forward
0 new messages