Reputation: 1911
I have got both BLE working to configure and setup the nano IoT, and WIFI working to send sensor data to a cloud DB.
I've found on Arduino Forum a possible solution it it https://forum.arduino.cc/t/coexistence-of-wifi-and-ble-in-arduino-nano-33-iot/676169
However I has a memory leak problem: every time I switch back to BLE it consumes roughly 500bytes of memory. This means all memory is exhausted within one hour or so and the Nano IoT crashes
Has anyone merged the two ideas. Have the Nano 33 IoT connected with both Wifi and BLE?
I know BLE and Wifi can't work in parallel on this board but can you easily and quickly switch between the two ?.
Upvotes: 0
Views: 787
Reputation: 1911
In the meantime I've found an answer to the memory leak problem on the ArduinoBLE library:
It looks like the issue comes from the following file:
.\libraries\ArduinoBLE\src\utility\GATT.cpp
In void GATTClass::begin()
a some objects are created with new. However they are not deleted in void GATTClass::end()
.
So the method need to be updated as follows:
void GATTClass::end()
{
delete( _genericAccessService );
delete( _deviceNameCharacteristic );
delete( _appearanceCharacteristic );
delete( _genericAttributeService );
delete( _servicesChangedCharacteristic );
_attributes.clear();
}
There's an open issue on GitHub https://github.com/arduino-libraries/ArduinoBLE/issues/192
Now back to the part of switch between BLE and WiFI. This is how to do it:
//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
and BLEcharacteristics
are done on the setup()
part of the code.
Upvotes: 0