Fix-BLE-task-stall (#421)
This commit is contained in:
@@ -193,7 +193,9 @@ bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttributes)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isConnected() || m_connEstablished || m_pTaskData != nullptr) {
|
ble_gap_conn_desc desc;
|
||||||
|
|
||||||
|
if(ble_gap_conn_find(m_conn_id, &desc) == 0 && (isConnected() || m_connEstablished || m_pTaskData != nullptr)) {
|
||||||
NIMBLE_LOGE(LOG_TAG, "Client busy, connected to %s, id=%d",
|
NIMBLE_LOGE(LOG_TAG, "Client busy, connected to %s, id=%d",
|
||||||
std::string(m_peerAddress).c_str(), getConnId());
|
std::string(m_peerAddress).c_str(), getConnId());
|
||||||
return false;
|
return false;
|
||||||
@@ -293,6 +295,8 @@ bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttributes)
|
|||||||
if(isConnected()) {
|
if(isConnected()) {
|
||||||
NIMBLE_LOGE(LOG_TAG, "Connect timeout - no response");
|
NIMBLE_LOGE(LOG_TAG, "Connect timeout - no response");
|
||||||
disconnect();
|
disconnect();
|
||||||
|
NIMBLE_LOGE(LOG_TAG, "Connect timeout - cancelling");
|
||||||
|
ble_gap_conn_cancel();
|
||||||
} else {
|
} else {
|
||||||
// workaround; if the controller doesn't cancel the connection
|
// workaround; if the controller doesn't cancel the connection
|
||||||
// at the timeout, cancel it here.
|
// at the timeout, cancel it here.
|
||||||
|
|||||||
@@ -541,7 +541,7 @@ void WebCfgServer::handleOtaUpload()
|
|||||||
.idle_core_mask = 0,
|
.idle_core_mask = 0,
|
||||||
.trigger_panic = false,
|
.trigger_panic = false,
|
||||||
};
|
};
|
||||||
esp_task_wdt_init(&twdt_config);
|
esp_task_wdt_reconfigure(&twdt_config);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NUKI_HUB_UPDATER
|
#ifndef NUKI_HUB_UPDATER
|
||||||
|
|||||||
38
src/main.cpp
38
src/main.cpp
@@ -7,6 +7,7 @@
|
|||||||
#include "esp_ota_ops.h"
|
#include "esp_ota_ops.h"
|
||||||
#include "esp_http_client.h"
|
#include "esp_http_client.h"
|
||||||
#include "esp_https_ota.h"
|
#include "esp_https_ota.h"
|
||||||
|
#include <esp_task_wdt.h>
|
||||||
|
|
||||||
#ifndef NUKI_HUB_UPDATER
|
#ifndef NUKI_HUB_UPDATER
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
@@ -72,6 +73,8 @@ TaskHandle_t networkTaskHandle = nullptr;
|
|||||||
|
|
||||||
void networkTask(void *pvParameters)
|
void networkTask(void *pvParameters)
|
||||||
{
|
{
|
||||||
|
int64_t networkLoopTs = 0;
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
int64_t ts = (esp_timer_get_time() / 1000);
|
int64_t ts = (esp_timer_get_time() / 1000);
|
||||||
@@ -97,6 +100,14 @@ void networkTask(void *pvParameters)
|
|||||||
webCfgServer->update();
|
webCfgServer->update();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if((esp_timer_get_time() / 1000) - networkLoopTs > 120000)
|
||||||
|
{
|
||||||
|
Log->println("networkTask is running");
|
||||||
|
networkLoopTs = esp_timer_get_time() / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_task_wdt_reset();
|
||||||
|
|
||||||
delay(100);
|
delay(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,6 +115,8 @@ void networkTask(void *pvParameters)
|
|||||||
#ifndef NUKI_HUB_UPDATER
|
#ifndef NUKI_HUB_UPDATER
|
||||||
void nukiTask(void *pvParameters)
|
void nukiTask(void *pvParameters)
|
||||||
{
|
{
|
||||||
|
int64_t nukiLoopTs = 0;
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
bleScanner->update();
|
bleScanner->update();
|
||||||
@@ -125,6 +138,13 @@ void nukiTask(void *pvParameters)
|
|||||||
nukiOpener->update();
|
nukiOpener->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if((esp_timer_get_time() / 1000) - nukiLoopTs > 120000)
|
||||||
|
{
|
||||||
|
Log->println("nukiTask is running");
|
||||||
|
nukiLoopTs = esp_timer_get_time() / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_task_wdt_reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,6 +274,8 @@ void otaTask(void *pvParameter)
|
|||||||
while (1) {
|
while (1) {
|
||||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
esp_task_wdt_reset();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -261,22 +283,38 @@ void setupTasks(bool ota)
|
|||||||
{
|
{
|
||||||
// configMAX_PRIORITIES is 25
|
// configMAX_PRIORITIES is 25
|
||||||
|
|
||||||
|
#if (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0))
|
||||||
|
esp_task_wdt_init(300, true);
|
||||||
|
#else
|
||||||
|
esp_task_wdt_config_t twdt_config = {
|
||||||
|
.timeout_ms = 300000,
|
||||||
|
.idle_core_mask = 0,
|
||||||
|
.trigger_panic = true,
|
||||||
|
};
|
||||||
|
esp_task_wdt_reconfigure(&twdt_config);
|
||||||
|
#endif
|
||||||
|
|
||||||
if(ota)
|
if(ota)
|
||||||
{
|
{
|
||||||
#if (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0))
|
#if (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0))
|
||||||
xTaskCreatePinnedToCore(networkTask, "ntw", preferences->getInt(preference_task_size_network, NETWORK_TASK_SIZE), NULL, 3, &networkTaskHandle, 1);
|
xTaskCreatePinnedToCore(networkTask, "ntw", preferences->getInt(preference_task_size_network, NETWORK_TASK_SIZE), NULL, 3, &networkTaskHandle, 1);
|
||||||
|
esp_task_wdt_add(networkTaskHandle);
|
||||||
#ifndef NUKI_HUB_UPDATER
|
#ifndef NUKI_HUB_UPDATER
|
||||||
xTaskCreatePinnedToCore(nukiTask, "nuki", preferences->getInt(preference_task_size_nuki, NUKI_TASK_SIZE), NULL, 2, &nukiTaskHandle, 1);
|
xTaskCreatePinnedToCore(nukiTask, "nuki", preferences->getInt(preference_task_size_nuki, NUKI_TASK_SIZE), NULL, 2, &nukiTaskHandle, 1);
|
||||||
|
esp_task_wdt_add(nukiTaskHandle);
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
xTaskCreatePinnedToCore(otaTask, "ota", 8192, NULL, 2, &otaTaskHandle, 1);
|
xTaskCreatePinnedToCore(otaTask, "ota", 8192, NULL, 2, &otaTaskHandle, 1);
|
||||||
|
esp_task_wdt_add(otaTaskHandle);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xTaskCreatePinnedToCore(networkTask, "ntw", preferences->getInt(preference_task_size_network, NETWORK_TASK_SIZE), NULL, 3, &networkTaskHandle, 1);
|
xTaskCreatePinnedToCore(networkTask, "ntw", preferences->getInt(preference_task_size_network, NETWORK_TASK_SIZE), NULL, 3, &networkTaskHandle, 1);
|
||||||
|
esp_task_wdt_add(networkTaskHandle);
|
||||||
#ifndef NUKI_HUB_UPDATER
|
#ifndef NUKI_HUB_UPDATER
|
||||||
xTaskCreatePinnedToCore(nukiTask, "nuki", preferences->getInt(preference_task_size_nuki, NUKI_TASK_SIZE), NULL, 2, &nukiTaskHandle, 1);
|
xTaskCreatePinnedToCore(nukiTask, "nuki", preferences->getInt(preference_task_size_nuki, NUKI_TASK_SIZE), NULL, 2, &nukiTaskHandle, 1);
|
||||||
|
esp_task_wdt_add(nukiTaskHandle);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user