• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Controlling GPIO(python script) from a website

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

kamran

Member
Joined
Jul 9, 2013
Location
Sadly Iran :(
I want to turn on GPIO from the Internet and I'm going to use my Raspberry Pi.
What is a good way to do that? And also, how can i put a username and a password on my website?
(I already googled but im not sure how i should do it, i followed php on codeacademy but i only learned to make classes and arrays :|)
 
Last edited:
The easiest way to password protect your website is with HTTP Basic authentication via an .htaccess and .htpasswd file. Keep in mind that while the passwords on the server are encrypted in your password file, they're transmitted from your browser in plain text. If someone nefarious were to be on your network (or if you're on public wifi) and sniffing your traffic, they could get your credentials.

Just google "raspberry pi python gpio" and I'm sure you'll get tons of results. Basically, though, you just need to code a page on your Pi that manipulates GPIO on the backend, and have the GPIO pins attached to some sort of driver like a relay board to switch your lights on and off. You'll need to hardwire each light switch that you want to control to the driver board, unless you replace the switches with some wireless ones, which will add significant cost.
 
I already done that by writting my own HTTP server and turning gpio on and off when the url is ?ON or ?OFF but im not sure i should do this securely with apache server!
 
If you're concerned with security, then I would skip a homegrown HTTP server and install Apache. You can implement some sort of security on the page itself by requiring a password or something, but it'd be better if you could stop people from hitting the page in the first place.
 
If you're concerned with security, then I would skip a homegrown HTTP server and install Apache. You can implement some sort of security on the page itself by requiring a password or something, but it'd be better if you could stop people from hitting the page in the first place.

i have no problem doing that either, but also i have no idea how i can tell my raspberry pi that user has clicked the On button or etc,
 
The most straightforward way would be to install PHP on your Pi and use exec() to call whatever python script manipulates the GPIO pins. I'm sure the Pi provides some modules or packages that make it a bit easier, I've never worked with it though so I'm not sure.

It seems like you're pretty new to programming in general, so until you get a better understanding of it and the security implications, I would be very hesitant to open this thing up to the web. You might start by just making it available on your local network only.
 
The most straightforward way would be to install PHP on your Pi and use exec() to call whatever python script manipulates the GPIO pins. I'm sure the Pi provides some modules or packages that make it a bit easier, I've never worked with it though so I'm not sure.

It seems like you're pretty new to programming in general, so until you get a better understanding of it and the security implications, I would be very hesitant to open this thing up to the web. You might start by just making it available on your local network only.

thanks, im installing PHP on my pi :D BTW i'm totally new to network programming (about less than a week of knowadge :D) but have been programming python and c and etc for long!
edit: i have permission and etc problems, i can't do it that way!
EDIT: my python program could constantly read the file and php write whenuser clickes an image, what do you think?
 
Last edited:
Back