Bear with me I'm not sure of the correct technical terms of what I'm asking.

Over the last year or so I have been playing with Arduino and Rpi. Little automation projects. Here's an example. I have an Arduino, ultrasonic sensor and relay attached to my desk lamp and screens. When I sit at my desk the Arduino turns my screens and desk lamp on. Then when I leave my desk the Aduino turns the screens and light off after 60 secs.

I would like to create a simple web interface that I can access from any browser (Computer, tab or phone), Like the ones Routers and other programs such as CUPS use.

I know how to write a static web page using HTML and CSS. I know that I would need a web server such as Apache running to serve the page. What I don't know is how do I get the HTML to send or execute a command to the program.

I know if I use an Ethernet shield the Aduino can check the packet header for a particular string and then act accordingly. Is that the same process that say CUPS would use. It seams a bit basic?

Lets say that I have a basic web page with a button to toggle the light. How would I get the web page to send a command when I click the button. I know there is a need for some logic to check the state of the light. i.e.

and the command to the Arduino is sent via the serial com or ethernet.

I've been researching this for a while. But the google results generated from my search always point to web apps for iPhones and Android. I don't want to create an App I want a web page. I've managed to work out that I need something like PHP/Java? to perform the function. Am I right in thinking PHP/java is what I need?

You need something a little more programmable on the web server than a plain http daemon. The classic Linux based solution is the LAMP stack - Linux, Apache, MySQL, Perl/Python/PHP. Ruby is sometimes used as an honorary "P" while you probably don't need a database but can get away with a script or two.

Apache is not the only good web server. It does have all the bell-and-whistle options such as PHP in case you need them, depending on whether you are more desperate to install them or to avoid installing stuff.

Check out those "P"s and choose your weapon. Or, (Gulp!) get into Java, maybe via JSP or whatever. Since it's an Arduino I wouldn't recommend Java as it can bloat your system.

You can use HTML Forms (and/or javascript if you want a fancy user interface) in your web page to send your selected option/s back to the server. You may/will need to set up Apache to pass your HTTP requests to the correct script - there are a lot of options here and I am v. rusty, so ask around. Probably the simplest is to create say a PHP script which can both process your requests and masquerade as index.html (once you have told Apache to default to it), in fact that may well be all you need.

Further elaboration might be to capture the Arduino status and use it to update the web display.

HTML forms: use the <input ...> element to create clickable widgets, with one along the lines of say <input type="submit" name="Enter" value="send "> to create an "Enter" button (sorry, v. rusty again on the exact code).

"Klinger, do you know how many zoots were killed to make that one suit?" — BJ Hunnicutt, 4077 M*A*S*H

I've seen the HTML forms being used on other Arduino projects is that the same as HTML post/get?

I'm glad you said one of the Ps. As I've been working through the PHP track on Code Academy it seems fairly easy to pick up. I've not dabbled with Python yet but plan to soon. I'm hoping to avoid databases and Java for now. Something else that popped up is a MQTT server, which looks really interesting maybe a bit over kill for now though. I've got an Apache LAMP server installed on a VM. Although I've not really used it.

I think the HTML forms need further investigation.

Going back to PHP for a moment. If I have a basic bash script that writes the output of

to a txt file. Could I use PHP to call the script directly? Or is there another mechanism between the PHP and the script? That seems to be something I could get my head around, I like to take small steps and build up to the big stuff.

I heard about MQTT on a site called superhouse.tv. The chap on there described it as a sort of drop in replacement for HTTP post. He said that although HTTP post is suitable it's a bit heavyweight for this sort of thing.

This is what I understood from his video.
MQTT is a subscribe/publish service. If my web UI has two buttons one for light on and one for light off. When one of the buttons is clicked Apache would publish to the channel either "light on" or "light off" accordingly. The Arduino/Rpi which is subscribed to the same channel would see the publish and take action.

purplepenguin wrote:I've seen the HTML forms being used on other Arduino projects is that the same as HTML post/get?

More or less. Broadly, when you request a web page or data you forward an HTML get but when you send form data you forward an HTML post. Your browser knows the difference and you can set Apache how to respond to each kind if you need to.

to a txt file. Could I use PHP to call the script directly? Or is there another mechanism between the PHP and the script?

I'm no expert in PHP but I'm pretty sure it can. Worst case would be PHP passing it to Apache to run the script. Alternatively, as suggested, you could just run a bash script directly from Apache. But getting the script to generate and serve your updated web page might be more of a challenge than giving that task to PHP.

On MQTT, it is a box-to-box protocol and nothing to do with the web. Its relevance depends on where you install the web server. Stick a small one on the Arduino and MQTT is redundant because your PC-to-Arduino protocol is then HTTP. Stick say Apache on your PC and you might find MQTT a good way for Apache to talk to the Arduino - see Apache ActiveMQ for the kind of support built into Apache.

"Klinger, do you know how many zoots were killed to make that one suit?" — BJ Hunnicutt, 4077 M*A*S*H

Thank you to all who replied. I now know what I should be looking into. It looks as though I have a few options.

To summarise my understanding.

I think the first thing I need to do is decide how the Web server will communicate with the Arduino. Serial interface or Ethernet.

If I use the Serial Interface. I could use CGI to call a script that can read or write to the Arduino's serial interface. I'm really interested in this CGI. I could write a script in PHP, Bash, C, Perl etc. This doesn't require me to learn a new language.

Using Ethernet would kill two birds with one stone. I could use HTTP forms to communicate with the Arduino and Power over Ethernet meaning I don't have to worry about power for the devices. Freetronics make an Arduino compatible board with Ethernet and PoE built in. I could then splice an Ethernet and Power cable together or buy a mid-span injector.

With regards to web servers. I'm going to stick with Apache for now as there are a lot of tutorials on the web. Once I get it all up and running. I'll look into lighter servers such as Nginx.

Nelz pointed out that MQTT isn't really what I want. Although I think it requires further investigation for future projects/builds.

I'm going to do some more reading and have a little play around. I'm sure I'll have a few more questions so I'll hold off on marking this one as solved for now.