Skip to content

Commit

Permalink
Small updates and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Nov 28, 2024
1 parent 438398b commit 1966f8c
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 35 deletions.
5 changes: 3 additions & 2 deletions include/YaSolR.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ extern Mycila::RouterRelay routerRelay2;
extern Mycila::TrafficLight lights;

extern Mycila::TaskManager coreTaskManager;
extern Mycila::Task dashboardTask;
extern Mycila::Task dashboardInitTask;
extern Mycila::Task dashboardUpdateTask;
extern Mycila::Task debugTask;
extern Mycila::Task networkConfigTask;
extern Mycila::Task networkManagerTask;
Expand Down Expand Up @@ -128,7 +129,7 @@ extern Mycila::Task routingTask;
extern Mycila::Task bootTask;
extern Mycila::Task initConfigTask;
extern Mycila::Task initCoreTask;
extern Mycila::Task initDashboardCards;
extern Mycila::Task initDashboard;
extern Mycila::Task initEventsTask;
extern Mycila::Task initLoggingTask;
extern Mycila::Task initMqttSubscribersTask;
Expand Down
24 changes: 13 additions & 11 deletions include/YaSolRDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,27 @@
#define YASOLR_ADMIN_USERNAME "admin"
#define YASOLR_DISPLAY_LINE_SIZE 21
#define YASOLR_DISPLAY_LINES 5
#define YASOLR_GRAPH_POINTS 120
#define YASOLR_HIDDEN_PWD "********"
#define YASOLR_MQTT_KEEPALIVE 60
#define YASOLR_MQTT_MEASUREMENT_EXPIRATION 60000
#define YASOLR_MQTT_SERVER_CERT_FILE "/mqtt-server.pem"
#define YASOLR_MQTT_WILL_TOPIC "/status"
#define YASOLR_PID_D_MODE_1 YASOLR_PID_P_MODE_1
#define YASOLR_PID_D_MODE_2 YASOLR_PID_P_MODE_2
#define YASOLR_PID_IC_MODE_0 "0: Off"
#define YASOLR_PID_IC_MODE_1 "1: Clamp"
#define YASOLR_PID_IC_MODE_2 "2: Advanced"
#define YASOLR_PID_P_MODE_1 "1: On Error"
#define YASOLR_PID_P_MODE_2 "2: On Input"
#define YASOLR_PID_P_MODE_3 "3: Both"
#define YASOLR_PZEM_ADDRESS_OUTPUT1 0x01
#define YASOLR_PZEM_ADDRESS_OUTPUT2 0x02
#define YASOLR_RELAY_TYPE_NC "NC"
#define YASOLR_RELAY_TYPE_NO "NO"
#define YASOLR_SERIAL_BAUDRATE 115200
#define YASOLR_WEEK_DAYS "sun,mon,tue,wed,thu,fri,sat"
#define YASOLR_GRAPH_POINTS 120
#define YASOLR_PID_P_MODE_1 "1: On Error"
#define YASOLR_PID_P_MODE_2 "2: On Input"
#define YASOLR_PID_P_MODE_3 "3: Both"
#define YASOLR_PID_D_MODE_1 YASOLR_PID_P_MODE_1
#define YASOLR_PID_D_MODE_2 YASOLR_PID_P_MODE_2
#define YASOLR_PID_IC_MODE_0 "0: Off"
#define YASOLR_PID_IC_MODE_1 "1: Clamp"
#define YASOLR_PID_IC_MODE_2 "2: Advanced"
#define YASOLR_MQTT_MEASUREMENT_EXPIRATION 60000
#define YASOLR_MQTT_SERVER_CERT_FILE "/mqtt-server.pem"
#define YASOLR_WEEK_DAYS_EMPTY "none"

// UDP communication

