Dear,
I have a web server inside an arduino Mega and the ethernet module. But I also need from it to send a GET request.
I'm not able to, answer "Connection Failed". Could you please tell me where the error is?
The IPs are local. The web server works perfect.
Tkx, Nahuel
#include <SPI.h>
#include <Ethernet.h>
#include <EEPROM.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(10, 240, 16, 23);
//IPAddress ip(192, 168, 1, 110);
EthernetServer server(8080);
EthernetClient clientPutin;
//Variables
int CNTRL_Modulos = EEPROM.read(1);
String Sensor;
byte server2[] = { 10, 240, 11, 138 };
void setup() {
Serial.begin(9600);
while (!Serial) {
}
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
if (clientPutin.connect(server2, 80)) {
Serial.println("connected");
clientPutin.println("GET /?prueba=30 HTTP/1.1");
clientPutin.println(F("Connection: close"));
clientPutin.println();
clientPutin.stop();
} else {
Serial.println("connection failed");
}
}
void loop() {
//for (int x = 0; x < 4096; x++) {
// delay(1);
// EEPROM.write(x, 0);
//}
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
String text = client.readString();
////