I am trying to create a simple home control over Ethernet system. I am trying to expand on Arduserver2 (The code for ArduServer2, a simple web server in an Arduino with a W5100 ethernet interface- a5as2code). I am doing fine with the outgoing part, I am displaying on the client just what I wanted for my test. My problem is getting and responding to what comes back from the client. I left two buttons and code from my sample however nothing works as advertised. If I click either button, the client appears to refresh, but times out. The address line on the client line says http://mon7nc.dyndns.org:81/\. The site is 207.225.26.203, if you want to see what it is doing. I left the server up. I simplified the code to the minimum. The code is:
#include <SPI.h>
#include <Ethernet.h>
#include <dht11.h>
/-----( Declare objects )-----/
dht11 DHT11;
/-----( Declare Constants, Pin Numbers )-----/
#define DHT11PIN 7
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
byte ip[] = {
192,168,0,15};//240 7NC... shared with old, nuElec, 254 SX
const byte bPort = 80;
const byte bLEDpin=6;//Was on 8 in version c
const byte bSensor1 = 0;
const byte MaxArrayElement=252;
char c,cMstRecentCmnd='/';
char cLineBuffer[MaxArrayElement];
byte bPlaceInBuffer;
Server server(bPort);
void setup()
{
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
pinMode(bLEDpin,OUTPUT);
LEDOff();
}
void loop()
{
int iAn0;
Client client = server.available();
if (client){
boolean currentLineIsBlank = true;
bPlaceInBuffer=0;
char cCmnd='H';
cMstRecentCmnd='H';
while (client.connected()) {
if (client.available()) {
c = client.read();
if ((c!='\n') && (c!='\r')){
cLineBuffer[bPlaceInBuffer]=c;
if (bPlaceInBuffer<MaxArrayElement) {
bPlaceInBuffer++;
};
}
if (c == '\n' && currentLineIsBlank) {
delay(250);
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("");
client.println("");
client.print("Test Server");
client.println("");
client.println("");
client.println();
client.println("");
iAn0=analogRead(bSensor1);
if (iAn0>320)
{
client.println("
Room: well lit.
");}
else
{
if (iAn0>30)
{
client.println("
Room: dim.
");}
else
{
client.println("
Room is dark.
");};
};
client.println("<form METHOD=get action="http://mon7nc.dyndns.org:81/\">");
client.println("<input type=hidden name="cmd" value="1">");
client.println("<input type=submit value="LED On">");
client.println("");
client.println();
client.println("<form METHOD=get action="http://mon7nc.dyndns.org:81/\">");
client.println("<input type=hidden name="cmd" value="0">");
client.println("<input type=submit value="LED Off">");
client.println("");
client.println("");
client.println("");
break;
}
if (c == '\n') {
currentLineIsBlank = true;
if ((cLineBuffer[0]=='G')&&(cLineBuffer[1]=='E')&&(cLineBuffer[2]=='T'))
{
cCmnd=cLineBuffer[10];
if (cCmnd!='/') {
DoCmnd(cCmnd);
};
}
}
bPlaceInBuffer=0;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1);
client.stop();
}
void DoCmnd(char cLCmnd)
{
if (cLCmnd=='0'){
cMstRecentCmnd=cLCmnd;
LEDOff();
};
if (cLCmnd=='1'){
cMstRecentCmnd=cLCmnd;
LEDOn();
};
}
void LEDOn(){
digitalWrite(bLEDpin,HIGH);
}
void LEDOff(){
digitalWrite(bLEDpin,LOW);
}
Setup is a Duemilanove, an Ethernet 5100 shield and a Sensor brick with a led brick(D6) and a light brick(A0). The light brick is just measuring ambient.
Jim