mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-31 01:36:11 +02:00
* start creation of visualisation api contents
* removed /json part -> moved to API * added missing update.html
This commit is contained in:
parent
78a9db5767
commit
810e16df6e
8 changed files with 95 additions and 47 deletions
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
Normal file
25
tools/esp8266/html/update.html
Normal file
|
@ -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">© 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>
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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…
Add table
Add a link
Reference in a new issue