I'm having a problem with my ethernet shield server connection. I connected my ethernet shield to a router ( client mode ) and then connect this router to my phone hotspot. This is my code:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "www.xxx";
IPAddress ip(192, 168, 1, 177);
EthernetClient client;
void setup() {
Serial.begin(9600);
while (!Serial) {
;
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
Serial.println(Ethernet.localIP());
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET http://xxx/ccc.php HTTP/1.1");
client.println("Connection: close");
client.println();
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop() {
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
while (true);
}
}
here is what showing on the serial monitor :
connecting...
192.168.43.107 //
connected
HTTP/1.1 400 Bad Request
Date: Mon, 23 May 2016 17:45:44 GMT
Server: Apache
Content-Length: 226
Connection: close
Content-Type: text/html; charset=iso-8859-1
Bad Request
Your browser sent a request that this server could not understand.
disconnecting.
it worked when i directly connect it with my wifi router, but when trying to connect it to my hotspot using a client mode router it gives a Bad request. any help please ?