与此同时,我在 ArduinoBLE 库上找到了内存泄漏问题的答案:
看起来问题来自以下文件:
.\libraries\ArduinoBLE\src\utility\GATT.cpp
在void GATTClass::begin()
a 中,一些对象是用 new 创建的。但是它们不会在 中删除void GATTClass::end()
。
所以方法需要更新如下:
void GATTClass::end()
{
delete( _genericAccessService );
delete( _deviceNameCharacteristic );
delete( _appearanceCharacteristic );
delete( _genericAttributeService );
delete( _servicesChangedCharacteristic );
_attributes.clear();
}
GitHub上有一个未解决的问题
https://github.com/arduino-libraries/ArduinoBLE/issues/192
现在回到BLE和WiFi之间切换的部分。这是如何做到的:
//Start Wifi
wiFiDrv.wifiDriverDeinit();
wiFiDrv.wifiDriverInit();
status = WiFi.begin(ssid, pass);
server.begin();
//...
// End Wifi
WiFi.end()
//...
//Start BLE
BLE.begin();
BLE.scan();
//...
// End BLE
BLE.stopAdvertise(); //don't think this is needed as I am reading other BLE devices
BLE.stopScan();
BLE.end();
BLEservice
并在代码部分BLEcharacteristics
完成。setup()