Okay, I'm getting close using my second example above, but I'm not quite getting the functionality I expected. By the way, I'm not against using some information stored on the Arduino for web server purposes, but I really want to host the main site elsewhere so I don't have a hundred people trying to connect to my Arduino at the same time.
Here is the simple example I'm trying:
Running on the Arduino:
#include <Ethernet.h>
#include <SPI.h>
boolean reading = false;
byte ip[] = { 192, 168, 1, 177 }; //ip address to assign the arduino
byte gateway[] = { 192, 168, 1, 1 }; //ip address of the gatewa or router
byte subnet[] = { 255, 255, 255, 0 };
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x78, 0x97 };
Server server = Server(80); //port 80
void setup(){
pinMode(7, OUTPUT);
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
}
void loop(){
// listen for incoming clients, and process request.
checkForClient();
}
void checkForClient(){
Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
boolean sentHeader = false;
while (client.connected()) {
if (client.available()) {
if(!sentHeader){
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
sentHeader = true;
}
char c = client.read();
if(reading && c == ' ') reading = false;
if(c == '?') reading = true; //found the ?, begin reading the info
if(reading){
Serial.print(c);
switch (c) {
case '7':
//add code here to trigger on 7
triggerPin(7, client);
break;
}
}
if (c == '\n' && currentLineIsBlank) break;
if (c == '\n') {
currentLineIsBlank = true;
}else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection:
}
}
void triggerPin(int pin, Client client){
digitalWrite(pin, HIGH);
delay(500);
digitalWrite(pin, LOW);
delay(500);
}
The web site source code for interaction:
<form name="test" action="http://xx.xx.xxx.xxx/?7" method="GET">
<input type="submit" value="Blink" />
</form>
(I filtered out the IP address I am using.) When I use the method "GET" the form does not work. When I use the method "POST" the form works, but it takes the user to a new blank web page. I want the user to stay on the same page.
Update: I see you were using an inline frame for the page that loads. Is it possible to have an inline frame load which is transparent to the user?
Update 2: I found an answer. I simply include an inline frame and added the following attribute:
style="display:none"