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 ads by
Signing UpStep 1: Knowledge Base
- Apache web server
- PHP5
- MySQL Server
- phpMyAdmin would help
You can find instructions for this here.
It may help to read up on my other Instructable: Control Stuff with your Raspberry Pi (GPIO) so you know what;s going on.









































Visit Our Store »
Go Pro Today »




but in output GPIO with LED not working?
anyone can fix this problem?
i has complete it and it work verry good.
i has complete it and it work verry good.
sleep 30
/var/www/GPIOServer.sh > /dev/null
Also, I added a line at the very beginning of the GPIOServer.sh
#!/bin/bash
I hope this helps.
i am unable to run the script at startup
i get the following errors
update-rc.d: using dependency based boot sequencing
insserv: warning: script 'GPIOServer.sh' missing LSB tags and overrides
insserv: warning: script 'myserver' missing LSB tags and overrides
insserv: There is a loop between service rpc_shellinaboxd and GPIOServer.sh if stopped
insserv: loop involving service GPIOServer.sh at depth 2
insserv: loop involving service rpc_shellinaboxd at depth 1
insserv: Stopping GPIOServer.sh depends on rpc_shellinaboxd and therefore on system facility `$all' which can not be true!
insserv: Stopping myserver depends on rpc_shellinaboxd and therefore on system facility `$all' which can not be true!
insserv: exiting now without changing boot order!
update-rc.d: error: insserv rejected the script header
plz help
I have a question that I have not found the answer to yet and I'm not all that familiar with PHP.
When I log on to the Control.PHP page with an iPhone, the page is very small and I have to zoom in. I also have to re-zoom every time I push a button.
Is there a way to set the screen resolution for an iPhone or other mobile device in the PHP script?
Again, thanks so much. This is so much fun!
I believe that has to be set in the HTML and CSS of the page.
Sorry I can't be of more help.
Thanks, Dan.
I discovered a bug :
with safari on mac, if I use port 8000, I can't login any more...
il I delete the line : session_regenerate_id
frome the control.php script, It works ok...
is it a problem to remove that line ?
thank you.
There's no real issue with removing that line, all it does is help towards the security of the login script, but shouldn't affect the system in any way.
Thanks, Dan.
I love your script, and I have 2 questions :
1 - where do you put the script GPIOServer.sh ? do you leave it in /root ?
2 - I would like it to start on boot of the raspberry, but I don't really know to create a init.d file... I did try but had an error when updating rc.d :
insserv: warning: script 'K01GPIOServer' missing LSB tags and overrides
insserv: warning: script 'GPIOServer' missing LSB tags and overrides
thank you
jean
Are you running the script as root?
Many thanks, Dan.
./GPIOServer.sh: 53: [: out: unexpected operator
./GPIOServer.sh: 65: [: out: unexpected operator
./GPIOServer.sh: 77: [: out: unexpected operator
./GPIOServer.sh: 89: [: out: unexpected operator
./GPIOServer.sh: 101: [: out: unexpected operator
./GPIOServer.sh: 113: [: out: unexpected operator
./GPIOServer.sh: 125: [: out: unexpected operator
./GPIOServer.sh: 137: [: out: unexpected operator
Any ideas why?
Does this only happen with a wait time of 5?
Many thanks, Dan.
I think that the piface board is a solution in its own right, however it probably could be controlled by the scripts if you really wanted.
Many thanks, Dan.
This information will be pretty usefull for mi proyect:
I am building a clock for the city hall in my town "Jalos" (in Mexico) that is able to configure via the web for people with privileges to schedule it in the departament of social communication. I built the mechanism and its controller that connects to the RPi. I use a DS1302 with its backup battery to avoid errors by power outage. Three actuators, which control the motor of hand's axis, the bell quarters and the bell of hours. This machine will play songs of my town at each hour with an amplifier, for this i use the program mpg123 that plays ogg and mp3 files.
Just need to use reading encoders that tell me the position of the hands.
I wonder how can I scan/read the pins of GPIO as inputs?
Uffortunally it boots, but then hangs in a loop of errors. after entering the wait time.
Cant find MySQL database etc bla bla...this because it is started to early.
I cant seem to kill the loop so it can continue to boot further..
Any ideas? btw im a real noob in linux...
As a work around, you could perhaps add a delay to the start of the script.
i.e. a For loop that goes for 30 seconds before allowing the rest of the script to run.
Many thanks, Dan.
keep up the good work!
Glad you got it all working :) - have fun with it.
At the moment I am planning to re-write the script to make it easier to set up, and less resource intensive (so faster updating), although this will be a few months off, as I'm quite busy with other projects at work.
Many thanks, Dan.
I've got one question about it.
Is there possibility to add another button "pulse" to each GPIO on control.php?
When I press the button I need 2 secs of signal
Many thanks :)
With the way I've set the scripts up, EXACT timing is not possible - but you could get near 2 seconds (maybe half a second out).
There are 2 ways of doing this:
Javascript in the browser
Modify the shell script and database and browser files.
The javascript method is probably the easiest and you'd have to add a button to the file with a javascript timer so that it automatically changes the database variable after 2 seconds.
For this, there is probably a better solution out there using python to perform the actions you request.
Many thanks, Dan.
1) how do I get the script to run at reboot?
2) when I reboot and run it manually, it sets all pins "high" - and updates the database. How can this be solved?
Login as your user, then input the following:
sudo cp /root/GPIOServer.sh /etc/init.d/GPIOServer.sh
sudo chmod +x /etc/init.d/GPIOServer.sh
sudo update-rc.d GPIOServer.sh defaults
Reboot and that should start the script on boot.
Many thanks, Dan.
2. (Easiest to start with) I believe it is in the architecture of the Raspberry pi to set all pins high on boot up, however I may be incorrect.
I don't know of any way of changing this (but would be very interested if you found one).
1. I'll post a reply to your comment tomorrow, although I believe it to be a simple thing. Just a bit late here :)
Many thanks, Dan.
Second, I *really* don't know much about php, how secure is the transmission of the password?
It's great that you want to build off of this! :)
No restrictions on the code - use it as you wish.
If you could link to the instructable, that'd be great thanks.
The password should be fine for transmission over the Internet as it's hashed and salted, so should be fine.
Let me know how it goes?
Many thanks, Dan.
I'll send you some code to put into the web page tomorrow that will automatically update the page if you want?
Many thanks, Dan.
Sorry about the lack of a reply, completely forgot.
I'm away on work at the moment, but I'll try my best to get that code sorted for you.
Again, sorry for no reply, Dan.
How good is your JavaScript?
The simplest way I can think of doing this is to refresh the page every x seconds, so that the updates will show.
In the header of the file, add:
NOTE: Change the 3000 for any millisecond value you want.
Hope this helps, Dan.
Thanks, Dan.
### Script Python ###
#!usr/bin/python
from time import sleep;
import RPi.GPIO as GPIO;
import MySQLdb
GPIO.setmode(GPIO.BCM)
conn = MySQLdb.connect('localhost','user','password','table_name');
while True:
curs = conn.cursor();
result = curs.execute("select * from pinStatus");
result = curs.fetchall()
for row in result:
pinNumber = int(row[1])
pinStatus = True if int(row[2]) == 1 else False
GPIO.setup(pinNumber, GPIO.OUT)
GPIO.output(pinNumber, pinStatus)
curs.close()
sleep(2)
##############
And the crontab looks like:
@reboot /home/toto/script.py
(@reboot means that the following script will be launch everytime the computer is started)
Any comments or advice are welcome