Skip to content

Commit

Permalink
Task manager fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Jun 7, 2024
1 parent b9971ac commit 764346f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
7 changes: 4 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,19 @@ lib_deps =
mathieucarbou/MycilaPZEM004Tv3 @ 4.0.1
mathieucarbou/MycilaRelay @ 4.0.1
mathieucarbou/MycilaSystem @ 2.0.4
mathieucarbou/MycilaTaskManager @ 3.1.0
mathieucarbou/MycilaTaskManager @ 3.1.1
mathieucarbou/MycilaTaskMonitor @ 3.0.1
mathieucarbou/MycilaTrafficLight @ 1.0.0
mathieucarbou/Dimmable Light for Arduino @ 2.0.1
; https://github.com/mathieucarbou/fabianoriccardi-dimmable-light#dev
build_flags =
-D ARDUINO_LOOP_STACK_SIZE=4096
-D CONFIG_ASYNC_TCP_PRIORITY=0
-D CONFIG_ASYNC_TCP_PRIORITY=10
-D CONFIG_ASYNC_TCP_QUEUE_SIZE=128
-D CONFIG_ASYNC_TCP_RUNNING_CORE=1
-D CONFIG_ASYNC_TCP_STACK_SIZE=4096
-D CONFIG_ETH_ENABLED
-D CONFIG_MQTT_TASK_CORE_SELECTION=1
-D DASH_DEFAULT_CARD_SIZE_LG=6
-D DASH_DEFAULT_CARD_SIZE_MD=6
-D DASH_DEFAULT_CARD_SIZE_SM=6
Expand All @@ -79,7 +80,7 @@ build_flags =
-D MYCILA_LOGGER_SUPPORT
-D MYCILA_MQTT_BUFFER_SIZE=512
-D MYCILA_MQTT_STACK_SIZE=4096
-D MYCILA_MQTT_TASK_PRIORITY=0
-D MYCILA_MQTT_TASK_PRIORITY=5
-D NETWORK_FREQ_RUNTIME
-D WS_MAX_QUEUED_MESSAGES=64
-D YASOLR_DISABLE_BROWNOUT_DETECTOR
Expand Down
10 changes: 5 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ void setup() {
initMqttSubscribersTask.forceRun();
initDashboardTask.forceRun();

assert( coreTaskManager.asyncStart(1024 * 4, 0, 1, 100, true)); // NOLINT
assert( ioTaskManager.asyncStart(1024 * 5, 0, 1, 100, true)); // NOLINT
assert( jsyTaskManager.asyncStart(1024 * 3, 0, 0, 100, true)); // NOLINT
assert( pzemTaskManager.asyncStart(1024 * 3, 0, 0, 100, true)); // NOLINT
assert(routerTaskManager.asyncStart(1024 * 3, 0, 1, 100, true)); // NOLINT
assert( coreTaskManager.asyncStart(1024 * 4, 1, 1, 100, true)); // NOLINT
assert( ioTaskManager.asyncStart(1024 * 5, 1, 1, 100, true)); // NOLINT
assert( jsyTaskManager.asyncStart(1024 * 3, 5, 0, 100, true)); // NOLINT
assert( pzemTaskManager.asyncStart(1024 * 3, 5, 0, 100, true)); // NOLINT
assert(routerTaskManager.asyncStart(1024 * 3, 5, 1, 100, true)); // NOLINT

// STARTUP READY!
logger.info(TAG, "Started %s", Mycila::AppInfo.nameModelVersion.c_str());
Expand Down
3 changes: 3 additions & 0 deletions src/tasks/DS18.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

Mycila::Task ds18Task("DS18", [](void* params) {
ds18Sys.read();
yield();
ds18O1.read();
yield();
ds18O2.read();
yield();
});
16 changes: 16 additions & 0 deletions src/tasks/MQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,38 @@ Mycila::Task mqttPublishStaticTask("MQTT Static", Mycila::TaskType::ONCE, [](voi
mqtt.publish(baseTopic + "/system/app/version", Mycila::AppInfo.version, true);
mqtt.publish(baseTopic + "/system/app/manufacturer", Mycila::AppInfo.manufacturer, true);
mqtt.publish(baseTopic + "/system/app/trial", YASOLR_BOOL(Mycila::AppInfo.trial), true);
yield();

mqtt.publish(baseTopic + "/system/device/id", Mycila::AppInfo.id, true);
mqtt.publish(baseTopic + "/system/device/model", ESP.getChipModel(), true);
mqtt.publish(baseTopic + "/system/device/cores", String(ESP.getChipCores()), true);
mqtt.publish(baseTopic + "/system/device/cpu_freq", String(ESP.getCpuFreqMHz()), true);
mqtt.publish(baseTopic + "/system/device/boots", String(Mycila::System.getBootCount()), true);
mqtt.publish(baseTopic + "/system/device/heap/total", String(ESP.getHeapSize()), true);
yield();

mqtt.publish(baseTopic + "/system/firmware/filename", Mycila::AppInfo.firmware, true);
mqtt.publish(baseTopic + "/system/firmware/build/hash", Mycila::AppInfo.buildHash, true);
mqtt.publish(baseTopic + "/system/firmware/build/branch", Mycila::AppInfo.buildBranch, true);
mqtt.publish(baseTopic + "/system/firmware/build/timestamp", Mycila::AppInfo.buildDate, true);
mqtt.publish(baseTopic + "/system/firmware/debug", YASOLR_BOOL(Mycila::AppInfo.debug), true);
yield();

mqtt.publish(baseTopic + "/system/network/hostname", ESPConnect.getHostname(), true);
mqtt.publish(baseTopic + "/system/network/eth/mac_address", ESPConnect.getMACAddress(ESPConnectMode::ETH), true);
mqtt.publish(baseTopic + "/system/network/wifi/mac_address", ESPConnect.getMACAddress(ESPConnectMode::STA), true);
yield();

if (!relay1.isEnabled()) {
mqtt.publish(baseTopic + "/router/relay1/state", YASOLR_STATE(relay1.isOn()), true);
mqtt.publish(baseTopic + "/router/relay1/switch_count", String(relay1.getSwitchCount()), true);
yield();
}

if (!relay2.isEnabled()) {
mqtt.publish(baseTopic + "/router/relay2/state", YASOLR_STATE(relay2.isOn()), true);
mqtt.publish(baseTopic + "/router/relay2/switch_count", String(relay2.getSwitchCount()), true);
yield();
}

if (!output1.isEnabled()) {
Expand All @@ -48,6 +54,7 @@ Mycila::Task mqttPublishStaticTask("MQTT Static", Mycila::TaskType::ONCE, [](voi
mqtt.publish(baseTopic + "/router/output1/relay/state", YASOLR_STATE(bypassRelayO1.isOn()), true);
mqtt.publish(baseTopic + "/router/output1/relay/switch_count", String(bypassRelayO1.getSwitchCount()), true);
mqtt.publish(baseTopic + "/router/output1/temperature", String(ds18O1.getLastTemperature()), true);
yield();
}

if (!output2.isEnabled()) {
Expand All @@ -57,6 +64,7 @@ Mycila::Task mqttPublishStaticTask("MQTT Static", Mycila::TaskType::ONCE, [](voi
mqtt.publish(baseTopic + "/router/output2/relay/state", YASOLR_STATE(bypassRelayO2.isOn()), true);
mqtt.publish(baseTopic + "/router/output2/relay/switch_count", String(bypassRelayO2.getSwitchCount()), true);
mqtt.publish(baseTopic + "/router/output2/temperature", String(ds18O2.getLastTemperature()), true);
yield();
}
});

Expand All @@ -79,6 +87,7 @@ Mycila::Task mqttPublishTask("MQTT", [](void* params) {
mqtt.publish(baseTopic + "/system/device/heap/usage", String(memory.usage));
mqtt.publish(baseTopic + "/system/device/heap/used", String(memory.used));
mqtt.publish(baseTopic + "/system/device/uptime", String(Mycila::System.getUptime()));
yield();

mqtt.publish(baseTopic + "/system/network/eth/ip_address", ESPConnect.getIPAddress(ESPConnectMode::ETH).toString());
mqtt.publish(baseTopic + "/system/network/ip_address", ESPConnect.getIPAddress().toString());
Expand All @@ -89,6 +98,7 @@ Mycila::Task mqttPublishTask("MQTT", [](void* params) {
mqtt.publish(baseTopic + "/system/network/wifi/quality", String(ESPConnect.getWiFiSignalQuality()));
mqtt.publish(baseTopic + "/system/network/wifi/rssi", String(ESPConnect.getWiFiRSSI()));
mqtt.publish(baseTopic + "/system/network/wifi/ssid", ESPConnect.getWiFiSSID());
yield();

switch (ESPConnect.getMode()) {
case ESPConnectMode::ETH:
Expand All @@ -111,6 +121,7 @@ Mycila::Task mqttPublishTask("MQTT", [](void* params) {
mqtt.publish(baseTopic + "/grid/power_factor", String(Mycila::Grid.getPowerFactor(), 3));
mqtt.publish(baseTopic + "/grid/power", String(Mycila::Grid.getActivePower(), 3));
mqtt.publish(baseTopic + "/grid/voltage", String(Mycila::Grid.getVoltage(), 3));
yield();

mqtt.publish(baseTopic + "/router/lights", lights.toString());
mqtt.publish(baseTopic + "/router/temperature", String(ds18Sys.getLastTemperature()));
Expand All @@ -119,15 +130,18 @@ Mycila::Task mqttPublishTask("MQTT", [](void* params) {
mqtt.publish(baseTopic + "/router/power", String(Mycila::Router.getTotalRoutedPower(), 3));
mqtt.publish(baseTopic + "/router/thdi", String(Mycila::Router.getTotalTHDi(), 3));
mqtt.publish(baseTopic + "/router/virtual_grid_power", String(Mycila::Router.getVirtualGridPower(), 3));
yield();

if (relay1.isEnabled()) {
mqtt.publish(baseTopic + "/router/relay1/state", YASOLR_STATE(relay1.isOn()));
mqtt.publish(baseTopic + "/router/relay1/switch_count", String(relay1.getSwitchCount()));
yield();
}

if (relay2.isEnabled()) {
mqtt.publish(baseTopic + "/router/relay2/state", YASOLR_STATE(relay2.isOn()));
mqtt.publish(baseTopic + "/router/relay2/switch_count", String(relay2.getSwitchCount()));
yield();
}

if (output1.isEnabled()) {
Expand All @@ -137,6 +151,7 @@ Mycila::Task mqttPublishTask("MQTT", [](void* params) {
mqtt.publish(baseTopic + "/router/output1/relay/state", YASOLR_STATE(bypassRelayO1.isOn()));
mqtt.publish(baseTopic + "/router/output1/relay/switch_count", String(bypassRelayO1.getSwitchCount()));
mqtt.publish(baseTopic + "/router/output1/temperature", String(ds18O1.getLastTemperature()));
yield();
}

if (output2.isEnabled()) {
Expand All @@ -146,5 +161,6 @@ Mycila::Task mqttPublishTask("MQTT", [](void* params) {
mqtt.publish(baseTopic + "/router/output2/relay/state", YASOLR_STATE(bypassRelayO2.isOn()));
mqtt.publish(baseTopic + "/router/output2/relay/switch_count", String(bypassRelayO2.getSwitchCount()));
mqtt.publish(baseTopic + "/router/output2/temperature", String(ds18O2.getLastTemperature()));
yield();
}
});
1 change: 1 addition & 0 deletions src/tasks/PZEM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Mycila::Task pzemTask("PZEM", [](void* params) {
// PZEM are on the same serial so cannot be read concurrently
pzemO1.read();
yield();
pzemO2.read();
});

Expand Down

0 comments on commit 764346f

Please sign in to comment.