Instructables
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 151Next »
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
===
#!/bin/bash

# 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

==

ON
===

also tried implementing a read status off led

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

but as is said no luck...
:(

should i try with python?

exec(sudo python scriptname.py)

???
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);
print_r($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);
print_r($outputArray);
?>


if ($_GET['on']) {
# This code will run if ?run=true is set.
exec("/var/www/teston.sh");
}
if ($_GET['off']) {
exec("/var/www/testoff.sh");
}
?>


ON

OFF
===

incredibly responsive
drcurzon (author)  maco17171 year ago
Hi there,
Nice to see you got it working :)
Dan.
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 GPIOServer.sh 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.
drcurzon (author)  pandringa1 year ago
Hi there,
This sounds like it may be a browser issue on the client pc.
What browser are you using? (Name and Version).
Also - have you tried any other computers / browsers?
Thanks, Dan.
freakqnc1 year ago
Well... eventually is "almost" everything working.
I had to modify the shell GPIO Script to
- include LSB so initserv would not keep issuing warnings about "missing lsb tags and overrides" throw a warning,
- add commands to the script for pins to work with raspi rev.2
- modify tables to store/retrieve pin status and description

After starting the service GPIOServer.sh 6 out of the 8 pins connected to the relay board are working (all 8 were working with webIOPi By Eric Ptak (trouch). The issue though that pushed me to try something else was that I experienced quite a lag, unreliable reading/writing of pin state and that rendered the system not usable in the en.

This one here (raspberry GPIO by Daniel Curzon) is not too bad and sort-of-work, although let me point out that is not for the faint-hearted and complete noobs.

The issue that will keep my quest going is that this simple implementation could be enough, but unfortunately has 2 problems... although more reliable when it comes to reading/writing pin state, is:
- still too slow in responding to command,
- starting the GPIOServer on boot make the raspi enter a loop where throwing errors as that comes in the way of other services and prevents the raspberry pi from actually booting fully as it should AND THEN start the GPIOServer service.

Having to start manually the service on each reboot is a deal breaker since when the system will be installed as a headless one to control devices, each time a restart occurs one would need a computer to manually start the GPIOServer.sh

Probably there is a way to make it work at boot but the info by Daniel which I followed to a T, achieved the endless error "looping" outcome making the system useless at this point.

Well I guess was worth the experience and the try. Better luck to my fellow raspberrians ;)
freakqnc1 year ago
Daniel, did as suggested and that and it's a no go

User ID:
1

Username:
admin

Password:
c56a280f30e3cfa08f6b6646b0593dee3ce3c4728b4562d0f7d827244167a2fd

Salt:
5652ccfa

Will not allow to login with admin/gpio credentials... any suggestions on how to fix this? Thanks! :)

PS: I would have replied to the comment all the way at the bottom but the instructable system would keep asking to fill in the captcha even when I did... so because that won't work I added the comment as a new one although it's really a reply to your original comment about resetting the pass and salt
Update... found the problem peeps :)

Do not use "admin" and "gpio" in

////////////////////////////////////////////////////////////
//  EDIT THESE TWO VARIABLES  //
///////////////////////////////////////////////////////////
$MySQLUsername = "USERNAME HERE";
$MySQLPassword = "PASSWORD HERE";


YOU MUST USE the username and password you created in Step 3 as the DATABASE USER and NOT use the value of the username in the gpio database!

I believe in this example that would be user gpio and password pr03ND2. Not very intuitive and quite confusing... perhaps should've been pointed out in the instructions.

Hope this helps who got stuck at this point.
deki1 year ago
Too many windows open at once, I posted this same comment in your other Instructable, sorry.
Daniel - nice job. Please consider expanding you Instructable to include digital input; maybe even add in another column to dynamically change it from the web interface. Also consider setting up email notification on pin status change. Right now I am using it as a backup to my garage door opener. Works great with my IPhone. It would be nice to know when the kids left the door open too long.
vantanevn1 year ago
MySql data is installed on SD card. But SD card only rewrite about <1000 times. So if you other file (data) on SDRAM it will work perfect.
gwiguna1 year ago
this great i has complete it,
but in output GPIO with LED not working?
anyone can fix this problem?
My raspberry is type B version 2. So GPIO 21 not work (it is GPIO 27). But GPIO17 too. So you can test other pin.
i has complete it and it work verry good.
vantanevn1 year ago
My raspberry is type B version 2. So GPIO 21 not work (it is GPIO 27). But GPIO17 too. So you can test other pin.
i has complete it and it work verry good.
To make mine start up automatically, I put this line just before the "exit 0" in the /etc/rc.local file,

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.
looks_4561 year ago
Hi,
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
thecank1 year ago
Great tutorial!! I finally got this working as well as my wireless adapter!!
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!
drcurzon (author)  thecank1 year ago
Hi there,
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.
jduffas1 year ago
Hi,

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.
drcurzon (author)  jduffas1 year ago
Hi there.
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.
jduffas1 year ago
hi !
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
Sorry, no it does it with any wait time I try
drcurzon (author)  checkers3131 year ago
Hi there.
Are you running the script as root?
Many thanks, Dan.
Whenever I use ./GPIOServer.sh and enter in 5 for the wait time it returns with:
./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?
drcurzon (author)  checkers3131 year ago
Hi there.
Does this only happen with a wait time of 5?
Many thanks, Dan.
ashah81 year ago
Is there an easy way to convert the control webpage so its more compatible with mobile browser?
Nechako1 year ago
Thanks for the quick reply, I'll give it a go!! Awesome tutorial.
thecank1 year ago
Great instructable! I am going to have fun with this. I do have one question that I can't figure out even after some research; When I view the page on my iPhone the text is very small. I have not coded HTML since the 90's and don't know anything about CSS or PHP. Is there a way to adjust resolution in your control.php script based on browser or screen size?
Nechako1 year ago
Can this be adapted to work with the piface board?
drcurzon (author)  Nechako1 year ago
Hi there.
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.
« Previous41-80 of 151Next »