Browse Source

* start creation of visualisation api contents

* removed /json part -> moved to API
* added missing update.html
pull/283/head
lumapu 2 years ago
parent
commit
810e16df6e
  1. 26
      tools/esp8266/app.cpp
  2. 1
      tools/esp8266/app.h
  3. 2
      tools/esp8266/html/index.html
  4. 25
      tools/esp8266/html/update.html
  5. 8
      tools/esp8266/web.cpp
  6. 1
      tools/esp8266/web.h
  7. 78
      tools/esp8266/webApi.cpp
  8. 1
      tools/esp8266/webApi.h

26
tools/esp8266/app.cpp

@ -498,32 +498,6 @@ void app::cbMqtt(char* topic, byte* payload, unsigned int length) {
}
//-----------------------------------------------------------------------------
String app::getJson(void) {
DPRINTLN(DBG_VERBOSE, F("app::showJson"));
String modJson;
modJson = F("{\n");
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
Inverter<> *iv = mSys->getInverterByPos(id);
if(NULL != iv) {
char topic[40], val[25];
snprintf(topic, 30, "\"%s\": {\n", iv->name);
modJson += String(topic);
for(uint8_t i = 0; i < iv->listLen; i++) {
snprintf(topic, 40, "\t\"ch%d/%s\"", iv->assign[i].ch, iv->getFieldName(i));
snprintf(val, 25, "[%.3f, \"%s\"]", iv->getValue(i), iv->getUnit(i));
modJson += String(topic) + ": " + String(val) + F(",\n");
}
modJson += F("\t\"last_msg\": \"") + getDateTimeStr(iv->ts) + F("\"\n\t},\n");
}
}
modJson += F("\"json_ts\": \"") + String(getDateTimeStr(mTimestamp)) + F("\"\n}\n");
return modJson;
}
//-----------------------------------------------------------------------------
bool app::getWifiApActive(void) {
return mWifi->getApActive();

1
tools/esp8266/app.h

@ -62,7 +62,6 @@ class app {
void cbMqtt(char* topic, byte* payload, unsigned int length);
void saveValues(void);
void resetPayload(Inverter<>* iv);
String getJson(void);
bool getWifiApActive(void);
uint8_t getIrqPin(void) {

2
tools/esp8266/html/index.html

@ -80,7 +80,7 @@
html += "producing\n";
if(false == i["is_avail"]) {
var date = new Date(i["ts_last_succes"] * 1000);
var date = new Date(i["ts_last_success"] * 1000);
html += "-> last successful transmission: " + date.toLocaleString('de-DE', {timeZone: 'UTC'});
}

25
tools/esp8266/html/update.html

@ -0,0 +1,25 @@
<!doctype html>
<html>
<head>
<title>Update</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
{#HEAD}
</head>
<body>
<h1>Update</h1>
<div id="content" class="content">
<div>
Make sure that you have noted all or settings before starting an update. New versions maybe changed their memory layout which remains in default settings.
</div>
<br/><br/>
{#CONTENT}
</div>
<div id="footer">
<p class="left">&copy 2022</p>
<p class="left"><a href="{#IP}/">Home</a></p>
<p class="right">AHOY :: {#VERSION}</p>
<p class="right"><a href="/reboot">Reboot</a></p>
</div>
</body>
</html>

8
tools/esp8266/web.cpp

@ -53,7 +53,6 @@ void web::setup(void) {
mWeb->on("/visualization", HTTP_ANY, std::bind(&web::showVisualization, this, std::placeholders::_1));
mWeb->on("/livedata", HTTP_ANY, std::bind(&web::showLiveData, this, std::placeholders::_1));
mWeb->on("/json", HTTP_ANY, std::bind(&web::showJson, this, std::placeholders::_1));
mWeb->on("/api1", HTTP_POST, std::bind(&web::showWebApi, this, std::placeholders::_1));
@ -413,13 +412,6 @@ void web::showLiveData(AsyncWebServerRequest *request) {
}
//-----------------------------------------------------------------------------
void web::showJson(AsyncWebServerRequest *request) {
DPRINTLN(DBG_VERBOSE, F("web::showJson"));
request->send(200, F("application/json"), mMain->getJson());
}
//-----------------------------------------------------------------------------
void web::showWebApi(AsyncWebServerRequest *request)
{

1
tools/esp8266/web.h

@ -39,7 +39,6 @@ class web {
void showVisualization(AsyncWebServerRequest *request);
void showLiveData(AsyncWebServerRequest *request);
void showJson(AsyncWebServerRequest *request);
void showWebApi(AsyncWebServerRequest *request);
void showUpdateForm(AsyncWebServerRequest *request);

78
tools/esp8266/webApi.cpp

@ -48,6 +48,7 @@ void webApi::onApi(AsyncWebServerRequest *request) {
else if(path == "serial") getSerial(root);
else if(path == "index") getIndex(root);
else if(path == "setup") getSetup(root);
else if(path == "live") getLive(root);
else
getNotFound(root, F("http://") + request->host() + F("/api/"));
@ -86,20 +87,20 @@ void webApi::getInverterList(JsonObject obj) {
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
iv = mApp->mSys->getInverterByPos(i);
if(NULL != iv) {
JsonObject obj = invArr.createNestedObject();
obj[F("id")] = i;
obj[F("name")] = String(iv->name);
obj[F("serial")] = String(iv->serial.u64, HEX);
obj[F("channels")] = iv->channels;
obj[F("version")] = String(iv->fwVersion);
JsonObject obj2 = invArr.createNestedObject();
obj2[F("id")] = i;
obj2[F("name")] = String(iv->name);
obj2[F("serial")] = String(iv->serial.u64, HEX);
obj2[F("channels")] = iv->channels;
obj2[F("version")] = String(iv->fwVersion);
for(uint8_t j = 0; j < iv->channels; j ++) {
obj[F("ch_max_power")][j] = iv->chMaxPwr[j];
obj[F("ch_name")][j] = iv->chName[j];
obj2[F("ch_max_power")][j] = iv->chMaxPwr[j];
obj2[F("ch_name")][j] = iv->chName[j];
}
obj[F("power_limit")] = iv->powerLimit[0];
obj[F("power_limit_option")] = iv->powerLimit[1];
obj2[F("power_limit")] = iv->powerLimit[0];
obj2[F("power_limit_option")] = iv->powerLimit[1];
}
}
obj[F("interval")] = String(mConfig->sendInterval);
@ -160,6 +161,7 @@ void webApi::getNotFound(JsonObject obj, String url) {
ep[F("serial")] = url + F("serial");
ep[F("index")] = url + F("index");
ep[F("setup")] = url + F("setup");
ep[F("live")] = url + F("live");
}
@ -210,3 +212,59 @@ void webApi::getSetup(JsonObject obj) {
getRadio(obj.createNestedObject(F("radio")));
getSerial(obj.createNestedObject(F("serial")));
}
//-----------------------------------------------------------------------------
void webApi::getLive(JsonObject obj) {
JsonArray invArr = obj.createNestedArray(F("inverter"));
uint8_t list[] = {FLD_UAC, FLD_IAC, FLD_PAC, FLD_F, FLD_PCT, FLD_T, FLD_YT, FLD_YD, FLD_PDC, FLD_EFF, FLD_PRA, FLD_ALARM_MES_ID};
Inverter<> *iv;
uint8_t pos;
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
iv = mApp->mSys->getInverterByPos(i);
if(NULL != iv) {
JsonObject obj2 = invArr.createNestedObject();
obj2[F("id")] = i;
obj2[F("name")] = String(iv->name);
obj2[F("channels")] = iv->channels;
obj2[F("power_limit_read")] = iv->actPowerLimit;
obj2[F("power_limit_active")] = NoPowerLimit != iv->powerLimit[1];
obj2[F("last_alarm")] = String(iv->lastAlarmMsg);
obj2[F("ts_last_success")] = iv->ts;
JsonArray ch = obj2.createNestedArray("ch");
JsonArray ch0 = ch.createNestedArray();
for (uint8_t fld = 0; fld < 11; fld++) {
pos = (iv->getPosByChFld(CH0, list[fld]));
if (0xff != pos) {
JsonObject dat = ch0.createNestedObject();
dat[F("value")] = iv->getValue(pos);
dat[F("unit")] = String(iv->getUnit(pos));
dat[F("name")] = String(iv->getFieldName(pos));
}
}
for(uint8_t j = 0; j < iv->channels; j ++) {
obj2[F("ch_names")][j] = iv->chName[j];
JsonArray cur = ch.createNestedArray();
for (uint8_t k = 0; k < 6; k++) {
switch(k) {
default: pos = (iv->getPosByChFld(j, FLD_UDC)); break;
case 1: pos = (iv->getPosByChFld(j, FLD_IDC)); break;
case 2: pos = (iv->getPosByChFld(j, FLD_PDC)); break;
case 3: pos = (iv->getPosByChFld(j, FLD_YD)); break;
case 4: pos = (iv->getPosByChFld(j, FLD_YT)); break;
case 5: pos = (iv->getPosByChFld(j, FLD_IRR)); break;
}
cur[k] = (0xff != pos) ? iv->getValue(pos) : 0;
if(0xff != pos) {
obj2[F("fld_units")][k] = String(iv->getUnit(pos));
obj2[F("fld_names")][k] = String(iv->getFieldName(pos));
}
}
}
}
}
}

1
tools/esp8266/webApi.h

@ -32,6 +32,7 @@ class webApi {
void getNotFound(JsonObject obj, String url);
void getIndex(JsonObject obj);
void getSetup(JsonObject obj);
void getLive(JsonObject obj);
AsyncWebServer *mSrv;
app *mApp;

Loading…
Cancel
Save