I can't understand why the get request works inside the void setup, but not working inside void loop. The code is exactly the same and I have been trying different stuff but nothing works.
Any ideas?
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
char serverName[] = "www.arpho.mobi";
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
// start the serial library:
Serial.begin(9600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
while(true);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(serverName, 80)) {
Serial.println("connected void setup");
// Make a HTTP request:
client.println("GET /app/arduino.php?sensor1=1 HTTP/1.0");
client.println("HOST: www.arpho.mobi");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.connect(serverName, 80)) {
Serial.println("connected void setup");
// Make a HTTP request:
client.println("GET /app/arduino.php?sensor1=1 HTTP/1.0");
client.println("HOST: www.arpho.mobi");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("nothing");
delay(00);
}
}