Control Stuff with your Raspberry Pi (GPIO) over the internet by drcurzon
Please Note:
This Instructable is now depreciated.
Click here for the updated, much improved, version.


Hi there,
This will hopefully show you how to control electronics across the internet using your Raspberry Pi.
It's not the best way to do it, and soon I will update this with a way to use MySQL to do the same thing.

Here's a link to YouTube showing it in action: http://www.youtube.com/watch?v=OCZlfAFcm7Q

For this, please ensure that you have apache with php running on your Raspberry Pi, Instructions can be found here.

Also, it would be a good idea to read my previous instructable on general GPIO control, which can be found here.
 
Remove these adsRemove these ads by Signing Up

Step 1: Overview + Warning

This is not the best way of doing this, and I hope to update this soon with a MySQL solution.
Until then, I'd recommend keeping this to your local network (not over the internet yet).
However, there shouldn't be any issues, it's just a warning. :D

Overview
This will (at the moment) allow you to control your GPIO pins via a web interface.
The program running on your Raspberry Pi checks to see if a file exists, if it does - it turns the output on, otherwise it turns it off. All the web interface does (at the moment) is to either create or delete this file.
pfaller says: Jan 19, 2013. 2:44 AM
Hello, I have a problem

1) I create a php file with the given code (gpio.txt) then I placed in var / www
2) I create a txt file with the given code (gpioCheck.txt) then I placed in a directory (the first available: home)
3) I logged in as root via Putty and i placed in the home directory (cd / home)
4) I have run this commands :

-"mv gpioCheck.txt gpioCheck.sh"
-"chmod +x gpioCheck.sh"
-"./gpioCheck.sh"

5) and this is what I get: http://hpics.li/4b247d7

I don't Understand !! What's the Problem ??? Thanks
drcurzon (author) says: Jan 19, 2013. 9:36 AM
Try changing the wait time to 1.
Many thanks. Dan.
pfaller says: Jan 19, 2013. 1:25 PM
the problem does'nt looks to be here : http://hpics.li/c8972c1
I am not a specialist, but there seems to be a problem in the script "gpioCheck",

Here is the code I downloaded and copy:

"echo "Please enter a wait time"
read waitTime
echo "Please enter GPIO number"
read pin
if [ "$pin" != "4" ] && [ "$pin" != "17" ] && [ "$pin" != "18" ] && [ "$pin" != "21" ] && [ "$pin" != "22" ] && [ "$pin" != "23" ] && [ "$pin" != "24" ] && [ "$pin" != "25" ]; then
echo "Pin error - GPIO number doesn't exist"
else
echo "$pin" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio$pin/direction
while :
do

if [ -f /var/www/gpio.txt ]
then
echo "Turn GPIO on"
echo "1" > /sys/class/gpio/gpio$pin/value
else
echo "Turn GPIO off"
echo "0" > /sys/class/gpio/gpio$pin/value
fi
sleep $waitTime
done

fi"
sriramvr says: Jan 15, 2013. 10:15 PM
the browser says can't open file

terminal says write error: Device or resource busy
how to fix it please reply soon........
azukovskij says: Nov 1, 2012. 8:59 AM
Thank you for this instructable. I'm wondering if it is possible to somehow execute Python (.py) scripts through the web-server. I'm kind a new for Linux and started working on Raspberry pi 2 weeks ago. I have 7 Python programs which are driving servo motor by generating different pulses. I just want to do a simple web page with 7 buttons. When you press one of the buttons, Python script should start executing. Any help and comments would be appreciated.
racafilla says: Oct 31, 2012. 4:20 PM
I get an error when i click turn on . It says "cant open file"
rogerramjetrdn says: Oct 11, 2012. 11:56 AM
Hi,

I am having problems uderstanding this line of code from gpioCheck.txt

if [ -f /var/www/gpio.txt ]

I understand that it is checking to see if the file gpio.txt is there or not, it's the -f part I can't seem to find on the internet. All I find for python language is os.path.exists or something similar to check if the file exists not -f.

Thanks in advance. You have really helped me out with this instructable. Thank you for shareing.
rogerramjetrdn says: Oct 11, 2012. 12:08 PM
Would you believe it. This is not python language but shell script language (so many different languages to learn!) Found it 5 mins after posting this question.

http://www.freeos.com/guides/lsst/ch03sec02.html

Shell also test for file and directory types

Test Meaning
-s file Non empty file
-f file Is File exist or normal file and not a directory
-d dir Is Directory exist and not a file
-w file Is writeable file
-r file Is read-only file
-x file Is file is executable

Once again thanks for the tutorial.

Best regards Rogerramjetrdn
gp.greg says: Aug 31, 2012. 1:43 AM
Thanks for the great tutorials. I am getting the following error when running the script:
Turn GPIO on
./gpioCheck.sh: line 16: /sys/class/gpio/gpio25/value: Permission denied

Can you please help with what I might be doing wrong
Thanks
gp.greg says: Aug 31, 2012. 1:48 AM
Sorry for the lack of concentration. All I needed to do was run the script as root.

I'm new to Linux so learning as I go.

Thanks again for the great tutorial
drcurzon (author) says: Aug 31, 2012. 2:25 AM
No Problem, glad you sorted it out :D
miicchhii says: Jul 21, 2012. 1:58 AM
megaduty says: Jun 7, 2012. 7:39 AM
So ready for my Pi to get in... Thanks for the ible!
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!