Hi there,
This is an updated version of my previous Instructable: Control Stuff with your Raspberry Pi (GPIO) Over the internet.

This version is much more secure and could easily be used across the internet with very few security concerns.

A brief outline:
- A server program that runs on the Raspberry Pi to read variables
- A MySQL database to store the variables in
- An Apache2 served webpage to allow control of the variables
Remove these adsRemove these ads by Signing Up
« Previous41-80 of 174Next »
acsooley10 months ago

How can I start the ./ on startup of the raspberry PI? I cant seem to figure it out. Any help please.

Did you try putting the script path into /etc/rc.local ?

Make sure you specify the complete directory path /full/path/ ./ is a relative path and likely won't work.

dpaterson1 made it!10 months ago

Thank you so much for putting up this instructable - this was a great starting point for my own GPIO control webpage.

I made a few modifications as I wanted a real-time response (instead of waiting for the to loop around), and a simple way to group pins together with time delays (turning on an Amp before the speakers in an auditorium etc)

I ended up using WiringPI to do this, after the "TurnOn" button was pressed it calls a Shell Script that calls WiringPI commands. I still track the state of the pins in the SQL database though.

As my system is used by many people I also added a login page, it also sends daily emails via shell script cron job that summarises which users turned items on and off during the day.

As some of my TurnOn/TurnOff scenario's add delay into the webpage reloading, I also used this guys Javascript loading image code to the mix to stop form resumbissions.

Once again - thanks for this example, it got a noob at RPI up and started in no time!

hilbo dpaterson110 months ago

The first script that worked ou of the box!

Thank you for sharing!

@ dpaterson1: Hi, this is exactly what I am working on. Would you mind sharing your script as well?

dpaterson1 hilbo9 months ago

Here's an example shell script I stored in /opt/scripts/

Make sure is executable "chmod 755"

***** contents*****


#WiringPi GPIO 1 = BCM 18 = Physical Header 12


#Set GPIO 1 = PIN 12 as an Output

gpio mode 1 out

#Change GPIO 1 voltage to High

gpio write 1 1

*******PHP Code*****

$groupOnScript = "/opt/scripts/";


m3mn0t dpaterson19 months ago

Can you help me ?Can you provide your code? or simple help me with something?

m3mn0t9 months ago

Hi how can i talk with you


imohammad11 months ago

hello there, thank you for the tutorial~!! i want to ask, if the gpio is set to input. If i gave the input a signal (on) does the web page update the input status?

I don't believe it does - would need to be modified to read the status of the GPIO pins, then load it into the mysql database.

Then the web page would read the database and show the status.

thanks for the info ^^

Hello, Wondering if you can help. Great tutorial by the way however i have followed everything through but when i type ./ and enter a value it automatically turns on any GPIO pins that are connected and then nothing plays ball after. Any ideas of where i am going wrong? Cheers
drcurzon (author)  aztecthegeordie1 year ago
Hi there - can you send me the file?
Thanks - Dan.
dhill281 year ago
I'm struggling to get the actual pins to work. From what I can tell, things are installed correctly, and if I go into the actual database, I can see that the pin status setting in the database is changing when I click the buttons, but I don't get anything out of the pins at all. Is there anything particular I should be looking at?
drcurzon (author)  dhill281 year ago
Hi there, Have you tried manually setting the GPIO pins?
Try the following commands (should set pin 21 high)

echo "21" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio21/direction
echo "1" > /sys/class/gpio/gpio21/value

To turn off:
echo "0" > /sys/class/gpio/gpio21/value
echo "21" > /sys/class/gpio/unexport

Let us know how it turns out - Dan.
jeryhawj1 year ago
when i put in http://raspberryPi/control.php(raspberryPi=my ip address), all i get is an invalid request. can someone tell me if i need to do something else. i have followed every instruction on here... and even went back to all the old pages to make sure i did everything correct. i even have access to "phpmyadmin" account. i dont know why i cannot get into this last part. any help and or reply will be appreciated. thank you.
winsum1 year ago
Hi drcurzon,
your instructable is very great!

I have only one problem. When i execute the ./, it return two errors:

line 54: /sys/class/gpio/gpio4/direction: File or directory not exist.
line 59: /sys/class/gpio/gpio4/value: File or directory not exist.
GPIO 4 Turned Off
GPIO 17 Turned Off
GPIO 18 Turned Off
GPIO 21 Turned Off
GPIO 22 Turned Off
GPIO 23 Turned Off
GPIO 24 Turned Off
GPIO 25 Turned Off

Why this error?
Very thanks.
i have had a similar error, turned out that i had some errors when exporting and selecting direction for the gpio#.
winsum winsum1 year ago
Hi boys,
i have seeking that the file gpio4 is not present in the folder /sys/class/gpio/

