I am trying to make a code that every time the arduino card is rebooted (Arduino Ethernet connected to Arduino UNO), values of an http request are collected. The problem is that sometimes I get the result of that request which is the following:
HTTP / 1.1 200 OK Date: Thu, 11 Jan 2018 23:04:01 GMT Server: Apache X-Powered-By: PHP / 5.6.32 Vary: User-Agent Content-Length: 4 Connection: close Content-Type: text / html; charset = UTF-8 DatoQueObtengo
However sometimes I get the error of connecting the client with the server, here is my code:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "www.miweb.mx";
IPAddress ip(192, 168, 0, 177);
#define RESTART asm("jmp 0x0000");
EthernetClient client;
void setup() {
Serial.begin(9600);
while (!Serial) {
;
}
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip);
}
delay(500);
Serial.println("connecting…");
if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET /ServiceWeB.php?Elements=All HTTP/1.1");
client.println("Host: www.miweb.com");
client.println("Connection: close");
client.println();
} else {
Serial.println("connection failed");
}
}
void loop() {
String content = "";
while(client.available()!=0)
{
content = content + String(char (client.read()));
}
Serial.println(content);
content = "";
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
delay(3000);
RESTART;
}
}
However, as I said, it does not always work and because that tells me that something is missing in the code