We are trying to push some data from the esp32 to the cloud using the httpclient post method without success. What we see on the server side is that parts of the http header gets filled (user agent and IP address), but the json data package arrives empty (cgi FieldStorage empty). I tested the cloud setup by sending post requests using a script with the same IP as the esp32 so I am pretty sure its OK. Here is the code to build the data json data package:
Code: Select all
void make_packet(){
packet = "{"; // JSON dictionary to send
// Build up json datum variable by variable:
for(uint8_t i=0; i < (UPDATE_SIZE); i++)
{
packet.concat( "x" + String(i) + ": " + String(data_update[i]));
if( i < (UPDATE_SIZE-1) ){
packet.concat(", ");
}
}
packet.concat(" }");
}
Code: Select all
HTTPClient WiFi_TCP::http; // http client definition
String WiFi_TCP::packet = " ";
void WiFi_TCP::Handle_Client()
{
http.begin(WiFi_TCP::http_server);
http.setUserAgent( WiFi_TCP::our_user_agent );
http.addHeader("Host", "our_host.com");
http.addHeader("Content-Type", "application/json");
make_packet();
int httpCode = http.POST(packet);
#ifdef SERIAL_DEBUG
Serial.printf("Post Response code: %d\n", httpCode);
if( httpCode <= 0 ){
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
#endif
http.end();
}