Apologies for this late response. The forum does presently not work with internet explorer. Now I have sent this thru my girlfriends' android tablet. Below this is my present code. I separately tested zoomkat's webclient and found it works well. I will integrate that into my code. I have not found out yet how I can mail the resulting ip address to myself. About my-ip.com or others like that, I think these are paid services. Also I do not understand how such a service would find my new ip adress if my provider changed it.
In the present code I also wanted to add some password security, to prevent other people from fiddling with my central heater, but I think that what I have done now is rather flimsy, especially as the browser displays my password. Is there any experience with https on the Arduino ?
/*
Web server sketch for IDE v1.0.1 and w5100/w5200
Posted October 2012 by SurferTim
Modified proron.40@gmail.com 7.11.2013
*/
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
int CountWrongPwd=-1;
int CountWrongPwdTotal=-1;
// this must be unique, its Ron's Arduino ethernet board
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x72, 0x7E };
// change to your network settings Ron's UPC network
IPAddress ip( 192,168,0,10 );
IPAddress gateway( 192,168,0,1 );
IPAddress subnet( 255,255,255,0 );
//Create a server that listens for incoming connections on the specified port.
EthernetServer server(82);
void setup()
{
Serial.begin(9600);
analogReference(EXTERNAL);
pinMode(7,OUTPUT);
digitalWrite(7,LOW);
pinMode(10,OUTPUT);
digitalWrite(10,HIGH);
// Serial.print("Starting SD..");
// if(!SD.begin(4)) Serial.println("failed");
// else Serial.println("ok");
//Initializes the ethernet library and network settings
Ethernet.begin(mac, ip, gateway, gateway, subnet);
// digitalWrite(10,HIGH);
delay(2000);
server.begin();
//Serial.println("Ready");
}
void loop()
{
EthernetClient client = server.available();
if(client)
{
boolean currentLineIsBlank = true;
boolean currentLineIsGet = true;
int tCount = 0;
char tBuf[64];
char *pch1 = "wrong";
char *pch2 = "wrongwrong";
//Serial.print("Client request: ");
while (client.connected()) {
while(client.available()) {
char c = client.read();
if(currentLineIsGet && tCount < 63)
{
tBuf[tCount] = c;
tCount++;
tBuf[tCount] = 0;
}
if (c == '\n' && currentLineIsBlank)
{
// send a standard http response
//Serial.println(tBuf);
//Serial.print("POST data: ");
while(client.available()) Serial.write(client.read());
//Serial.println();
pch1 = strtok(tBuf,"?");
pch1 = strtok(NULL,"=");
pch2 = strtok(NULL," ");
//Serial.println(pch1);
//Serial.println(pch2);
//Serial.println("Sending response");
client.write("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n");
if((strncmp(pch1,"xxx",3) == 0)&(strncmp(pch2,"yy",2) == 0))
{//pch2=on
digitalWrite(7,HIGH);
delay(10000);
digitalWrite(7,LOW);
}//pch2=on
if((strncmp(pch1,"zzz",3) == 0)&(strncmp(pch2,"qqqqqqqqqq",10) == 0))
{
client.write("
Ron's Arduino Webserver v5.106d !
");
//start of table
// after calling analogReference(EXTERNAL)
//connecting Aref with +5 via 4k3
//with 2k2 in series with KTY10-7 sensor
client.write("
");
client.write("<table border=1 bgcolor='white'");
client.write("width=180 height=30 ALIGN=right>");
client.write("");
client.write("");
client.write("Outside
temperature
C");
client.write("");
client.write("");
client.write("Workshop
temperature
C");
client.write("");
client.write("");
client.write("Living
temperature
C");
client.write("");
client.write("");
client.write("");
client.write("");
client.print(float(analogRead(1))*0.476 - 236.0,1);
client.write("");
client.write("");
client.print(float(analogRead(0))*0.464 - 231.0,1);
client.write("");
client.write("");
client.print(float(analogRead(2))*0.476 - 236.0,1);
client.write("");
client.write("");
client.write("
");
// button set.
client.write("
");
client.write("
");
client.write("Number of failed login attempts : ");
client.println(CountWrongPwdTotal);
CountWrongPwd=-1;
CountWrongPwdTotal=-1;
client.write("\r\n\r\n");
client.stop();
}
else
{
//Serial.println("no");
client.write("
Ron's Arduino webserver ?
");
client.write("Password:
");
CountWrongPwd++;
CountWrongPwdTotal++;
// Serial.println(CountWrongPwd);
if(CountWrongPwd>2)
{
client.write("Wrong password. Website is locked");
CountWrongPwd=-1;
client.write("\r\n\r\n");
client.stop();
delay(60000);
}
else
{
client.write("\r\n\r\n");
client.stop();
}
}
}
else if (c == '\n')
{
currentLineIsBlank = true;
currentLineIsGet = false;
}
else if (c != '\r')
{
currentLineIsBlank = false;
}
}
}
//Serial.println("done");
}
}