log URLs of all HTTP requests to AG backend / log status codes of responses

This commit is contained in:
Phat Nguyen
2024-07-29 06:00:54 +07:00
parent 6c1c914716
commit ed7b8df6fe

View File

@ -66,6 +66,10 @@ bool AgApiClient::fetchServerConfiguration(void) {
/** Get data */ /** Get data */
int retCode = client.GET(); int retCode = client.GET();
logInfo(String("GET: ") + uri);
logInfo(String("Return code: ") + String(retCode));
if (retCode != 200) { if (retCode != 200) {
client.end(); client.end();
getConfigFailed = true; getConfigFailed = true;
@ -112,18 +116,22 @@ bool AgApiClient::postToServer(String data) {
String uri = String uri =
"http://hw.airgradient.com/sensors/airgradient:" + ag->deviceId() + "http://hw.airgradient.com/sensors/airgradient:" + ag->deviceId() +
"/measures"; "/measures";
logInfo("Post uri: " + uri); // logInfo("Post uri: " + uri);
logInfo("Post data: " + data); // logInfo("Post data: " + data);
WiFiClient wifiClient; WiFiClient wifiClient;
HTTPClient client; HTTPClient client;
if (client.begin(wifiClient, uri.c_str()) == false) { if (client.begin(wifiClient, uri.c_str()) == false) {
logError("Init client failed");
return false; return false;
} }
client.addHeader("content-type", "application/json"); client.addHeader("content-type", "application/json");
int retCode = client.POST(data); int retCode = client.POST(data);
client.end(); client.end();
logInfo(String("POST: ") + uri);
logInfo(String("Return code: ") + String(retCode));
if ((retCode == 200) || (retCode == 429)) { if ((retCode == 200) || (retCode == 429)) {
postToServerFailed = false; postToServerFailed = false;
return true; return true;