[BLE] When BLE watchdog is triggered, only deinit and reinit BLE (#1635)
* [BLE] Watchdog restart BLE only * Add minFreeHeap and blecorestacktrace indicators
This commit is contained in:
1 parent
474b8a87ab
commit
28f9fbff60
2 files changed
+43
-23
No files matched your search
+40
-23
@@ -68,6 +68,8 @@ struct decompose {
|
|||||||
bool reverse;
|
bool reverse;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
unsigned long BLEstarts = 0;
|
||||||
|
|
||||||
vector<BLEAction> BLEactions;
|
vector<BLEAction> BLEactions;
|
||||||
|
|
||||||
vector<BLEdevice*> devices;
|
vector<BLEdevice*> devices;
|
||||||
@@ -104,7 +106,7 @@ void BTConfig_init() {
|
|||||||
BTConfig.presenceAwayTimer = PresenceAwayTimer;
|
BTConfig.presenceAwayTimer = PresenceAwayTimer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Watchdog, if there was no change of BLE scanCount, restart ESP
|
// Watchdog, if there was no change of BLE scanCount, restart BT
|
||||||
void btScanWDG() {
|
void btScanWDG() {
|
||||||
static unsigned long previousBtScanCount = 0;
|
static unsigned long previousBtScanCount = 0;
|
||||||
static unsigned long lastBtScan = 0;
|
static unsigned long lastBtScan = 0;
|
||||||
@@ -114,7 +116,8 @@ void btScanWDG() {
|
|||||||
scanCount != 0 &&
|
scanCount != 0 &&
|
||||||
(now - lastBtScan > BTConfig.BLEinterval)) {
|
(now - lastBtScan > BTConfig.BLEinterval)) {
|
||||||
Log.error(F("BLE Scan watchdog triggered at : %ds" CR), lastBtScan / 1000);
|
Log.error(F("BLE Scan watchdog triggered at : %ds" CR), lastBtScan / 1000);
|
||||||
ESPRestart(4);
|
stopProcessing();
|
||||||
|
startProcessing();
|
||||||
} else {
|
} else {
|
||||||
previousBtScanCount = scanCount;
|
previousBtScanCount = scanCount;
|
||||||
lastBtScan = now;
|
lastBtScan = now;
|
||||||
@@ -151,6 +154,8 @@ String stateBTMeasures(bool start) {
|
|||||||
jo["btqsnd"] = btQueueLengthCount;
|
jo["btqsnd"] = btQueueLengthCount;
|
||||||
jo["btqavg"] = (btQueueLengthCount > 0 ? btQueueLengthSum / (float)btQueueLengthCount : 0);
|
jo["btqavg"] = (btQueueLengthCount > 0 ? btQueueLengthSum / (float)btQueueLengthCount : 0);
|
||||||
jo["bletaskstack"] = uxTaskGetStackHighWaterMark(xProcBLETaskHandle);
|
jo["bletaskstack"] = uxTaskGetStackHighWaterMark(xProcBLETaskHandle);
|
||||||
|
jo["blecoretaskstack"] = uxTaskGetStackHighWaterMark(xCoreTaskHandle);
|
||||||
|
jo["blestarts"] = BLEstarts;
|
||||||
|
|
||||||
if (start) {
|
if (start) {
|
||||||
Log.notice(F("BT sys: "));
|
Log.notice(F("BT sys: "));
|
||||||
@@ -830,10 +835,15 @@ void stopProcessing() {
|
|||||||
vTaskSuspend(xProcBLETaskHandle);
|
vTaskSuspend(xProcBLETaskHandle);
|
||||||
vTaskDelete(xProcBLETaskHandle);
|
vTaskDelete(xProcBLETaskHandle);
|
||||||
if (BLEDevice::getInitialized()) BLEDevice::deinit(true);
|
if (BLEDevice::getInitialized()) BLEDevice::deinit(true);
|
||||||
esp_bt_mem_release(ESP_BT_MODE_BTDM);
|
|
||||||
Log.notice(F("BLE gateway stopped, free heap: %d" CR), ESP.getFreeHeap());
|
Log.notice(F("BLE gateway stopped, free heap: %d" CR), ESP.getFreeHeap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void startProcessing() {
|
||||||
|
ProcessLock = false;
|
||||||
|
setupBTTasksAndBLE();
|
||||||
|
Log.notice(F("BLE gateway started, free heap: %d" CR), ESP.getFreeHeap());
|
||||||
|
}
|
||||||
|
|
||||||
void coreTask(void* pvParameters) {
|
void coreTask(void* pvParameters) {
|
||||||
while (true) {
|
while (true) {
|
||||||
if (!ProcessLock) {
|
if (!ProcessLock) {
|
||||||
@@ -928,6 +938,32 @@ void changelowpowermode(int newLowPowerMode) {
|
|||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setupBTTasksAndBLE() {
|
||||||
|
BLEDevice::setScanDuplicateCacheSize(BLEScanDuplicateCacheSize);
|
||||||
|
BLEDevice::init("");
|
||||||
|
|
||||||
|
xTaskCreatePinnedToCore(
|
||||||
|
procBLETask, /* Function to implement the task */
|
||||||
|
"procBLETask", /* Name of the task */
|
||||||
|
5120, /* Stack size in bytes */
|
||||||
|
NULL, /* Task input parameter */
|
||||||
|
2, /* Priority of the task (set higher than core task) */
|
||||||
|
&xProcBLETaskHandle, /* Task handle. */
|
||||||
|
1); /* Core where the task should run */
|
||||||
|
|
||||||
|
// we setup a task with priority one to avoid conflict with other gateways
|
||||||
|
xTaskCreatePinnedToCore(
|
||||||
|
coreTask, /* Function to implement the task */
|
||||||
|
"coreTask", /* Name of the task */
|
||||||
|
5120, /* Stack size in bytes */
|
||||||
|
NULL, /* Task input parameter */
|
||||||
|
1, /* Priority of the task */
|
||||||
|
&xCoreTaskHandle, /* Task handle. */
|
||||||
|
taskCore); /* Core where the task should run */
|
||||||
|
|
||||||
|
BLEstarts++;
|
||||||
|
}
|
||||||
|
|
||||||
void setupBT() {
|
void setupBT() {
|
||||||
BTConfig_init();
|
BTConfig_init();
|
||||||
BTConfig_load();
|
BTConfig_load();
|
||||||
@@ -954,27 +990,8 @@ void setupBT() {
|
|||||||
|
|
||||||
BLEQueue = xQueueCreate(32, sizeof(NimBLEAdvertisedDevice*));
|
BLEQueue = xQueueCreate(32, sizeof(NimBLEAdvertisedDevice*));
|
||||||
|
|
||||||
BLEDevice::setScanDuplicateCacheSize(BLEScanDuplicateCacheSize);
|
setupBTTasksAndBLE();
|
||||||
BLEDevice::init("");
|
|
||||||
|
|
||||||
xTaskCreatePinnedToCore(
|
|
||||||
procBLETask, /* Function to implement the task */
|
|
||||||
"procBLETask", /* Name of the task */
|
|
||||||
5120, /* Stack size in bytes */
|
|
||||||
NULL, /* Task input parameter */
|
|
||||||
2, /* Priority of the task (set higher than core task) */
|
|
||||||
&xProcBLETaskHandle, /* Task handle. */
|
|
||||||
1); /* Core where the task should run */
|
|
||||||
|
|
||||||
// we setup a task with priority one to avoid conflict with other gateways
|
|
||||||
xTaskCreatePinnedToCore(
|
|
||||||
coreTask, /* Function to implement the task */
|
|
||||||
"coreTask", /* Name of the task */
|
|
||||||
5120, /* Stack size in bytes */
|
|
||||||
NULL, /* Task input parameter */
|
|
||||||
1, /* Priority of the task */
|
|
||||||
&xCoreTaskHandle, /* Task handle. */
|
|
||||||
taskCore); /* Core where the task should run */
|
|
||||||
Log.trace(F("ZgatewayBT multicore ESP32 setup done " CR));
|
Log.trace(F("ZgatewayBT multicore ESP32 setup done " CR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1956,11 +1956,14 @@ String stateMeasures() {
|
|||||||
# if defined(ESP8266) || defined(ESP32)
|
# if defined(ESP8266) || defined(ESP32)
|
||||||
SYSdata["env"] = ENV_NAME;
|
SYSdata["env"] = ENV_NAME;
|
||||||
uint32_t freeMem;
|
uint32_t freeMem;
|
||||||
|
uint32_t minFreeMem;
|
||||||
freeMem = ESP.getFreeHeap();
|
freeMem = ESP.getFreeHeap();
|
||||||
SYSdata["freemem"] = freeMem;
|
SYSdata["freemem"] = freeMem;
|
||||||
SYSdata["mqttport"] = mqtt_port;
|
SYSdata["mqttport"] = mqtt_port;
|
||||||
SYSdata["mqttsecure"] = mqtt_secure;
|
SYSdata["mqttsecure"] = mqtt_secure;
|
||||||
# ifdef ESP32
|
# ifdef ESP32
|
||||||
|
minFreeMem = ESP.getMinFreeHeap();
|
||||||
|
SYSdata["minfreemem"] = minFreeMem;
|
||||||
# ifndef NO_INT_TEMP_READING
|
# ifndef NO_INT_TEMP_READING
|
||||||
SYSdata["tempc"] = intTemperatureRead();
|
SYSdata["tempc"] = intTemperatureRead();
|
||||||
# endif
|
# endif
|
||||||
|
|||||||
Reference in new issue
Block a user