forked from airgradienthq/arduino
Merge pull request #232 from samuelbles07/feat/ag-client-timeout
Feat/ag-client-timeout
This commit is contained in:
@ -58,6 +58,7 @@ bool AgApiClient::fetchServerConfiguration(void) {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
HTTPClient client;
|
HTTPClient client;
|
||||||
|
client.setTimeout(timeoutMs);
|
||||||
if (client.begin(uri) == false) {
|
if (client.begin(uri) == false) {
|
||||||
getConfigFailed = true;
|
getConfigFailed = true;
|
||||||
return false;
|
return false;
|
||||||
@ -113,14 +114,13 @@ bool AgApiClient::postToServer(String data) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String uri =
|
String uri = apiRoot + "/sensors/airgradient:" + ag->deviceId() + "/measures";
|
||||||
"http://hw.airgradient.com/sensors/airgradient:" + ag->deviceId() +
|
|
||||||
"/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;
|
||||||
|
client.setTimeout(timeoutMs);
|
||||||
if (client.begin(wifiClient, uri.c_str()) == false) {
|
if (client.begin(wifiClient, uri.c_str()) == false) {
|
||||||
logError("Init client failed");
|
logError("Init client failed");
|
||||||
return false;
|
return false;
|
||||||
@ -190,3 +190,12 @@ bool AgApiClient::sendPing(int rssi, int bootCount) {
|
|||||||
String AgApiClient::getApiRoot() const { return apiRoot; }
|
String AgApiClient::getApiRoot() const { return apiRoot; }
|
||||||
|
|
||||||
void AgApiClient::setApiRoot(const String &apiRoot) { this->apiRoot = apiRoot; }
|
void AgApiClient::setApiRoot(const String &apiRoot) { this->apiRoot = apiRoot; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set http request timeout. (Default: 10s)
|
||||||
|
*
|
||||||
|
* @param timeoutMs
|
||||||
|
*/
|
||||||
|
void AgApiClient::setTimeout(uint16_t timeoutMs) {
|
||||||
|
this->timeoutMs = timeoutMs;
|
||||||
|
}
|
@ -25,6 +25,7 @@ private:
|
|||||||
bool getConfigFailed;
|
bool getConfigFailed;
|
||||||
bool postToServerFailed;
|
bool postToServerFailed;
|
||||||
bool notAvailableOnDashboard = false; // Device not setup on Airgradient cloud dashboard.
|
bool notAvailableOnDashboard = false; // Device not setup on Airgradient cloud dashboard.
|
||||||
|
uint16_t timeoutMs = 10000; // Default set to 10s
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AgApiClient(Stream &stream, Configuration &config);
|
AgApiClient(Stream &stream, Configuration &config);
|
||||||
@ -40,6 +41,7 @@ public:
|
|||||||
bool sendPing(int rssi, int bootCount);
|
bool sendPing(int rssi, int bootCount);
|
||||||
String getApiRoot() const;
|
String getApiRoot() const;
|
||||||
void setApiRoot(const String &apiRoot);
|
void setApiRoot(const String &apiRoot);
|
||||||
|
void setTimeout(uint16_t timeoutMs);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /** _AG_API_CLIENT_H_ */
|
#endif /** _AG_API_CLIENT_H_ */
|
||||||
|
Reference in New Issue
Block a user