I want to build a two way communication between an ESP32 and a (Python) server.
The ESP32 shall send a first GET request to the server and according to the server's response call different POST or GET methods.
For the sake of simplicity, I would like to use HTTPclient.h.
Code: Select all
void loop() {
HTTPClient http;
http.begin("http://xx.xx.x.xxx:5000/");
int httpCode = http.GET();
if(httpCode > 0) {
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
}
}else{
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
Do I have to end my HTTPClient and start a new connection with http.begin():
Code: Select all
void loop() {
HTTPClient http;
http.begin("http://10.42.0.191:5000/");
int httpCode = http.GET();
if(httpCode > 0) {
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
http.end();
[...]
http.begin("http://10.42.0.191:5000/one");
int httpCode = http.GET();
[...]
http.end();
}
}else{
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
delay(500);
}
Thanks for your help!