Updated the sendHttpQuery error handling due to changes made in the HttpClient library

This commit is contained in:
Th3maz1ng 2022-04-09 16:44:06 +02:00
parent b16f103948
commit c2167f18c5

View File

@ -226,12 +226,14 @@ void gotIpFunc(const WiFiEventStationModeGotIP &event)
void lostConnectionFunc(const WiFiEventStationModeDisconnected &event) void lostConnectionFunc(const WiFiEventStationModeDisconnected &event)
{ {
(void)event;
Serial.println("Lost connection, will try to reconnect ..."); Serial.println("Lost connection, will try to reconnect ...");
} }
void insertIntoDB(void) void insertIntoDB(void)
{ {
char buffer[100] = ""; char buffer[100] = "";
int result(0);
//We get the values and put it in our dictionary //We get the values and put it in our dictionary
sprintf(buffer ,"%u", p.id); sprintf(buffer ,"%u", p.id);
postData("packetUID")->setString(buffer); postData("packetUID")->setString(buffer);
@ -257,18 +259,17 @@ void insertIntoDB(void)
sprintf(buffer, "%f", p.htuTemp); sprintf(buffer, "%f", p.htuTemp);
postData("htu_tmp")->setString(buffer); postData("htu_tmp")->setString(buffer);
if(DBHost.sendHttpQuery(HttpClient::HttpRequestMethod::POST, NULL, &postData)) if((result = DBHost.sendHttpQuery(HttpClient::HttpRequestMethod::POST, NULL, &postData)) == 0)
{ {
Serial.println("Data posted successfully"); Serial.println("Data posted successfully");
HttpClient::HTTP_CODE response = DBHost.isReplyAvailable(2000); HttpClient::HTTP_CODE response = DBHost.isReplyAvailable(2000);
Serial.printf("Got response code : %u\n", response); Serial.printf("Got response code : %u\n", response);
DBHost.stop();
} }
else else
{ {
Serial.println("Failed to post data"); Serial.printf("Failed to post data : error(%d)\n", result);
DBHost.stop();
} }
DBHost.stop();
} }
void debugStruct(DataPacket *p) void debugStruct(DataPacket *p)