Hello All Guys, Hello SurferTim
after some tests, I still having the connection failed after awhile.
Just to have a better solution I took your web client program Arduino Playground - WebClient and readapted to my server to transmit some datas.
Basically it is the same program.
I tested from yesterday, but again after 12 hours the test failed,
Please find annexed my program ( you can test directly) and the logs report.
i have read the response from server without printing on serial ( shall I do it??) and put delays before stopping as according to the original program.
Still failed connection.
/*
Web client sketch for IDE v1.0.1 and w5100/w5200
Uses GET method.
Posted October 2012 by SurferTim
Last modified September 15, 2013
*/
#include <Time.h>
#include <SPI.h>
#include <Ethernet.h>
// this must be unique
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// change to your network settings
IPAddress ip(192,168,1,177);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
// change to your server
IPAddress server(93,57,69,235); // Google
//Change to your domain name for virtual servers
char serverName[] = "HYDRA SERVER";
// If no domain name, use the ip address above
// char serverName[] = "74.125.227.16";
// change to your server's port
int serverPort = 778;
EthernetClient client;
int totalCount = 0;
char pageAdd[64];
// set this to the number of milliseconds delay
// this is 30 seconds
#define delayMillis 30000UL
unsigned long thisMillis = 0;
unsigned long lastMillis = 0;
void setup() {
Serial.begin(9600);
// disable SD SPI
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
// Start ethernet
Serial.println("Starting ethernet...");
Ethernet.begin(mac, ip, gateway, gateway, subnet);
// If using dhcp, comment out the line above
// and uncomment the next 2 lines plus the Ethernet.maintain call in loop
// if(!Ethernet.begin(mac)) Serial.println(F("failed"));
// else Serial.println(F("ok"));
Serial.println(Ethernet.localIP());
delay(2000);
Serial.println("Ready");
}
void loop()
{
// If using dhcp to get an IP, uncomment the next line
// Ethernet.maintain();
String dataToSend = "/?SK=DGtest03&I=1&G="+String(random(0,1023))+"&V="+String(random(0,1023))+"&CHECK="+String(random(999999))+"&S=1";
char rr[64];
thisMillis = millis();
if(thisMillis - lastMillis > delayMillis)
{
lastMillis = thisMillis;
// Modify next line to load different page
// or pass values to server
dataToSend.toCharArray(rr,64);
sprintf(pageAdd,rr,totalCount);
printTime();
// sprintf(pageAdd,"/arduino.php?test=%u",totalCount);
if(!getPage(server,serverPort,pageAdd)) Serial.print("Fail ");
else Serial.print("Pass ");
totalCount++;
Serial.println(totalCount,DEC);
Serial.println();
}
}
byte getPage(IPAddress ipBuf,int thisPort, char *page)
{
int inChar;
char outBuf[128];
Serial.print("connecting...");
if(client.connect(ipBuf,thisPort) == 1)
{
Serial.println("connected");
sprintf(outBuf,"GET %s HTTP/1.1",page);
Serial.println(outBuf);
client.println(outBuf);
sprintf(outBuf,"Host: %s",serverName);
client.println(outBuf);
client.println("Connection: close\r\n");
}
else
{
Serial.println("failed");
return 0;
}
// connectLoop controls the hardware fail timeout
int connectLoop = 0;
while(client.connected())
{
while(client.available())
{
inChar = client.read();
//Serial.write(inChar);
// set connectLoop to zero if a packet arrives
connectLoop = 0;
}
connectLoop++;
// if more than 10000 milliseconds since the last packet
if(connectLoop > 10000)
{
// then close the connection from this end.
Serial.println();
Serial.println("Timeout");
client.stop();
}
// this is a delay for the connectLoop timing
delay(1);
}
//Serial.println();
Serial.println("disconnecting.");
// close client end
client.stop();
return 1;
}
void printTime(){
time_t t = now();
//Serial.println("System Date/Time:");
Serial.print(day());
Serial.print(".");
Serial.print(month());
Serial.print(".");
Serial.print(year());
Serial.print(" ");
Serial.print(hour());
Serial.print("h ");
Serial.print(minute());
Serial.print("m ");
Serial.print(second());
Serial.print("s ---- ");
//Serial.print("secondi dall'inizio (1.1.1970) = ");
//Serial.println(t);
//Serial.print("ore dall'inizio (1.1.1970) = ");
//t = t / 3600;
//Serial.println(t);
}
Any Idea more?
it is important and unfortunately this is blocking my job...
Ciao Domenico
SRV_logs.TXT (245 KB)