Buttons in node-red

809 views
Skip to first unread message

Jags

unread,
Aug 27, 2015, 6:12:35 AM8/27/15
to Node-RED
Hello,

I am new to node-red and trying to create a simple flow to change the image on click of button using raspberry pi2. I tried with the following nodes, but with no success.

The javascript is perfect as i tried the same ouside the node-red. Can anyone please help me to get it done. Below is the nodes and script I used in node-red




1. html in node (Method=GET, URL=/mypage)

2. template node
<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Can Change Images</h1>

<button onclick="myFunction1()">On</button>
<button onclick="myFunction2()">Off</button>

<img id="myImage" src="pic_bulboff.gif" width="100" height="180">

<p>Click the light bulb to turn on/off the light.</p>

<script>
function myFunction1() {
    var image = document.getElementById('myImage');
    image.src = "pic_bulbon.gif";
}

function myFunction2() {
    var image = document.getElementById('myImage');
    image.src = "pic_bulboff.gif";
}


</script>

</body>
</html>

3. http response node

Note. When I hit the url http://xx.xx.xx.xx:1880/mypage, the image is not displayed on the browser. When I try to view the image from browser, it says....Cannot GET /mypage/pic_bulboff.gif. I tried to coped the image on different paths, but didnt get the acutal path where i need to copy the image.

Thanks,
Jagtar

Mark Setrem

unread,
Aug 27, 2015, 7:24:38 AM8/27/15
to Node-RED
You can set the directory to be what ever you want it to be by using the httpStatic setting within the settings.js file.

If you start Node-Red with the -v setting it should tell you where the settings.js file it is using is located.  

Its worthwhile looking at the documentation before you do anything http://nodered.org/docs/configuration.html

Jags

unread,
Aug 28, 2015, 1:22:39 AM8/28/15
to Node-RED
Hello Mark,

Many thanks for the info. Successfully able to configure the path.
Reply all
Reply to author
Forward
0 new messages