HTML to activate GPIO

#1

Hello together,

for the first, excuse me for my bad english.
for the second, I doesn't know much about programming.

what i want to do is:

html to activate a GPIO for maybe 15 minutes

so when I write "http://192.168.X.X/test/GPIO2" in my browser, i want to activate the GPIO2
when I write "http://192.168.X.X/test/GPIO3" in my browser, i want to activate the GPIO3

I hope you can help me.
And again, excuse me for my bad english, I am german.

0 Likes

#2

If you are using node-red on Raspberry PI use the http request node (https://pt.coursera.org/lecture/developer-nodered/creating-a-web-api-in-node-red-part-1-Io3F1) and use the raspberrypi nodes https://projects.raspberrypi.org/en/projects/getting-started-with-node-red/7

0 Likes

#3

Okay but i don`t know, how i can do it.

When i write "http://192.168.178.35/test?test=GPIO" i receive it.
But how can i go on with this information?
i mean my GPIO needs a 0 or >1 to switch.
and in the funktion how can i say when GPIO1 then Out1 and when GPIO2 then Out2

0 Likes

#4

Take a look at the switch node and the change node

0 Likes

#5

Try using the switch node and get the data from msg.req.test. Send the payload do desired output

0 Likes

#6

how can i send it to the payload?

0 Likes

#7

on a function node
var gpio = msg.req.test
msg.payload = {"gpio": gpio}

0 Likes

#8

i tryed it but it doesn't worked.

my flow is like this:

  1. http node with "Method GET" an "URL /test"
  2. funktion node with:
    "var gpio = msg.req.test;"
    "msg.payload = {"gpio":gpio};"
  3. switch node, here i don't know what to do!!!
  4. GPIO node

my URL is "http://192.168.178.35/test?test=gpio"
can you say me what i have to do?

what im looking for ist to switch on GPIO2 when the URL ist test=GPIO2, an to switch on GPIO3 when the URL ist test=GPIO3.

0 Likes

#9

Please export your flow
Then read the following post How to share code or flow json and follow the instructions to post your flow here.

0 Likes