Why does it timeout, after 1 min it will not answer.
i am using a 16 chan relay card, arduino mega 2560 and a netcard.
It works ok, but after some time it wont work.... (www.anlsoft.dk:88) only for test fun, but i will change it later..
CODE: (made with help from this: http://www.instructables.com/id/Ethernet-Shield-LED-WEB-SERVER/step4/The-program/)
#include <Ethernet.h>
#include <SPI.h>
#include <pgmspace.h>
prog_char string_0[] PROGMEM = "
Control af 16 relay
";prog_char string_1[] PROGMEM = "
";
prog_char string_2[] PROGMEM = "";
prog_char string_3[] PROGMEM = "";
prog_char string_4[] PROGMEM = "";
prog_char string_5[] PROGMEM = "
";
prog_char string_6[] PROGMEM = "";
prog_char string_7[] PROGMEM = "";
prog_char string_8[] PROGMEM = "";
prog_char string_9[] PROGMEM = "
";
prog_char string_10[] PROGMEM = "";
prog_char string_11[] PROGMEM = "";
prog_char string_12[] PROGMEM = "";
prog_char string_13[] PROGMEM = "
";
prog_char string_14[] PROGMEM = "";
prog_char string_15[] PROGMEM = "";
prog_char string_16[] PROGMEM = "";
prog_char string_17[] PROGMEM = "
";
prog_char string_18[] PROGMEM = "";
prog_char string_19[] PROGMEM = " "; prog_char string_20[] PROGMEM = " "; //for auto refresh
PROGMEM const char *string_table[] = // change "string_table" name to suit
{
string_0,
string_1,
string_2,
string_3,
string_4,
string_5,
string_6,
string_7,
string_8,
string_9,
string_10,
string_11,
string_12,
string_13,
string_14,
string_15,
string_16,
string_17,
string_18,
string_19,
string_20
};
char buffer[99]; // make sure this is large enough for the largest string it must hold
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 0, 0, 200 };
byte gateway[] = { 10, 0, 0, 1 };
byte subnet[] = { 255, 255, 255, 0 };
String inString = String(60);
EthernetServer server(88);
char* Re[] = {"Relay 01", "Relay 02", "Relay 03", "Relay 04", "Relay 05", "Relay 06", "Relay 07", "Relay 08", "Relay 09", "Relay 10", "Relay 11", "Relay 12", "Relay 13", "Relay 14", "Relay 15", "Relay 16", "Hjemme", "Godnat"
};
char* sen[] = {"r01", "r02", "r03", "r04", "r05", "r06", "r07", "r08", "r09", "r10", "r11", "r12", "r13", "r14", "r15", "r16", "hon", "nat"
};
int Rpin[] = {30, 31, 32, 33, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47};
int st[] = {9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9};
int led[] = { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 };
String msg="";
int tam=0;
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip,gateway,subnet);
server.begin();
Serial.println("Serial READY");
Serial.println("Ethernet READY");
Serial.println("Server READY");
for (int x=0;x<17;x++) {
pinMode(Rpin[x],OUTPUT);
digitalWrite(Rpin[x],HIGH);
}
}
void loop()
{
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if we've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (inString.length() < 45) {
inString.concat(c);
}
int leds=0;
if (c == '\n' && current_line_is_blank) {
if(inString.indexOf(sen[16])>0){
hjem_on();
}
if(inString.indexOf(sen[17])>0){
nat();
}
for (int p=0; p<18;p++) {
if(inString.indexOf(sen[p])>0){
if(led[p]==0){
st[p]=8;
led[p]=1;
digitalWrite(Rpin[p],HIGH);
}
else{
st[p]=9;
led[p]=0;
digitalWrite(Rpin[p],LOW);
}
leds=1;
}
}
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
strcpy_P(buffer, (char*)pgm_read_word(&(string_table[0]))); // Necessary casts and dereferencing, just copy.
client.println( buffer );
for (int i = 1; i < 20; i++)
{
strcpy_P(buffer, (char*)pgm_read_word(&(string_table*))); // Necessary casts and dereferencing, just copy.*
-
client.println( buffer );*
-
delay(30);*
-
}*
-
for (int x=0;x<16;x++) {*
-
if (x==4 || x==8 || x==12) {*
-
client.println("*
"); -
}*
-
if(digitalRead(Rpin[x])==HIGH){*
-
client.println(Re[x]);*
-
client.println(" (OFF) |");*
-
}*
-
if(digitalRead(Rpin[x])==LOW){*
-
client.println(Re[x]);*
-
client.println(" (ON_) |");*
-
}*
-
}*
-
break;*
-
}*
-
if (c == '\n') {*
-
// we're starting a new line*
-
current_line_is_blank = true;*
-
} else if (c != '\r') {*
-
// we've gotten a character on the current line*
-
current_line_is_blank = false;*
-
}*
-
}*
-
}*
-
// give the web browser time to receive the data*
-
delay(1);*
-
inString = "";*
-
client.stop();*
-
}*
strcpy_P(buffer, (char*)pgm_read_word(&(string_table[20]))); client.println( buffer );
}
void hjem_on(){ -
digitalWrite(Rpin[5],LOW);*
-
digitalWrite(Rpin[7],LOW);*
-
digitalWrite(Rpin[8],LOW);*
-
st[5]=9;*
-
led[5]=0;*
-
st[7]=9;*
-
led[7]=0;*
-
st[8]=9;*
-
led[8]=0;*
}
void nat() { -
for (int x=0;x<17;x++) {*
-
digitalWrite(Rpin[x],HIGH);*
-
st[x]=8;*
-
led[x]=1;*
-
}*
}