Ok this one is a bit different. Does anyone know how to set up an arduino to be controlled over the web via serial connection to the pc. I want to start an automation system for my room and want to be able to have some control via the web. So that way before I go home from school or whatever I could send a command to turn on the lights or heat. something simple but effective. I plan on getting more sensors and relays. Later on I may add a keypad lock system.
If you are using a windows machine, you can put the apache server on your pc and use a cgi batch file to echo the GET query_string data to the arduino. If you need bidirectional info with the arduino, you need a cgi file to use instead of a batch file.You would need to use a resistor or capacitor on the arduino to keep it from resetting on the com port open/close.
I'm running windows 7. So how do I go about setting up an apache server. I have a free website on my dad's web hosting package through 1and1. So I can put it there. I can write some html stuff. I'm not that great at it but my father is good at html. So if I get stuck with that I can get his help. also how do I go about writing the cgi script.
This will have to run on your local computer, since 1and1's servers are far away and don't have a USB/serial connection to your arduino
You'll also need to be able to get to your computer over the internet, so you'll need to know your IP address and if you have a wireless router in front of your PC or something it'll have to be configured to port-forward port 80 to your PC.
There is a router in the computer room of our house. I'm connected through a 16 port hub and then through the router. I have my ip saved on my computer.
gotcha, cool.
How to install Apache Server on Windows | ricocheting.com -- that guide should help getting the base Apache HTTP server installed
For the CGI, there's a few programming languages you can use... I'm a fan of PHP myself, and you can install PHP5 on windows too; here's a guide:
http://webdevcodex.com/tutorial-installing-apache2-php5-mysql5-phpmyadmin3-windows-7-vista/
that also talks about installing database software (mysql), don't think you need that for this application. Then you'll need to see what PHP's class/library for doing serial I/O is and work from there. http://php.net/ has good documentation for learning the language and using libraries. Not sure what your experience is with this though, just tossing that out there.
thanks a lot the apache server is installed an running as local host. I probably need to change it to my ip address.
Yeah you'll want Apache listening on the internal LAN IP of your machine (not localhost, but the one assigned to your machine by your router), then the router forwarding port 80 traffic from outside over to your machine's internal IP at port 80.
how do I change the webpage that apache comes with to my own. because I want to add a login system for security purposes.
Below is a simple web cam setup that uses apache and simple batch type files to operate some cam pan/tilt. The same can be done using an arduino. Been working 24/7 since 2004. Bottom is a link to another forum that has some info on using freebasic to make an .exe cgi application for use with apache for bidirectional serial port communication. As to PHP, it is really no more functional for serial port operations than a simple batch file.
I'm still stuck on the cgi part. Also how do I change the default apache page to my own.
I'm still stuck on the cgi part. Also how do I change the default apache page to my own.
The default apache page is index.html in the htdocs folder. You can make a different web page with the same name and replace the default one.
The cgi basics are the brouser makes a get request from a URL link in the web page containing the desired data in the query_string part of the URL. Apache receives the request, executes the executable file in the cgi-bin folder. The executable file does what is desired using the data in the query_string, then sends the result back to apache, which sends the info back to the brouser.
how's that supposed to make my arduino do anything. I need to have control on my arduino now via php.
Since you are having some trouble with the web server, and it doesnt seem like youd be thrilled about CGI, port forwarding, dynamic DNS, and the pains of home web hosting, I propose two possible solutions:
-
Read (and follow) a guide about setting up a WAMP (although you probably dont need My SQL)
-
Setup a website on 1and1 that has a login, and a page to configure whatever you want to configure. Have this webpage save its results in plain text format to another webpage, with information for each item, such as: bedroom_light: ON . heat: ON . etcetera. This can all be accomplished with some very simple PHP (or ASP if thats your thing -- yuck) Then,write a simple python script to check the webpage, and send appropriate commands over serial to the arduino. If you want two way communication, just have the python script send GET information to the configuration web page, as if it were a web client-- also very simple. I can help you with the code here if you want, but it is much easier than it sounds.
Number 2 is probably more flexible, reliable, and easier, especially sinc eyou have free hosting..
Good luck!
how's that supposed to make my arduino do anything.
It makes my arduino do stuff, but I got a feeling it probably won't happen with your arduino.
I need to have control on my arduino now via php.
Can't help you with PHP as I never found it capable of doing the computer I/O of interest to me.
I think you might be best with a ethernet shield. The arduino can host a basic webpage that can directly does things on the arduino. No PC required. There are great examples in the playground.
I think I may go with cgi I do understand php some but not a lot. I know more html then php because my father has taught me some stuff. He's a web developer. He also has an arduino and a bunch of sensors. He's got the mega 2650.
I need to have control on my arduino now via php.
I'm running windows 7.
PHP is great for a lot of things, but bi-directional serial data transmission on Windows is not one of them.
PHP can write to the serial port, but can not read from it, on Windows. It can do both on Mac and Linux systems.