mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 09:49:32 +02:00
Moving mqtt loop to new task with lower priority than wifi and http to limit impact of mqtt load on wifi and http performance.
This commit is contained in:
parent
6109211c96
commit
d9167c3cc7
2 changed files with 32 additions and 9 deletions
|
@ -70,9 +70,13 @@ MyTimer loop_task_timer_10s(INTERVAL_10_S);
|
||||||
|
|
||||||
MyTimer check_pause_2s(INTERVAL_2_S);
|
MyTimer check_pause_2s(INTERVAL_2_S);
|
||||||
|
|
||||||
|
int64_t mqtt_task_time_us;
|
||||||
|
MyTimer mqtt_task_timer_10s(INTERVAL_10_S);
|
||||||
|
|
||||||
TaskHandle_t main_loop_task;
|
TaskHandle_t main_loop_task;
|
||||||
TaskHandle_t connectivity_loop_task;
|
TaskHandle_t connectivity_loop_task;
|
||||||
TaskHandle_t logging_loop_task;
|
TaskHandle_t logging_loop_task;
|
||||||
|
TaskHandle_t mqtt_loop_task;
|
||||||
|
|
||||||
Logging logging;
|
Logging logging;
|
||||||
|
|
||||||
|
@ -99,6 +103,11 @@ void setup() {
|
||||||
TASK_CONNECTIVITY_PRIO, &logging_loop_task, WIFI_CORE);
|
TASK_CONNECTIVITY_PRIO, &logging_loop_task, WIFI_CORE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MQTT
|
||||||
|
xTaskCreatePinnedToCore((TaskFunction_t)&mqtt_loop, "mqtt_loop", 4096, &mqtt_task_time_us, TASK_MQTT_PRIO,
|
||||||
|
&mqtt_loop_task, WIFI_CORE);
|
||||||
|
#endif
|
||||||
|
|
||||||
init_CAN();
|
init_CAN();
|
||||||
|
|
||||||
init_contactors();
|
init_contactors();
|
||||||
|
@ -180,9 +189,6 @@ void connectivity_loop(void* task_time_us) {
|
||||||
#ifdef MDNSRESPONDER
|
#ifdef MDNSRESPONDER
|
||||||
init_mDNS();
|
init_mDNS();
|
||||||
#endif
|
#endif
|
||||||
#ifdef MQTT
|
|
||||||
init_mqtt();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
START_TIME_MEASUREMENT(wifi);
|
START_TIME_MEASUREMENT(wifi);
|
||||||
|
@ -191,15 +197,9 @@ void connectivity_loop(void* task_time_us) {
|
||||||
ota_monitor();
|
ota_monitor();
|
||||||
#endif
|
#endif
|
||||||
END_TIME_MEASUREMENT_MAX(wifi, datalayer.system.status.wifi_task_10s_max_us);
|
END_TIME_MEASUREMENT_MAX(wifi, datalayer.system.status.wifi_task_10s_max_us);
|
||||||
#ifdef MQTT
|
|
||||||
START_TIME_MEASUREMENT(mqtt);
|
|
||||||
mqtt_loop();
|
|
||||||
END_TIME_MEASUREMENT_MAX(mqtt, datalayer.system.status.mqtt_task_10s_max_us);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef FUNCTION_TIME_MEASUREMENT
|
#ifdef FUNCTION_TIME_MEASUREMENT
|
||||||
if (connectivity_task_timer_10s.elapsed()) {
|
if (connectivity_task_timer_10s.elapsed()) {
|
||||||
datalayer.system.status.mqtt_task_10s_max_us = 0;
|
|
||||||
datalayer.system.status.wifi_task_10s_max_us = 0;
|
datalayer.system.status.wifi_task_10s_max_us = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -209,6 +209,28 @@ void connectivity_loop(void* task_time_us) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MQTT
|
||||||
|
void mqtt_loop(void* task_time_us) {
|
||||||
|
esp_task_wdt_add(NULL); // Register this task with WDT
|
||||||
|
|
||||||
|
init_mqtt();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
START_TIME_MEASUREMENT(mqtt);
|
||||||
|
mqtt_loop();
|
||||||
|
END_TIME_MEASUREMENT_MAX(mqtt, datalayer.system.status.mqtt_task_10s_max_us);
|
||||||
|
|
||||||
|
#ifdef FUNCTION_TIME_MEASUREMENT
|
||||||
|
if (mqtt_task_timer_10s.elapsed()) {
|
||||||
|
datalayer.system.status.mqtt_task_10s_max_us = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
esp_task_wdt_reset(); // Reset watchdog
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void core_loop(void* task_time_us) {
|
void core_loop(void* task_time_us) {
|
||||||
esp_task_wdt_add(NULL); // Register this task with WDT
|
esp_task_wdt_add(NULL); // Register this task with WDT
|
||||||
TickType_t xLastWakeTime = xTaskGetTickCount();
|
TickType_t xLastWakeTime = xTaskGetTickCount();
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
*/
|
*/
|
||||||
#define TASK_CORE_PRIO 4
|
#define TASK_CORE_PRIO 4
|
||||||
#define TASK_CONNECTIVITY_PRIO 3
|
#define TASK_CONNECTIVITY_PRIO 3
|
||||||
|
#define TASK_MQTT_PRIO 2
|
||||||
#define TASK_MODBUS_PRIO 8
|
#define TASK_MODBUS_PRIO 8
|
||||||
#define TASK_ACAN2515_PRIORITY 10
|
#define TASK_ACAN2515_PRIORITY 10
|
||||||
#define TASK_ACAN2517FD_PRIORITY 10
|
#define TASK_ACAN2517FD_PRIORITY 10
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue