Hi,
I'm struggling for weeks now to get a basic GET-request with an Arduino UNO in combination with the Ethernet shield. I want to use this configuration due to the stability of a wired network. The Arduino kit talks to a computer which runs a lighting program and which can accept HTTP-requests. On a trigger input a sequence of requests (with acceptable delay between each request) is send to trigger a lightshow.
Important to mention that it is a basic HTTP request, https gives issues.
There is not authentication or anything.
The computer is set to a static IP, and so is the arduino set in the same range.
If I test the GET-requests with Postman, it works as supposed.
Somehow I can't get the GET-request working on Arduino.
I've removed the whole sequence to sort out why it isn't working and just send a single request after boot every second, but nothing happens.
Anyone with advise how to make this working?
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetClient client;
// const char server[] = "192.168.178.201"; // server address [on-site]
const char server[] = "172.16.1.5"; // server address [office]
const int port = 80;
void setup() {
// You can use Ethernet.init(pin) to configure the CS pin
//Ethernet.init(10); // Most Arduino shields
//Ethernet.init(5); // MKR ETH shield
//Ethernet.init(0); // Teensy 2.0
//Ethernet.init(20); // Teensy++ 2.0
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// start the Ethernet connection:
Serial.println("Initialize Ethernet with DHCP:");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
} else {
Serial.print(" DHCP assigned IP ");
Serial.println(Ethernet.localIP());
}
// give the Ethernet shield a second to initialize:
delay(1000);
}
void loop() {
Serial.println("Sending request");
client.println("GET /RemoteCommands?SetFadeTime=4 HTTP/1.1");
client.println("Host: " + String(server));
client.println("User-Agent: arduino-ethernet");
client.println("Connection: close");
// client.println("Connection: keep-alive");
client.println();
// if (client.connect(server, port)) {
// Serial.println("Sending request");
// client.println("GET /RemoteCommands?SetFadeTime=4 HTTP/1.1");
// client.println("Host: " + String(server));
// client.println("User-Agent: arduino-ethernet");
// // client.println("Connection: close");
// client.println("Connection: keep-alive");
// client.println();
// }
delay(1000);
}
11 posts - 3 participants