Reintroduce 'ROOTAPI' so domain and protocol can be configured

eg. setter for api root added as comment in examples/BASIC/BASIC.ino
This commit is contained in:
John
2024-07-21 19:38:50 +12:00
parent a9d9c60dfa
commit 7b9dac756b
3 changed files with 15 additions and 6 deletions

View File

@ -22,6 +22,7 @@ AgApiClient::~AgApiClient() {}
void AgApiClient::begin(void) {
getConfigFailed = false;
postToServerFailed = false;
logInfo("Init apiRoot: " + apiRoot);
logInfo("begin");
}
@ -44,9 +45,8 @@ bool AgApiClient::fetchServerConfiguration(void) {
return false;
}
String uri =
"http://hw.airgradient.com/sensors/airgradient:" + ag->deviceId() +
"/one/config";
String uri = apiRoot + "/sensors/airgradient:" +
ag->deviceId() + "/one/config";
/** Init http client */
#ifdef ESP8266
@ -109,9 +109,8 @@ bool AgApiClient::postToServer(String data) {
return false;
}
String uri =
"http://hw.airgradient.com/sensors/airgradient:" + ag->deviceId() +
"/measures";
String uri = apiRoot + "/sensors/airgradient:" +
ag->deviceId() + "/measures";
logInfo("Post uri: " + uri);
logInfo("Post data: " + data);
@ -177,3 +176,7 @@ bool AgApiClient::sendPing(int rssi, int bootCount) {
root["boot"] = bootCount;
return postToServer(JSON.stringify(root));
}
String AgApiClient::getApiRoot() const { return apiRoot; }
void AgApiClient::setApiRoot(const String &apiRoot) { this->apiRoot = apiRoot; }