Browse Source

fix sync time from browser issue

pull/421/head
lumapu 2 years ago
parent
commit
ef72fe9a40
  1. 2
      tools/esp8266/defines.h
  2. 15
      tools/esp8266/webApi.cpp
  3. 6
      tools/esp8266/webApi.h

2
tools/esp8266/defines.h

@ -13,7 +13,7 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 5
#define VERSION_PATCH 28
#define VERSION_PATCH 29
//-------------------------------------
typedef struct {

15
tools/esp8266/webApi.cpp

@ -80,14 +80,15 @@ void webApi::onApiPostBody(AsyncWebServerRequest *request, uint8_t *data, size_t
AsyncJsonResponse* response = new AsyncJsonResponse(false, 200);
JsonObject root = response->getRoot();
DeserializationError err = deserializeJson(json, (const char *)data);
DeserializationError err = deserializeJson(json, (const char *)data, len);
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(json, root);
root[F("success")] = setCtrl(obj, root);
else if(path == "setup")
root[F("success")] = setSetup(json, root);
root[F("success")] = setSetup(obj, root);
else {
root[F("success")] = false;
root[F("error")] = "Path not found: " + path;
@ -400,7 +401,7 @@ void webApi::getRecord(JsonObject obj, record_t<> *rec) {
//-----------------------------------------------------------------------------
bool webApi::setCtrl(DynamicJsonDocument jsonIn, JsonObject jsonOut) {
bool webApi::setCtrl(JsonObject jsonIn, JsonObject jsonOut) {
uint8_t cmd = jsonIn[F("cmd")];
// Todo: num is the inverter number 0-3. For better display in DPRINTLN
@ -458,8 +459,8 @@ bool webApi::setCtrl(DynamicJsonDocument jsonIn, JsonObject jsonOut) {
//-----------------------------------------------------------------------------
bool webApi::setSetup(DynamicJsonDocument jsonIn, JsonObject jsonOut) {
if(F("scan_wifi"))
bool webApi::setSetup(JsonObject jsonIn, JsonObject jsonOut) {
if(F("scan_wifi") == jsonIn[F("cmd")])
mApp->scanAvailNetworks();
else if(F("set_time") == jsonIn[F("cmd")])
mApp->setTimestamp(jsonIn[F("ts")]);
@ -479,7 +480,7 @@ bool webApi::setSetup(DynamicJsonDocument jsonIn, JsonObject jsonOut) {
//-----------------------------------------------------------------------------
Inverter<> *webApi::getInverter(DynamicJsonDocument jsonIn, JsonObject jsonOut) {
Inverter<> *webApi::getInverter(JsonObject jsonIn, JsonObject jsonOut) {
uint8_t id = jsonIn[F("inverter")];
Inverter<> *iv = mApp->mSys->getInverterByPos(id);
if(NULL == iv)

6
tools/esp8266/webApi.h

@ -49,10 +49,10 @@ class webApi {
void getLive(JsonObject obj);
void getRecord(JsonObject obj, record_t<> *rec);
bool setCtrl(DynamicJsonDocument jsonIn, JsonObject jsonOut);
bool setSetup(DynamicJsonDocument jsonIn, JsonObject jsonOut);
bool setCtrl(JsonObject jsonIn, JsonObject jsonOut);
bool setSetup(JsonObject jsonIn, JsonObject jsonOut);
Inverter<> *getInverter(DynamicJsonDocument jsonIn, JsonObject jsonOut);
Inverter<> *getInverter(JsonObject jsonIn, JsonObject jsonOut);
double round3(double value) {
return (int)(value * 1000 + 0.5) / 1000.0;

Loading…
Cancel
Save