Rich_Pi
Posts: 1
Joined: Fri Oct 10, 2014 10:49 am

Control Pi via web

Sun Oct 12, 2014 1:38 pm

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

elatllat
Posts: 1337
Joined: Sat Dec 17, 2011 5:05 pm

Re: Control Pi via web

Sun Oct 12, 2014 3:34 pm

Yes you could use php exec or the like.
SBC with 32GB RAM: https://hardkernel.com

FAQ : https://raspberrypi.stackexchange.com

Unanswered: https://www.raspberrypi.org/forums/search.php?search_id=unanswered

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Control Pi via web

Sun Oct 12, 2014 4:49 pm

Would WebIOPi meet your requirements?

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Control Pi via web

Mon Oct 13, 2014 8:38 am

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.

Return to “Beginners”