Expand Down
2 changes: 1 addition & 1 deletion lib/ESPDASHPro
7 changes: 4 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ lib_deps =
mathieucarbou/MycilaConfig @ 7.0.3
mathieucarbou/MycilaDS18 @ 4.1.2
mathieucarbou/MycilaESPConnect @ 7.0.0
mathieucarbou/MycilaEasyDisplay @ 3.0.2
mathieucarbou/MycilaEasyDisplay @ 3.0.3
mathieucarbou/MycilaHADiscovery @ 6.0.1
mathieucarbou/MycilaJSY @ 12.0.0
mathieucarbou/MycilaLogger @ 3.2.1
Expand All @@ -82,7 +82,7 @@ lib_deps =
mathieucarbou/MycilaSystem @ 4.0.0
mathieucarbou/MycilaTaskManager @ 3.1.3
mathieucarbou/MycilaTaskMonitor @ 3.0.2
mathieucarbou/MycilaTrafficLight @ 2.0.0
mathieucarbou/MycilaTrafficLight @ 2.0.2
mathieucarbou/MycilaUtilities @ 3.1.2
lib_ignore =
; AsyncTCP
Expand Down Expand Up @@ -133,7 +133,8 @@ build_flags =
-D DASH_DEFAULT_CARD_SIZE_XS=12
-D DASH_DEFAULT_CARD_SIZE_XXL=3
-D DASH_USE_STL_STRING=1
; -D DASH_JSON_SIZE=4096
-D DASH_JSON_SIZE=4096
; -D DASH_DEBUG=1
; WebSerial
-D WSL_HIGH_PERF
; YaSolR
Expand Down
10 changes: 4 additions & 6 deletions src/Website.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ void YaSolR::Website::initLayout() {
config.set(KEY_OUTPUT2_RESISTANCE, Mycila::string::to_string(router.getOutputs()[1]->config.calibratedResistance, 2));
});

initCards();
dashboardInitTask.resume();
mqttPublishConfigTask.resume();
mqttPublishTask.requestEarlyRun();

Expand Down Expand Up @@ -563,8 +563,7 @@ void YaSolR::Website::initLayout() {
_mqttServerCertDelete.attachCallback([this]() {
if (LittleFS.exists(YASOLR_MQTT_SERVER_CERT_FILE) && LittleFS.remove(YASOLR_MQTT_SERVER_CERT_FILE)) {
logger.warn(TAG, "MQTT server certificate deleted successfully!");
initCards();
dashboardTask.requestEarlyRun();
dashboardInitTask.resume();
}
});

Expand Down Expand Up @@ -1330,7 +1329,6 @@ void YaSolR::Website::_pinConfig(Card& card, const char* key) {
} else {
config.unset(key);
}
initCards();
dashboard.refreshCard(&card);
});
#endif
Expand Down Expand Up @@ -1393,7 +1391,7 @@ void YaSolR::Website::_outputBypassSwitch(Card& card, Mycila::RouterOutput& outp
}
card.update(output.isBypassOn());
dashboard.refreshCard(&card);
dashboardTask.requestEarlyRun();
dashboardInitTask.resume();
});
}

Expand All @@ -1404,7 +1402,7 @@ void YaSolR::Website::_outputDimmerSlider(Card& card, Mycila::RouterOutput& outp
}
card.update(output.getDimmerDutyCycle() * 100);
dashboard.refreshCard(&card);
dashboardTask.requestEarlyRun();
dashboardUpdateTask.requestEarlyRun();
});
}

