ve.direct:
- add poll rate - add data_age and age_critical to rest api
This commit is contained in:
parent
72c0e8579a
commit
d9bf0ab2e9
@ -77,6 +77,7 @@ struct CONFIG_T {
|
|||||||
|
|
||||||
bool Vedirect_Enabled;
|
bool Vedirect_Enabled;
|
||||||
bool Vedirect_UpdatesOnly;
|
bool Vedirect_UpdatesOnly;
|
||||||
|
uint32_t Vedirect_PollInterval;
|
||||||
|
|
||||||
char Mqtt_Hostname[MQTT_MAX_HOSTNAME_STRLEN + 1];
|
char Mqtt_Hostname[MQTT_MAX_HOSTNAME_STRLEN + 1];
|
||||||
};
|
};
|
||||||
|
|||||||
@ -78,3 +78,4 @@
|
|||||||
|
|
||||||
#define VEDIRECT_ENABLED false
|
#define VEDIRECT_ENABLED false
|
||||||
#define VEDIRECT_UPDATESONLY true
|
#define VEDIRECT_UPDATESONLY true
|
||||||
|
#define VEDIRECT_POLL_INTERVAL 5
|
||||||
@ -63,16 +63,27 @@ void VeDirectFrameHandler::init()
|
|||||||
Serial2.flush();
|
Serial2.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VeDirectFrameHandler::setPollInterval(uint32_t interval)
|
||||||
|
{
|
||||||
|
_pollInterval = interval;
|
||||||
|
}
|
||||||
|
|
||||||
void VeDirectFrameHandler::loop()
|
void VeDirectFrameHandler::loop()
|
||||||
{
|
{
|
||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
|
|
||||||
while ( Serial2.available()) {
|
if (millis() - _lastPoll > (_pollInterval * 1000)) {
|
||||||
if ((millis() - now) > 500) {
|
Serial.print(F("Start polling ve.direct interface... "));
|
||||||
now = millis();
|
|
||||||
yield();
|
while ( Serial2.available()) {
|
||||||
|
if ((millis() - now) > 500) {
|
||||||
|
now = millis();
|
||||||
|
yield();
|
||||||
|
}
|
||||||
|
rxData(Serial2.read());
|
||||||
}
|
}
|
||||||
rxData(Serial2.read());
|
_lastPoll = millis();
|
||||||
|
Serial.println(F("done"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,7 @@ public:
|
|||||||
|
|
||||||
VeDirectFrameHandler();
|
VeDirectFrameHandler();
|
||||||
void init();
|
void init();
|
||||||
|
void setPollInterval(uint32_t interval);
|
||||||
void loop();
|
void loop();
|
||||||
uint32_t getLastUpdate();
|
uint32_t getLastUpdate();
|
||||||
void setLastUpdate();
|
void setLastUpdate();
|
||||||
@ -74,6 +75,8 @@ private:
|
|||||||
void logE(const char *, const char *);
|
void logE(const char *, const char *);
|
||||||
bool hexRxEvent(uint8_t);
|
bool hexRxEvent(uint8_t);
|
||||||
uint32_t _lastUpdate = 0;
|
uint32_t _lastUpdate = 0;
|
||||||
|
uint32_t _pollInterval;
|
||||||
|
uint32_t _lastPoll = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern VeDirectFrameHandler VeDirect;
|
extern VeDirectFrameHandler VeDirect;
|
||||||
|
|||||||
@ -59,6 +59,7 @@ void ConfigurationClass::init()
|
|||||||
|
|
||||||
config.Vedirect_Enabled = VEDIRECT_ENABLED;
|
config.Vedirect_Enabled = VEDIRECT_ENABLED;
|
||||||
config.Vedirect_UpdatesOnly = VEDIRECT_UPDATESONLY;
|
config.Vedirect_UpdatesOnly = VEDIRECT_UPDATESONLY;
|
||||||
|
config.Vedirect_PollInterval = VEDIRECT_POLL_INTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigurationClass::write()
|
bool ConfigurationClass::write()
|
||||||
@ -150,6 +151,7 @@ void ConfigurationClass::migrate()
|
|||||||
strlcpy(config.Mqtt_RootCaCert, MQTT_ROOT_CA_CERT, sizeof(config.Mqtt_RootCaCert));
|
strlcpy(config.Mqtt_RootCaCert, MQTT_ROOT_CA_CERT, sizeof(config.Mqtt_RootCaCert));
|
||||||
config.Vedirect_Enabled = VEDIRECT_ENABLED;
|
config.Vedirect_Enabled = VEDIRECT_ENABLED;
|
||||||
config.Vedirect_UpdatesOnly = VEDIRECT_UPDATESONLY;
|
config.Vedirect_UpdatesOnly = VEDIRECT_UPDATESONLY;
|
||||||
|
config.Vedirect_PollInterval = VEDIRECT_POLL_INTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.Cfg_Version < 0x00011400) {
|
if (config.Cfg_Version < 0x00011400) {
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
* Copyright (C) 2022 Thomas Basler and others
|
* Copyright (C) 2022 Thomas Basler and others
|
||||||
*/
|
*/
|
||||||
#include "WebApi_vedirect.h"
|
#include "WebApi_vedirect.h"
|
||||||
|
#include "VeDirectFrameHandler.h"
|
||||||
#include "ArduinoJson.h"
|
#include "ArduinoJson.h"
|
||||||
#include "AsyncJson.h"
|
#include "AsyncJson.h"
|
||||||
#include "Configuration.h"
|
#include "Configuration.h"
|
||||||
@ -30,6 +31,7 @@ void WebApiVedirectClass::onVedirectStatus(AsyncWebServerRequest* request)
|
|||||||
CONFIG_T& config = Configuration.get();
|
CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
root[F("vedirect_enabled")] = config.Vedirect_Enabled;
|
root[F("vedirect_enabled")] = config.Vedirect_Enabled;
|
||||||
|
root[F("vedirect_pollinterval")] = config.Vedirect_PollInterval;
|
||||||
root[F("vedirect_updatesonly")] = config.Vedirect_UpdatesOnly;
|
root[F("vedirect_updatesonly")] = config.Vedirect_UpdatesOnly;
|
||||||
|
|
||||||
response->setLength();
|
response->setLength();
|
||||||
@ -43,6 +45,7 @@ void WebApiVedirectClass::onVedirectAdminGet(AsyncWebServerRequest* request)
|
|||||||
CONFIG_T& config = Configuration.get();
|
CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
root[F("vedirect_enabled")] = config.Vedirect_Enabled;
|
root[F("vedirect_enabled")] = config.Vedirect_Enabled;
|
||||||
|
root[F("vedirect_pollinterval")] = config.Vedirect_PollInterval;
|
||||||
root[F("vedirect_updatesonly")] = config.Vedirect_UpdatesOnly;
|
root[F("vedirect_updatesonly")] = config.Vedirect_UpdatesOnly;
|
||||||
|
|
||||||
response->setLength();
|
response->setLength();
|
||||||
@ -81,16 +84,24 @@ void WebApiVedirectClass::onVedirectAdminPost(AsyncWebServerRequest* request)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(root.containsKey("vedirect_enabled"))) {
|
if (!(root.containsKey("vedirect_enabled") && root.containsKey("vedirect_pollinterval") && root.containsKey("vedirect_updatesonly")) ) {
|
||||||
retMsg[F("message")] = F("Values are missing!");
|
retMsg[F("message")] = F("Values are missing!");
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (root[F("vedirect_pollinterval")].as<uint32_t>() == 0) {
|
||||||
|
retMsg[F("message")] = F("Poll interval must be greater zero!");
|
||||||
|
response->setLength();
|
||||||
|
request->send(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CONFIG_T& config = Configuration.get();
|
CONFIG_T& config = Configuration.get();
|
||||||
config.Vedirect_Enabled = root[F("vedirect_enabled")].as<bool>();
|
config.Vedirect_Enabled = root[F("vedirect_enabled")].as<bool>();
|
||||||
config.Vedirect_UpdatesOnly = root[F("vedirect_updatesonly")].as<bool>();
|
config.Vedirect_UpdatesOnly = root[F("vedirect_updatesonly")].as<bool>();
|
||||||
|
config.Vedirect_PollInterval = root[F("vedirect_pollinterval")].as<uint32_t>();
|
||||||
Configuration.write();
|
Configuration.write();
|
||||||
|
|
||||||
retMsg[F("type")] = F("success");
|
retMsg[F("type")] = F("success");
|
||||||
@ -99,5 +110,5 @@ void WebApiVedirectClass::onVedirectAdminPost(AsyncWebServerRequest* request)
|
|||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
|
|
||||||
|
VeDirect.setPollInterval(config.Vedirect_PollInterval);
|
||||||
}
|
}
|
||||||
@ -105,6 +105,8 @@ void WebApiWsVedirectLiveClass::generateJsonResponse(JsonVariant& root)
|
|||||||
root[F(VeDirect.veName[i])] = VeDirect.veValue[i];
|
root[F(VeDirect.veName[i])] = VeDirect.veValue[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
root[F("data_age")] = (millis() - VeDirect.getLastUpdate() ) / 1000;
|
||||||
|
root[F("age_critical")] = ((millis() - VeDirect.getLastUpdate()) / 1000) > Configuration.get().Vedirect_PollInterval * 5;
|
||||||
|
|
||||||
if (VeDirect.getLastUpdate() > _newestVedirectTimestamp) {
|
if (VeDirect.getLastUpdate() > _newestVedirectTimestamp) {
|
||||||
_newestVedirectTimestamp = VeDirect.getLastUpdate();
|
_newestVedirectTimestamp = VeDirect.getLastUpdate();
|
||||||
|
|||||||
@ -103,6 +103,7 @@ void setup()
|
|||||||
// Initialize ve.direct communication
|
// Initialize ve.direct communication
|
||||||
Serial.print(F("Initialize ve.direct interface... "));
|
Serial.print(F("Initialize ve.direct interface... "));
|
||||||
VeDirect.init();
|
VeDirect.init();
|
||||||
|
VeDirect.setPollInterval(config.Vedirect_PollInterval);
|
||||||
Serial.println(F("done"));
|
Serial.println(F("done"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,14 +18,25 @@
|
|||||||
<div class="card-header text-white bg-primary">Ve.direct Configuration</div>
|
<div class="card-header text-white bg-primary">Ve.direct Configuration</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<label class="col-sm-4 form-check-label" for="inputVedirect">Enable Ve.direct</label>
|
<label class="col-sm-2 form-check-label" for="inputVedirect">Enable Ve.direct</label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-10">
|
||||||
<div class="form-check form-switch">
|
<div class="form-check form-switch">
|
||||||
<input class="form-check-input" type="checkbox" id="inputVedirect"
|
<input class="form-check-input" type="checkbox" id="inputVedirect"
|
||||||
v-model="vedirectConfigList.vedirect_enabled" />
|
v-model="vedirectConfigList.vedirect_enabled" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row mb-3" v-show="vedirectConfigList.vedirect_enabled">
|
||||||
|
<label for="inputPollInterval" class="col-sm-2 col-form-label">Poll Interval:</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<div class="input-group">
|
||||||
|
<input type="number" class="form-control" id="inputPollInterval" min="1" max="86400"
|
||||||
|
placeholder="Poll Interval in Seconds" v-model="vedirectConfigList.vedirect_pollinterval"
|
||||||
|
aria-describedby="pollIntervalDescription" />
|
||||||
|
<span class="input-group-text" id="pollIntervalDescription">seconds</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row mb-3" v-show="vedirectConfigList.vedirect_enabled">
|
<div class="row mb-3" v-show="vedirectConfigList.vedirect_enabled">
|
||||||
<label class="col-sm-2 form-check-label" for="inputTls">Send only updates</label>
|
<label class="col-sm-2 form-check-label" for="inputTls">Send only updates</label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
@ -57,6 +68,7 @@ export default defineComponent({
|
|||||||
dataLoading: true,
|
dataLoading: true,
|
||||||
vedirectConfigList: {
|
vedirectConfigList: {
|
||||||
vedirect_enabled: false,
|
vedirect_enabled: false,
|
||||||
|
vedirect_pollinterval: 0,
|
||||||
vedirect_updatesonly: true,
|
vedirect_updatesonly: true,
|
||||||
},
|
},
|
||||||
alertMessage: "",
|
alertMessage: "",
|
||||||
|
|||||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user