Developing web applications using Raspberry Pi is the cool stuff for every developer and displaying Pi projects over browser makes it more smart if we talk about IoT(Internet of Things).
Type in cmdline:-
1. Install apache server: sudo apt-get install apache2
2. Install php & dev tools: sudo apt-get install php5 libapache2-mod-php5
3. Create web application: sudo leafpad /var/www/html/index.php
4. Remove index.html: sudo rm /var/www/html/index.html
GPIO setup for php:-
1. Install GIT: sudo apt-get install git-core
2. Install WiringPi:
git clone git://git.drogon.net/wiringPi
cd wiringPi
./build
3. Check wiringPi:
gpio mode 1 out
gpio write 1 1
gpio readall
GPIO WiringPi HeaderPins:-


PHP Code:-
1. Create form using GET or POST method & call same php file
2. Read form using conditionals & run GPIO using exec() function or shell_exec() function.
Create Form: index.php
<?php
<form method="POST" action="index.php">
<input type="submit" name="start" value="start">
<input type="submit" name="start" value="start">
</form>
GPIO setmode: system("gpio mode 1 out")
<?php
system("gpio mode 1 out");
if(isset($_POST['start']))
{
exec("gpio write 1 1");
}
else if(isset($_POST['stop']))
{
exec("gpio write 1 0");
}
?>
GPIO read: exec("gpio read 1",$status)
<?php
system("gpio mode 1 out");
if(isset($_POST['start']))
{
exec("gpio read 1",$status);
if($status==1)
{
echo "SENSE"
}
else
{
echo "NO SENSE"
}
}
?>
3. Running python script in background using shell_exec() function.
It needs various permissions which you have to configure manually, read here
Read more: http://www.raspberry-pi-geek.com/Archive/2014/07/PHP-on-Raspberry-Pi
For more php codes comment!
0 comments:
Post a Comment
Thanks for your comment. We will try to reply as soon as possible.
Regards
VSL Creations