mirror of
https://github.com/lumapu/ahoy.git
synced 2025-08-06 01:48:19 +02:00
Merge branch 'development03' into zero-export
This commit is contained in:
commit
053a2e0079
22 changed files with 190 additions and 121 deletions
|
@ -141,7 +141,7 @@ class RestApi {
|
|||
DPRINTLN(DBG_VERBOSE, "onApiPostBody");
|
||||
|
||||
if(0 == index) {
|
||||
if(NULL != mTmpBuf)
|
||||
if(nullptr != mTmpBuf)
|
||||
delete[] mTmpBuf;
|
||||
mTmpBuf = new uint8_t[total+1];
|
||||
mTmpSize = total;
|
||||
|
@ -154,36 +154,40 @@ class RestApi {
|
|||
|
||||
DynamicJsonDocument json(1000);
|
||||
|
||||
DeserializationError err = deserializeJson(json, reinterpret_cast<const char*>(mTmpBuf), mTmpSize);
|
||||
JsonObject obj = json.as<JsonObject>();
|
||||
|
||||
AsyncJsonResponse* response = new AsyncJsonResponse(false, 200);
|
||||
JsonObject root = response->getRoot();
|
||||
root[F("success")] = (err) ? false : true;
|
||||
if(!err) {
|
||||
String path = request->url().substring(5);
|
||||
if(path == "ctrl")
|
||||
root[F("success")] = setCtrl(obj, root, request->client()->remoteIP().toString().c_str());
|
||||
else if(path == "setup")
|
||||
root[F("success")] = setSetup(obj, root, request->client()->remoteIP().toString().c_str());
|
||||
else {
|
||||
root[F("success")] = false;
|
||||
root[F("error")] = F(PATH_NOT_FOUND) + path;
|
||||
}
|
||||
} else {
|
||||
switch (err.code()) {
|
||||
case DeserializationError::Ok: break;
|
||||
case DeserializationError::IncompleteInput: root[F("error")] = F(INCOMPLETE_INPUT); break;
|
||||
case DeserializationError::InvalidInput: root[F("error")] = F(INVALID_INPUT); break;
|
||||
case DeserializationError::NoMemory: root[F("error")] = F(NOT_ENOUGH_MEM); break;
|
||||
default: root[F("error")] = F(DESER_FAILED); break;
|
||||
DeserializationError err = deserializeJson(json, reinterpret_cast<const char*>(mTmpBuf), mTmpSize);
|
||||
if(!json.is<JsonObject>())
|
||||
root[F("error")] = F(DESER_FAILED);
|
||||
else {
|
||||
JsonObject obj = json.as<JsonObject>();
|
||||
|
||||
root[F("success")] = (err) ? false : true;
|
||||
if(!err) {
|
||||
String path = request->url().substring(5);
|
||||
if(path == "ctrl")
|
||||
root[F("success")] = setCtrl(obj, root, request->client()->remoteIP().toString().c_str());
|
||||
else if(path == "setup")
|
||||
root[F("success")] = setSetup(obj, root, request->client()->remoteIP().toString().c_str());
|
||||
else {
|
||||
root[F("success")] = false;
|
||||
root[F("error")] = F(PATH_NOT_FOUND) + path;
|
||||
}
|
||||
} else {
|
||||
switch (err.code()) {
|
||||
case DeserializationError::Ok: break;
|
||||
case DeserializationError::IncompleteInput: root[F("error")] = F(INCOMPLETE_INPUT); break;
|
||||
case DeserializationError::InvalidInput: root[F("error")] = F(INVALID_INPUT); break;
|
||||
case DeserializationError::NoMemory: root[F("error")] = F(NOT_ENOUGH_MEM); break;
|
||||
default: root[F("error")] = F(DESER_FAILED); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
delete[] mTmpBuf;
|
||||
mTmpBuf = NULL;
|
||||
mTmpBuf = nullptr;
|
||||
}
|
||||
|
||||
void getNotFound(JsonObject obj, String url) {
|
||||
|
@ -422,7 +426,7 @@ class RestApi {
|
|||
obj[F("name")] = String(iv->config->name);
|
||||
obj[F("rx_success")] = iv->radioStatistics.rxSuccess;
|
||||
obj[F("rx_fail")] = iv->radioStatistics.rxFail;
|
||||
obj[F("rx_fail_answer")] = iv->radioStatistics.rxFailNoAnser;
|
||||
obj[F("rx_fail_answer")] = iv->radioStatistics.rxFailNoAnswer;
|
||||
obj[F("frame_cnt")] = iv->radioStatistics.frmCnt;
|
||||
obj[F("tx_cnt")] = iv->radioStatistics.txCnt;
|
||||
obj[F("retransmits")] = iv->radioStatistics.retransmits;
|
||||
|
@ -480,7 +484,6 @@ class RestApi {
|
|||
obj[F("strtWthtTm")] = (bool)mConfig->inst.startWithoutTime;
|
||||
obj[F("rdGrid")] = (bool)mConfig->inst.readGrid;
|
||||
obj[F("rstMaxMid")] = (bool)mConfig->inst.rstMaxValsMidNight;
|
||||
obj[F("yldEff")] = mConfig->inst.yieldEffiency;
|
||||
}
|
||||
|
||||
void getInverter(JsonObject obj, uint8_t id) {
|
||||
|
@ -998,7 +1001,7 @@ class RestApi {
|
|||
uint32_t mTimezoneOffset = 0;
|
||||
uint32_t mHeapFree = 0, mHeapFreeBlk = 0;
|
||||
uint8_t mHeapFrag = 0;
|
||||
uint8_t *mTmpBuf = NULL;
|
||||
uint8_t *mTmpBuf = nullptr;
|
||||
uint32_t mTmpSize = 0;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue