|
@ -141,7 +141,7 @@ class RestApi { |
|
|
DPRINTLN(DBG_VERBOSE, "onApiPostBody"); |
|
|
DPRINTLN(DBG_VERBOSE, "onApiPostBody"); |
|
|
|
|
|
|
|
|
if(0 == index) { |
|
|
if(0 == index) { |
|
|
if(NULL != mTmpBuf) |
|
|
if(nullptr != mTmpBuf) |
|
|
delete[] mTmpBuf; |
|
|
delete[] mTmpBuf; |
|
|
mTmpBuf = new uint8_t[total+1]; |
|
|
mTmpBuf = new uint8_t[total+1]; |
|
|
mTmpSize = total; |
|
|
mTmpSize = total; |
|
@ -154,36 +154,40 @@ class RestApi { |
|
|
|
|
|
|
|
|
DynamicJsonDocument json(1000); |
|
|
DynamicJsonDocument json(1000); |
|
|
|
|
|
|
|
|
DeserializationError err = deserializeJson(json, reinterpret_cast<const char*>(mTmpBuf), mTmpSize); |
|
|
|
|
|
JsonObject obj = json.as<JsonObject>(); |
|
|
|
|
|
|
|
|
|
|
|
AsyncJsonResponse* response = new AsyncJsonResponse(false, 200); |
|
|
AsyncJsonResponse* response = new AsyncJsonResponse(false, 200); |
|
|
JsonObject root = response->getRoot(); |
|
|
JsonObject root = response->getRoot(); |
|
|
root[F("success")] = (err) ? false : true; |
|
|
DeserializationError err = deserializeJson(json, reinterpret_cast<const char*>(mTmpBuf), mTmpSize); |
|
|
if(!err) { |
|
|
if(!json.is<JsonObject>()) |
|
|
String path = request->url().substring(5); |
|
|
root[F("error")] = F(DESER_FAILED); |
|
|
if(path == "ctrl") |
|
|
else { |
|
|
root[F("success")] = setCtrl(obj, root, request->client()->remoteIP().toString().c_str()); |
|
|
JsonObject obj = json.as<JsonObject>(); |
|
|
else if(path == "setup") |
|
|
|
|
|
root[F("success")] = setSetup(obj, root, request->client()->remoteIP().toString().c_str()); |
|
|
root[F("success")] = (err) ? false : true; |
|
|
else { |
|
|
if(!err) { |
|
|
root[F("success")] = false; |
|
|
String path = request->url().substring(5); |
|
|
root[F("error")] = F(PATH_NOT_FOUND) + path; |
|
|
if(path == "ctrl") |
|
|
} |
|
|
root[F("success")] = setCtrl(obj, root, request->client()->remoteIP().toString().c_str()); |
|
|
} else { |
|
|
else if(path == "setup") |
|
|
switch (err.code()) { |
|
|
root[F("success")] = setSetup(obj, root, request->client()->remoteIP().toString().c_str()); |
|
|
case DeserializationError::Ok: break; |
|
|
else { |
|
|
case DeserializationError::IncompleteInput: root[F("error")] = F(INCOMPLETE_INPUT); break; |
|
|
root[F("success")] = false; |
|
|
case DeserializationError::InvalidInput: root[F("error")] = F(INVALID_INPUT); break; |
|
|
root[F("error")] = F(PATH_NOT_FOUND) + path; |
|
|
case DeserializationError::NoMemory: root[F("error")] = F(NOT_ENOUGH_MEM); break; |
|
|
} |
|
|
default: root[F("error")] = F(DESER_FAILED); break; |
|
|
} 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(); |
|
|
response->setLength(); |
|
|
request->send(response); |
|
|
request->send(response); |
|
|
delete[] mTmpBuf; |
|
|
delete[] mTmpBuf; |
|
|
mTmpBuf = NULL; |
|
|
mTmpBuf = nullptr; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void getNotFound(JsonObject obj, String url) { |
|
|
void getNotFound(JsonObject obj, String url) { |
|
@ -422,7 +426,7 @@ class RestApi { |
|
|
obj[F("name")] = String(iv->config->name); |
|
|
obj[F("name")] = String(iv->config->name); |
|
|
obj[F("rx_success")] = iv->radioStatistics.rxSuccess; |
|
|
obj[F("rx_success")] = iv->radioStatistics.rxSuccess; |
|
|
obj[F("rx_fail")] = iv->radioStatistics.rxFail; |
|
|
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("frame_cnt")] = iv->radioStatistics.frmCnt; |
|
|
obj[F("tx_cnt")] = iv->radioStatistics.txCnt; |
|
|
obj[F("tx_cnt")] = iv->radioStatistics.txCnt; |
|
|
obj[F("retransmits")] = iv->radioStatistics.retransmits; |
|
|
obj[F("retransmits")] = iv->radioStatistics.retransmits; |
|
@ -480,7 +484,6 @@ class RestApi { |
|
|
obj[F("strtWthtTm")] = (bool)mConfig->inst.startWithoutTime; |
|
|
obj[F("strtWthtTm")] = (bool)mConfig->inst.startWithoutTime; |
|
|
obj[F("rdGrid")] = (bool)mConfig->inst.readGrid; |
|
|
obj[F("rdGrid")] = (bool)mConfig->inst.readGrid; |
|
|
obj[F("rstMaxMid")] = (bool)mConfig->inst.rstMaxValsMidNight; |
|
|
obj[F("rstMaxMid")] = (bool)mConfig->inst.rstMaxValsMidNight; |
|
|
obj[F("yldEff")] = mConfig->inst.yieldEffiency; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void getInverter(JsonObject obj, uint8_t id) { |
|
|
void getInverter(JsonObject obj, uint8_t id) { |
|
@ -998,7 +1001,7 @@ class RestApi { |
|
|
uint32_t mTimezoneOffset = 0; |
|
|
uint32_t mTimezoneOffset = 0; |
|
|
uint32_t mHeapFree = 0, mHeapFreeBlk = 0; |
|
|
uint32_t mHeapFree = 0, mHeapFreeBlk = 0; |
|
|
uint8_t mHeapFrag = 0; |
|
|
uint8_t mHeapFrag = 0; |
|
|
uint8_t *mTmpBuf = NULL; |
|
|
uint8_t *mTmpBuf = nullptr; |
|
|
uint32_t mTmpSize = 0; |
|
|
uint32_t mTmpSize = 0; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|