Rich_Pi wrote:Hi
I have just started with RPi and need a bit of guidance.
I want to control electrical circuits I have set up on my Pi via the web. So far I have created a simple LED circuit on a breadboard that I can control via Python scripts. I have also installed Apache and set up port forwarding and can see my hosted site on the net. Now I need to tie the two together and I am not sure how.
Can I run python scripts via the web page I setup? If not then what do I need to do?
Thanks for any help
Rich
Hi Rich, you can run python scripts from PHP but will need root access (bad thing to give to a web access), if you install wiringPi you can control GPIO directly from PHP commands.
$ git clone git://git.drogon.net/wiringPi
This is a sample of code that I am using in my
Dalek project, First of all it turns off the GPIO that I'm not using, then it turns on the GPIO that I want to use, then it returns to the HTML page that I triggered it from
Code: Select all
<?php
$off1 = 'gpio mode 1 in';
$off2 = 'gpio mode 2 in';
$off3 = 'gpio mode 3 in';
$off4 = 'gpio mode 0 in';
$stop1 = 'gpio write 1 0';
$stop2 = 'gpio write 2 0';
$stop3 = 'gpio write 3 0';
$stop4 = 'gpio write 0 0';
exec($stop1);
exec($stop4);
exec($off1);
exec($off4);
$lefton = 'gpio mode 2 out';
$leftoff = 'gpio mode 2 in';
$righton = 'gpio mode 3 out';
$rightoff = 'gpio mode 3 in';
$command = 'gpio write 2 1';
$command2 = 'gpio write 2 0';
$command3 = 'gpio write 3 1';
$command4 = 'gpio write 3 0';
exec($lefton);
exec($righton);
exec($command);
exec($command3);
header ("Location: Dalek.html");
?>
you probably noticed that there are more commands than are executed, I left in the unnecessary bits to make it easy to modify as desired.
The GPIO numbering in wiring pi is best checked on Gordon's website
here, which explains the numbering method used and shows you the pinout on a GPIO table.
Doug.
Building Management Systems Engineer.