Browse Source

change from counting to millis()

pull/1155/head
DanielR92 2 years ago
parent
commit
b8994248fd
  1. 42
      src/app.cpp
  2. 6
      src/config/settings.h
  3. 15
      src/plugins/zeroExport/zeroExport.h
  4. 2
      src/web/RestApi.h

42
src/app.cpp

@ -593,29 +593,33 @@ void app::updateLed(void) {
//-----------------------------------------------------------------------------
#if defined(ESP32)
void app::zeroexport() {
if (!mConfig->plugin.zexport.enabled &&
!mConfig->plugin.zexport.rdytoSend) return; // check if plugin is enabled && indicate to send new value
if (!mConfig->plugin.zexport.enabled) return; // check if plugin is enabled && indicate to send new value
Inverter<> *iv = mSys.getInverterByPos(mConfig->plugin.zexport.Iv);
if (millis() - mConfig->plugin.zexport.lastTime < mConfig->plugin.zexport.count_avg * 1000UL)
{
Inverter<> *iv = mSys.getInverterByPos(mConfig->plugin.zexport.Iv);
DynamicJsonDocument doc(512);
JsonObject object = doc.to<JsonObject>();
DynamicJsonDocument doc(512);
JsonObject object = doc.to<JsonObject>();
double nValue = round(mzExport.getPowertoSetnewValue());
double twoPerVal = nValue <= (iv->getMaxPower() / 100 * 2 );
if(mConfig->plugin.zexport.two_percent && (nValue <= twoPerVal)) {
object["val"] = twoPerVal;
} else {
object["val"] = nValue;
}
double nValue = round(mzExport.getPowertoSetnewValue());
double twoPerVal = nValue <= (iv->getMaxPower() / 100 * 2 );
if(mConfig->plugin.zexport.two_percent && (nValue <= twoPerVal)) {
object["val"] = twoPerVal;
} else {
object["val"] = nValue;
}
object["id"] = mConfig->plugin.zexport.Iv;
object["path"] = "ctrl";
object["cmd"] = "limit_nonpersistent_absolute";
object["id"] = mConfig->plugin.zexport.Iv;
object["path"] = "ctrl";
object["cmd"] = "limit_nonpersistent_absolute";
String data;
serializeJsonPretty(object, data);
DPRINTLN(DBG_INFO, data);
mApi.ctrlRequest(object);
}
String data;
serializeJsonPretty(object, data);
DPRINTLN(DBG_INFO, data);
mApi.ctrlRequest(object);
mConfig->plugin.zexport.lastTime = millis(); // set last timestamp
}
#endif

6
src/config/settings.h

@ -143,11 +143,12 @@ typedef struct {
uint8_t device; // save the monitor device (1 - Shelly; 2 - Hichi;)
uint8_t Iv; // saves the inverter that is used for regulation
bool enabled;
bool rdytoSend; // indicate to send new value
float power_avg;
uint8_t count_avg;
double total_power;
unsigned long lastTime; // tic toc
bool two_percent; // ask if not go lower then 2%
} cfgzeroExport_t;
#endif
@ -457,8 +458,9 @@ class settings {
#if defined(ESP32)
snprintf(mCfg.plugin.zexport.monitor_ip, ZEXPORT_ADDR_LEN, "%s", DEF_ZEXPORT);
mCfg.plugin.zexport.enabled = false;
mCfg.plugin.zexport.rdytoSend = false;
mCfg.plugin.zexport.count_avg = 10;
mCfg.plugin.zexport.lastTime = millis(); // do not change!
mCfg.plugin.zexport.power_avg = 10;
mCfg.plugin.zexport.device = 0;
mCfg.plugin.zexport.Iv = 0;

15
src/plugins/zeroExport/zeroExport.h

@ -20,15 +20,11 @@ class ZeroExport {
mConfig = config;
}
void payloadEventListener(uint8_t cmd) {
mCfg->rdytoSend = false;
}
void tickerSecond() {
if (!mCfg->rdytoSend || ((++mLoopCnt % mCfg->count_avg) == 0)) {
mCfg->rdytoSend = true;
mLoopCnt = 0;
zero();
//DPRINTLN(DBG_INFO, (F("tickerSecond()")));
if (millis() - mCfg->lastTime < mCfg->count_avg * 1000UL) {
zero(); // just refresh when it is needed. To get cpu load low.
//DPRINTLN(DBG_INFO, (F("zero()")));
}
}
@ -53,8 +49,6 @@ class ZeroExport {
private:
HTTPClient http;
void loop() { }
// TODO: Need to improve here. 2048 for a JSON Obj is to big!?
void zero() {
switch (mCfg->device) {
@ -117,7 +111,6 @@ class ZeroExport {
}
// private member variables
uint8_t mLoopCnt;
const char *mVersion;
cfgzeroExport_t *mCfg;

2
src/web/RestApi.h

@ -65,7 +65,7 @@ class RestApi {
void ctrlRequest(JsonObject obj) {
char out[128];
serializeJson(obj, out, 128);
DPRINTLN(DBG_INFO, "RestApi: " + String(out));
//DPRINTLN(DBG_INFO, "RestApi: " + String(out));
DynamicJsonDocument json(128);
JsonObject dummy = json.as<JsonObject>();
if(obj[F("path")] == "ctrl")

Loading…
Cancel
Save