Skip to content

Commit

Permalink
More development...
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Jun 17, 2024
1 parent 75a5f25 commit 00d7c10
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 34 deletions.
9 changes: 6 additions & 3 deletions include/YaSolRWebsite.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,15 @@ namespace YaSolR {
#endif

// home
Card _routerEnergy = Card(&dashboard, ENERGY_CARD, "Total Routed Energy", "kWh");
Card _routerPower = Card(&dashboard, ENERGY_CARD, "Total Routed Power", "W");
Card _routerPower = Card(&dashboard, ENERGY_CARD, "Routed Power", "W");
Card _routerApparentPower = Card(&dashboard, ENERGY_CARD, "Routed Apparent Power", "VA");
Card _routerPowerFactor = Card(&dashboard, ENERGY_CARD, "Router Power Factor");
Card _routerTHDi = Card(&dashboard, ENERGY_CARD, "Router THDi", "%");
Card _routerVoltage = Card(&dashboard, ENERGY_CARD, "Router Voltage", "V");
Card _routerCurrent = Card(&dashboard, ENERGY_CARD, "Routed Current", "A");
Card _routerResistance = Card(&dashboard, ENERGY_CARD, "Router Resistance", "Ω");
Card _routerEnergy = Card(&dashboard, ENERGY_CARD, "Routed Energy", "kWh");
Card _gridPower = Card(&dashboard, ENERGY_CARD, "Grid Power", "W");
Card _gridVoltage = Card(&dashboard, ENERGY_CARD, "Grid Voltage", "V");
Card _routerDS18State = Card(&dashboard, TEMPERATURE_CARD, "System Temperature", "°C");

#ifdef APP_MODEL_PRO
Expand Down
32 changes: 22 additions & 10 deletions lib/MycilaRouter/MycilaRouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace Mycila {
float energy = 0;
float power = 0;
float powerFactor = 0;
float resistance = 0;
float thdi = 0;
RouterOutputMetrics outputs[MYCILA_ROUTER_OUTPUT_COUNT] = {};
} RouterMetrics;
Expand All @@ -47,25 +48,36 @@ namespace Mycila {

void getMetrics(RouterMetrics& metrics) const {
size_t index = 0;
bool routing = false;

for (const auto& output : _outputs) {
assert(index < MYCILA_ROUTER_OUTPUT_COUNT);

output->getMetrics(metrics.outputs[index]);

metrics.apparentPower += metrics.outputs[index].apparentPower;
metrics.current += metrics.outputs[index].current;
if (output->getState() == RouterOutputState::OUTPUT_ROUTING) {
routing = true;
output->getMetrics(metrics.outputs[index]);
metrics.apparentPower += metrics.outputs[index].apparentPower;
metrics.current += metrics.outputs[index].current;
metrics.power += metrics.outputs[index].power;
}
metrics.energy += metrics.outputs[index].energy;
metrics.power += metrics.outputs[index].power;

index++;
}

metrics.powerFactor = metrics.apparentPower == 0 ? 0 : metrics.power / metrics.apparentPower;
metrics.thdi = metrics.powerFactor == 0 ? 0 : sqrt(1 / pow(metrics.powerFactor, 2) - 1);
if (routing && _jsy->isConnected()) {
if (!metrics.apparentPower)
metrics.apparentPower = _jsy->getApparentPower1();
if (!metrics.current)
metrics.current = _jsy->getCurrent1();
if (!metrics.power)
metrics.power = _jsy->getPower1();
}

if (metrics.energy == 0)
if (!metrics.energy)
metrics.energy = _jsy->getEnergy1() + _jsy->getEnergyReturned1();

metrics.powerFactor = metrics.apparentPower == 0 ? 0 : metrics.power / metrics.apparentPower;
metrics.resistance = metrics.current == 0 ? 0 : metrics.power / (metrics.current * metrics.current);
metrics.thdi = metrics.powerFactor == 0 ? 0 : sqrt(1 / pow(metrics.powerFactor, 2) - 1);
}

#ifdef MYCILA_JSON_SUPPORT
Expand Down
4 changes: 1 addition & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ lib_deps =
mathieucarbou/Async TCP @ 3.1.4
mathieucarbou/ESP Async WebServer @ 2.10.8
mathieucarbou/MycilaConfig @ 3.0.1
mathieucarbou/MycilaDS18 @ 2.0.1
mathieucarbou/MycilaDS18 @ 3.0.0
mathieucarbou/MycilaESPConnect @ 4.3.1
mathieucarbou/MycilaEasyDisplay @ 3.0.1
mathieucarbou/MycilaHADiscovery @ 2.2.1
Expand Down Expand Up @@ -79,7 +79,6 @@ build_flags =
-D MYCILA_MQTT_TASK_PRIORITY=5
-D NETWORK_FREQ_RUNTIME
-D WS_MAX_QUEUED_MESSAGES=64
-D YASOLR_DISABLE_BROWNOUT_DETECTOR
-D WSL_HIGH_PERF
-Wall -Wextra
-std=c++17
Expand Down Expand Up @@ -582,7 +581,6 @@ build_flags =
-D YASOLR_ZCD_PIN=8
-D YASOLR_PZEM_RX_PIN=-1
-D YASOLR_PZEM_TX_PIN=-1
-UARDUINO_USB_CDC_ON_BOOT

[env:oss-lilygo_eth_lite_s3]
extends = env:oss-esp32
Expand Down
5 changes: 4 additions & 1 deletion src/Website.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,14 @@ void YaSolR::WebsiteClass::updateCards() {

// home
_routerPower.update(routerMetrics.power);
_routerApparentPower.update(routerMetrics.apparentPower);
_routerPowerFactor.update(routerMetrics.powerFactor);
_routerTHDi.update(routerMetrics.thdi * 100);
_routerVoltage.update(gridMetrics.voltage);
_routerCurrent.update(routerMetrics.current);
_routerResistance.update(routerMetrics.resistance);
_routerEnergy.update(routerMetrics.energy);
_gridPower.update(gridMetrics.power);
_gridVoltage.update(gridMetrics.voltage);
_temperature(_routerDS18State, ds18Sys);

#ifdef APP_MODEL_PRO
Expand Down
9 changes: 0 additions & 9 deletions src/init/Boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,7 @@
*/
#include <YaSolR.h>

#ifdef YASOLR_DISABLE_BROWNOUT_DETECTOR
#include "soc/rtc_cntl_reg.h"
#include "soc/soc.h"
#endif

Mycila::Task bootTask("Boot", [](void* params) {
#ifdef YASOLR_DISABLE_BROWNOUT_DETECTOR
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
#endif

Serial.begin(YASOLR_SERIAL_BAUDRATE);
#if ARDUINO_USB_CDC_ON_BOOT
Serial.setTxTimeoutMs(0);
Expand Down
1 change: 1 addition & 0 deletions src/init/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Mycila::Task initConfigTask("Init Config", [](void* params) {
displayTask.setEnabledWhen([]() { return display.isEnabled(); });
displayTask.setInterval(293 * Mycila::TaskDuration::MILLISECONDS);
ds18Task.setEnabledWhen([]() { return ds18Sys.isEnabled() || ds18O1.isEnabled() || ds18O2.isEnabled(); });
ds18Task.setInterval(1 * Mycila::TaskDuration::SECONDS);
jsyTask.setEnabledWhen([]() { return jsy.isEnabled(); });
lightsTask.setInterval(200 * Mycila::TaskDuration::MILLISECONDS);
mqttPublishConfigTask.setEnabledWhen([]() { return mqtt.isConnected(); });
Expand Down
3 changes: 1 addition & 2 deletions src/init/Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Mycila::Task initLoggingTask("Init Logging", [](void* params) {
// Enable profiling for some FOREVER tasks
dashboardTask.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS);
displayTask.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS);
ds18Task.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS);
jsyTask.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS);
mqttPublishTask.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS);
profilerTask.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS);
Expand All @@ -35,7 +34,6 @@ Mycila::Task initLoggingTask("Init Logging", [](void* params) {
} else {
dashboardTask.disableProfiling();
displayTask.disableProfiling();
ds18Task.disableProfiling();
jsyTask.disableProfiling();
mqttPublishTask.disableProfiling();
profilerTask.disableProfiling();
Expand All @@ -45,6 +43,7 @@ Mycila::Task initLoggingTask("Init Logging", [](void* params) {
}

// Log execution time for some "ONCE" tasks
ds18Task.setCallback(debug ? LOG_EXEC_TIME : nullptr);
haDiscoveryTask.setCallback(debug ? LOG_EXEC_TIME : nullptr);
mqttPublishConfigTask.setCallback(debug ? LOG_EXEC_TIME : nullptr);
mqttPublishStaticTask.setCallback(debug ? LOG_EXEC_TIME : nullptr);
Expand Down
12 changes: 6 additions & 6 deletions src/tasks/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ Mycila::Task displayTask("Display", [](void* params) {
display.home.printf("Resistance: %4d Ohms\n", static_cast<int>(round(outputMetrics.resistance)));
display.home.printf("Dimmer: %5d %5d W\n", dimmerO1.getPowerDuty(), static_cast<int>(round(outputMetrics.power)));
if (ds18O1.isEnabled())
display.home.printf("Temperature: %4.1f", ds18O1.getLastTemperature());
display.home.printf("Temperature: %4.1f°C", ds18O1.getLastTemperature());
else
display.home.printf("Temperature: --.-");
display.home.printf("Temperature: --.-°C");
display.home.printf("\xb0");
display.home.printf("C\n");
break;
Expand All @@ -150,9 +150,9 @@ Mycila::Task displayTask("Display", [](void* params) {
display.home.printf("Resistance: %4d Ohms\n", static_cast<int>(round(outputMetrics.resistance)));
display.home.printf("Dimmer: %5d %5d W\n", dimmerO2.getPowerDuty(), static_cast<int>(round(outputMetrics.power)));
if (ds18O2.isEnabled())
display.home.printf("Temperature: %4.1f", ds18O2.getLastTemperature());
display.home.printf("Temperature: %4.1f°C", ds18O2.getLastTemperature());
else
display.home.printf("Temperature: --.-");
display.home.printf("Temperature: --.-°C");
display.home.printf("\xb0");
display.home.printf("C\n");
break;
Expand All @@ -167,9 +167,9 @@ Mycila::Task displayTask("Display", [](void* params) {
else
display.home.printf("NTP Time: --:--\n");
if (ds18Sys.isEnabled())
display.home.printf("Temperature: %4.1f", ds18Sys.getLastTemperature());
display.home.printf("Temperature: %4.1f°C", ds18Sys.getLastTemperature());
else
display.home.printf("Temperature: --.-");
display.home.printf("Temperature: --.-°C");
display.home.printf("\xb0");
display.home.printf("C\n");
break;
Expand Down

0 comments on commit 00d7c10

Please sign in to comment.