arduino-libraries / Ethernet

Ethernet Library for Arduino
http://arduino.cc/
259 stars 264 forks source link

get http code without blocking the program in a while loop. #200

Closed RensMvP closed 2 years ago

RensMvP commented 2 years ago

For a project i need a hardwired connection with ethernet, for which i am using the W5500 connected to my esp32s2. The posting works without any isues, but i would like to have the httpcode back. This way i know if the command has succesfully been received and handled.

The function i use to post the commands is seen below. Anybody that has a idea that won't block my program but gets met the httpcode?

bool httpSendRequest(String type, String JsonData)
{
  Serial.print("  STATIC assigned IP ");
  Serial.println(Ethernet.localIP());
  if (client.connect(TV_ip, TV_port))
  {
    client.println( type + url + "HTTP/1.1");
    client.println("Host: " + String(TV_ip) + ":" + String(TV_port));
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.println("User-Agent: " + userAgent);
    client.print("Content-Length: ");
    client.println(JsonData.length());
    client.println();
    client.println(JsonData);
    client.println();

    return true;
  }
  else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
    return false;
  }
}
per1234 commented 2 years ago

Hi @RensMvP. Thanks for your interest in this open source project. This issue tracker is only to be used to report bugs or feature requests. This topic is more appropriate for the Arduino Forum. I'm sure we will be able to help you out over there:

https://forum.arduino.cc/