Web page button controls GPIO relay
#1
Hi all,
I'm looking for some advice with regards to controlling a relay from a web page. 

I am familiar with using the RPi.GPIO to control the actual relay(s) on the pine64.

What I am confused about it how to have the web page button onClick event send the python code to the pine64.
Does html have an event or method "onClick" or is this only available using javascript?

Would I create a html (PHP) webpage  add a button, then have a cgi script run the python RPi.GPIO code?

I'm trying to come up with the right strategy of how to go about this so any assistance would be greatly appreciated.

Thanks in advance
Dave
  Reply
#2
(04-17-2020, 06:51 PM)coolio Wrote: Hi all,
I'm looking for some advice with regards to controlling a relay from a web page. 

I am familiar with using the RPi.GPIO to control the actual relay(s) on the pine64.

What I am confused about it how to have the web page button onClick event send the python code to the pine64.
Does html have an event or method "onClick" or is this only available using javascript?

Would I create a html (PHP) webpage  add a button, then have a cgi script run the python RPi.GPIO code?

I'm trying to come up with the right strategy of how to go about this so any assistance would be greatly appreciated.

Thanks in advance
Dave


I'm toying about with a arduino board with wifi and basically did something similar.

I use onclick events to trigger a XMLHttpRequest request so I don't need to refresh the whole page just to use a servo
  Reply
#3
(04-17-2020, 10:16 PM)evilbunny Wrote:
(04-17-2020, 06:51 PM)coolio Wrote: Hi evilbunny,

Thanks for the info.  I've researched the ajax XMLhttpRequest and have it working, well I have a web page that allows me to run a "hello Dave"  cgi script
on my pine64...I've written a cgi script that when run from the command line turns ON and OFF a relay momentarily...
When I try to run the cgi script through the XMLHttpRequest event handler, I end up with an INTERNAL ERROR page on my web browser...

From my searching on the web the problem is related to the GPIO pins needing to run as ROOT...
I've spent 2 days (and nights) on this and am now officially giving up trying to do this on the pine64.

FYI - I'm heading back to the Raspberry pi and will use the wiringpi module, then right PHP code to do the same...


Hi all,
I'm looking for some advice with regards to controlling a relay from a web page. 

I am familiar with using the RPi.GPIO to control the actual relay(s) on the pine64.

What I am confused about it how to have the web page button onClick event send the python code to the pine64.
Does html have an event or method "onClick" or is this only available using javascript?

Would I create a html (PHP) webpage  add a button, then have a cgi script run the python RPi.GPIO code?

I'm trying to come up with the right strategy of how to go about this so any assistance would be greatly appreciated.

Thanks in advance
Dave


I'm toying about with a arduino board with wifi and basically did something similar.

I use onclick events to trigger a XMLHttpRequest request so I don't need to refresh the whole page just to use a servo
  Reply
#4
(04-19-2020, 07:50 AM)coolio Wrote: Thanks for the info.  I've researched the ajax XMLhttpRequest and have it working, well I have a web page that allows me to run a "hello Dave"  cgi script
on my pine64...I've written a cgi script that when run from the command line turns ON and OFF a relay momentarily...
When I try to run the cgi script through the XMLHttpRequest event handler, I end up with an INTERNAL ERROR page on my web browser...

From my searching on the web the problem is related to the GPIO pins needing to run as ROOT...
I've spent 2 days (and nights) on this and am now officially giving up trying to do this on the pine64.

FYI - I'm heading back to the Raspberry pi and will use the wiringpi module, then right PHP code to do the same...

You can allow php to run things as root, although generally you wouldn't want this, edit /etc/sudoers and add the following:

Code:
www-data    ALL=(ALL:ALL) ALL

Then you just do:

Code:
sudo <cmd>

As for the INTERNAL ERROR that is coming from the server and can be caused by a number of things
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)