The problem is that I own an account behind a virtual Linux server of someone else and that the code gives a bad request.
I think the problem occurs because of wrong setup of IPAddress server declaration. I need it to be declared as a domain.
char server ('www.domain.com'); doesn't work as well...
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x00, 0x00, 0x1A, 0x2B, 0x3C, 0x4D };
IPAddress ip(192, 168, 1, XXX);
IPAddress gateway(192, 168, 1, 254);
IPAddress subnet(255, 255, 255, 0);
IPAddress server(XXX,XXX,XXX,XXX); // Change to your server ip
EthernetClient client;
int totalCount = 0;
int loopCount = 0;
void setup() {
Serial.begin(9600);
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
Ethernet.begin(mac, ip, gateway, gateway, subnet);
delay(2000);
Serial.println("Ready");
}
char pageAdd[32];
void loop()
{
if(loopCount < 5)
{
delay(1000);
}
else
{
loopCount = 0;
sprintf(pageAdd,"/arduino.php?temp1=%d",totalCount);
if(!getPage(server,pageAdd)) Serial.print("Fail ");
else Serial.print("Pass ");
totalCount++;
Serial.println(totalCount,DEC);
}
loopCount++;
}
byte getPage(IPAddress ipBuf,char *page)
{
int inChar;
char outBuf[128];
Serial.print("connecting...");
if(client.connect(ipBuf,80))
{
Serial.println("connected");
sprintf(outBuf,"GET %s HTTP/1.0\r\nHost: http://www.domain.com\r\n\r\n",page); // Should it be http://www.domain.com/arduino.php\r\n\r\n" ???
client.write(outBuf);
}
else
{
Serial.println("failed");
return 0;
}
int connectLoop = 0;
while(client.connected())
{
while(client.available())
{
inChar = client.read();
Serial.write(inChar);
connectLoop = 0;
}
delay(10);
connectLoop++;
if(connectLoop > 1000)
{
Serial.println();
Serial.println("Timeout");
client.stop();
}
}
Serial.println();
Serial.println("disconnecting.");
client.stop();
return 1;
}