i not know because!
tmcisaac1 year ago
Quick query, just picked up a Raspberry Pi, got this setup and I was wondering. Can the other pins on the GPIO be addressed to add more buttons? (minus the DNC pins of course)
Rather n00b question, I know.
buteman1 year ago
Running control.php doesn't seem to do anything. I have edited control.php and put a username and password in but when I enter them on running control.php it just goes straight back to asking for user name and password. I tried refreshing the web page to ensure I was running the modified version, I restarted both mysqld and apache2 but it just doesn't work. Any ideas?
lionikus1 year ago
Great tutorial. But... My Raspberry Pi rev2.. This does not include pin2.. ... I added in :
direction2=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinDirection FROM pinDirection WHERE pinNumber='2'";)
status2=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinStatus FROM pinStatus WHERE pinNumber='2'";)
if [ "$direction2" == "out" ]; then
echo "out" > /sys/class/gpio/gpio2/direction
if [ "$status2" == "1" ]; then
echo "0" > /sys/class/gpio/gpio2/value
echo "GPIO 2 Turned On"
echo "1" > /sys/class/gpio/gpio2/value
echo "GPIO 2 Turned Off"
and... I added in SQLbase gpio respective lines...
then it worked... But...
My led is flashing every "How long do you want the wait time to be? "...
Weak, but flashes...
How to fix this problem?
Sorry for my english :)
Who could be useful it:
sudo su -
echo "4" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio4/direction
echo "0" > /sys/class/gpio/gpio4/value
echo "1" > /sys/class/gpio/gpio4/value
Sorry... It : This does not include pin2.. read as: This does not include gpio2..
Note that 0 and 1 interchanged in Turned on and turned off... I do not know why but check first to bash...
maco17171 year ago
Hi, Great tutorial! at last something that work for me. was trying with webGPIO for ages to then realize that the new version dont support to run from apache anymore so can use on my solution.

anyway was wondering what that sleep time? and it takes around 2s for the led to change state when i do trough web is this a normal delay time? would it be quicked with another solutions?

drcurzon (author)  maco17171 year ago
Hi there,
Glad you got it working. :)
the sleep time is the time before it updates each of the variables - the smaller the number, then more CPU + RAM usage, etc...
The delay is unfortunately due to the way the script works - there are other solutions - I believe you can call scripts directly from Python.
Many thanks, Dan.
yeah that's what i was trying, well first i tried php exec() with a bash script but would execute i guess because of permissions i was going to try python but i read that the script also need to be executed by admin so didnt try... is there any way around this?
the bash script was very basic, basically

# Set up GPIO 4 and set to output
echo "4" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio4/direction

# Write output
echo "1" > /sys/class/gpio/gpio4/value

and "0" to turn off...

all this in a .sh that was called from a button



also tried implementing a read status off led

exec('sudo cat /sys/class/gpio/gpio4/value',$outputArray);

but as is said no luck...

should i try with python?

exec(sudo python

i changed the visudo file to allow www-data apache user to edit files this allowed me to run
exec('sudo cat /sys/class/gpio/gpio4/value',$outputArray);

but the buttons are not working...
at last got it working.
my problem wasnt permission was not good web programing...

the page is like this now...

exec('cat /sys/class/gpio/gpio4/value',$outputArray);

if ($_GET['on']) {
# This code will run if ?run=true is set.
if ($_GET['off']) {



incredibly responsive
drcurzon (author)  maco17171 year ago
Hi there,
Nice to see you got it working :)
sdobbie1 year ago
I can't log in. It just changes the user back to root and doesn't work.
sdobbie1 year ago
I got into it and tried the web address but it says that The requested URL /admin/phpMyAdmin/index.php was not found on this server.
sln911 year ago
Hello, just curious does it work outside the same network ? or can we only access the web control interface if it is on the same network ?
I couldn't manage to give it a host name so I always type the ip address and it works if I am connected to the same router/network but when I connect to another network I can't access it did I miss a step ?
Sorry I have no prior experience with server.
Thanks in advance.
drcurzon (author)  sln911 year ago
Hi there.
It is possible to access this externally, however I highly recommend the installation of a firewall first.
After the firewall is installed, you need to set port forwarding on your router to forward ports 80, 21 to the raspberry pi (web, FTP).
Many thanks, Dan.
hkusumah1 year ago
awesome tutorial. many thanks for making this instructable
Hi, First off... EXCELLENT tutorial! I've loved working through it and appreciate your work.

However, I'm having problems with setting the script to run from boot. When I put in "sudo update-rc.d defaults" I get the "missing lsb tags and overrides" warning and on reboot... nothing. So I have to log in as root and run the script by hand-crank ;)

So far, I've modded the control.php to look perfect on my tablet and phone and have bench tested the hardware for running all my external lighting (with override switches) from my armchair.... I just need to get past this "start on boot" problem and I'll be a happy man... any help and advice would be most welcome.

P.S. Anyone who needs help resizing the text etc in the php, comment here and I'll try to guide you. I'm hoping to find time to knock together a .css to pretty it up a little and I'll share that too
@drcurzon good job.
But, i am so confused to merge all post together.
specially i have no idea about your url: raspberrypi/
how can it's possible that.
According to my knowledge raspberry pi's IP will be there.
How can we arrange secure access of raspberry control?
Forgive me for my post, but i really confuse about all those things.
drcurzon (author)  denimjohnson1 year ago
Hi there,
The URL works as previously you set the hostname of the raspberry pi.
The URL can be the hostname or the ip address.

Secure access with this setup is not possible - you'd have to install a firewall at the very least. (Or keep it on the LAN with an external firewall (such as untangle)).

Many thanks, Dan.
pandringa1 year ago
@drcurzon - I tried to respond to your reply but the captcha wasn't loading, so I had to reply here.

Anyways, I've tried the site on the latest versions of Firefox and Safari (on my Mac), but neither worked.
pandringa1 year ago
I've gotten the webpage to load and I've been able to log in, but the "turn on" and "turn off" buttons don't do anything. I have LEDs hooked up to each output, and I can turn them on or off with a python script no problem, but the buttons on the website don't do anything.
« Previous41-80 of 174Next »