Expand Down
5 changes: 3 additions & 2 deletions src/init/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ Mycila::Task initConfigTask("Init Config", [](void* params) {
calibrationTask.setInterval(1 * Mycila::TaskDuration::SECONDS);
carouselTask.setEnabledWhen([]() { return display.isEnabled(); });
carouselTask.setIntervalSupplier([]() { return config.getLong(KEY_DISPLAY_SPEED) * Mycila::TaskDuration::SECONDS; });
dashboardTask.setEnabledWhen([]() { return espConnect.isConnected() && !dashboard.isAsyncAccessInProgress(); });
dashboardTask.setInterval(1000 * Mycila::TaskDuration::MILLISECONDS);
dashboardInitTask.setEnabledWhen([]() { return espConnect.isConnected() && !dashboard.isAsyncAccessInProgress(); });
dashboardUpdateTask.setEnabledWhen([]() { return espConnect.isConnected() && !dashboard.isAsyncAccessInProgress(); });
dashboardUpdateTask.setInterval(1000 * Mycila::TaskDuration::MILLISECONDS);
debugTask.setEnabledWhen([]() { return config.getBool(KEY_ENABLE_DEBUG); });
debugTask.setInterval(20 * Mycila::TaskDuration::SECONDS);
displayTask.setEnabledWhen([]() { return display.isEnabled(); });
Expand Down
3 changes: 2 additions & 1 deletion src/init/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Mycila::Task initCoreTask("Init Core", [](void* params) {
// coreTaskManager
calibrationTask.setManager(coreTaskManager);
carouselTask.setManager(coreTaskManager);
dashboardTask.setManager(coreTaskManager);
dashboardInitTask.setManager(coreTaskManager);
dashboardUpdateTask.setManager(coreTaskManager);
debugTask.setManager(coreTaskManager);
displayTask.setManager(coreTaskManager);
lightsTask.setManager(coreTaskManager);
Expand Down
2 changes: 1 addition & 1 deletion src/init/Dashboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

extern YaSolR::Website website;

Mycila::Task initDashboardCards("Init Dashboard", [](void* params) {
Mycila::Task initDashboard("Init Dashboard", [](void* params) {
logger.info(TAG, "Initializing dashboard");
website.initLayout();
website.initCards();
Expand Down
5 changes: 3 additions & 2 deletions src/init/Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Mycila::Task initLoggingTask("Init Logging", [](void* params) {

if (debug) {
// Enable profiling for some FOREVER tasks
dashboardTask.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS);
dashboardUpdateTask.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS);
// debugTask.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS);
// ds18Task.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS);
displayTask.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS);
Expand All @@ -32,7 +32,7 @@ Mycila::Task initLoggingTask("Init Logging", [](void* params) {
// routerTask.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS);
// routingTask.enableProfiling(10, Mycila::TaskTimeUnit::MILLISECONDS);
} else {
dashboardTask.disableProfiling();
dashboardUpdateTask.disableProfiling();
// debugTask.disableProfiling();
// ds18Task.disableProfiling();
displayTask.disableProfiling();
Expand All @@ -44,6 +44,7 @@ Mycila::Task initLoggingTask("Init Logging", [](void* params) {
}

// Log execution time for some "ONCE" tasks
dashboardInitTask.setCallback(debug ? LOG_EXEC_TIME : nullptr);
ds18Task.setCallback(debug ? LOG_EXEC_TIME : nullptr);
haDiscoveryTask.setCallback(debug ? LOG_EXEC_TIME : nullptr);
mqttConfigTask.setCallback(debug ? LOG_EXEC_TIME : nullptr);
Expand Down
3 changes: 2 additions & 1 deletion src/init/Events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ Mycila::Task initEventsTask("Init Events", [](void* params) {
logger.info(TAG, "PID Controller reconfigured!");
}

website.initCards();
dashboardInitTask.resume();
mqttPublishConfigTask.resume();
mqttPublishTask.requestEarlyRun();
});
Expand Down Expand Up @@ -287,6 +287,7 @@ Mycila::Task initEventsTask("Init Events", [](void* params) {
default:
break;
}
dashboardInitTask.resume();
});

bypassRelayO1.listen([](bool state) {
Expand Down
3 changes: 1 addition & 2 deletions src/init/REST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ Mycila::Task initRestApiTask("Init REST API", [](void* params) {
File serverCertFile = LittleFS.open(YASOLR_MQTT_SERVER_CERT_FILE, "r");
logger.info(TAG, "Uploaded MQTT PEM server certificate:\n%s", serverCertFile.readString().c_str());
serverCertFile.close();
website.initCards();
dashboardTask.requestEarlyRun();
dashboardInitTask.resume();
request->send(response);
},
[](AsyncWebServerRequest* request, String filename, size_t index, uint8_t* data, size_t len, bool final) {
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void setup() {
initWebTask.forceRun();
initRestApiTask.forceRun();
initMqttSubscribersTask.forceRun();
initDashboardCards.forceRun();
initDashboard.forceRun();

assert( jsyTaskManager.asyncStart(512 * 6, 5, 0, 100, true)); // NOLINT
assert( pioTaskManager.asyncStart(512 * 7, 1, 1, 100, true)); // NOLINT
Expand Down
8 changes: 7 additions & 1 deletion src/tasks/Dashboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@

extern YaSolR::Website website;

Mycila::Task dashboardTask("Dashboard", [](void* params) {
Mycila::Task dashboardInitTask("Dashboard Init", Mycila::TaskType::ONCE, [](void* params) {
website.initCards();
website.updateCards();
dashboard.sendUpdates();
});

Mycila::Task dashboardUpdateTask("Dashboard Update", [](void* params) {
if (config.getBool(KEY_ENABLE_PID_VIEW)) {
website.updatePID();
if (wsDebugPID.count()) {
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/Routing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Mycila::Task routingTask("Routing", Mycila::TaskType::ONCE, [](void* params) {
if (voltage.has_value() && power.isPresent()) {
router.divert(voltage.value(), power.get());
if (config.getBool(KEY_ENABLE_PID_VIEW)) {
dashboardTask.requestEarlyRun();
dashboardUpdateTask.requestEarlyRun();
}
}
});

0 comments on commit 1966f8c

Please sign in to comment.