- Notifications
You must be signed in to change notification settings - Fork220
Closed
Description
Hi,
Thebegin()
function does not behave as expected following anend()
and instead I have to power cycle. This is similar to#33
I've created two minimal examples for people to try below:
Example 1:
- Initialise BLE
- Call
BLE.disconnect()
10 seconds after connected to central - Re-advertise 15 seconds later to allow reconnection
Expected behaviour - disconnect from central and allow reconnection after re-advertising
Actual behaviour - works as expected
#include<ArduinoBLE.h>BLEServiceTestService("DEAD");BLECharacteristicTestData("BEEF", BLEIndicate | BLENotify,2,true);BLEDescriptorTestDescriptor("BEEF","Test");uint32_t genericTimer =0;bool wasConnected =false;voidsetup(){initBLE();}voidloop(){ BLEDevice central = BLE.central();// begin listening for centrals to connectif(central){ genericTimer =millis();while(central.connected()){if(millis() - genericTimer >=10000){// Wait 10 seconds after connect BLE.disconnect();// Disconnect BLE wasConnected =true; } } }if(wasConnected){ genericTimer =millis();while(millis() - genericTimer <=15000){}// Wait 15 seconds after disconnect wasConnected =false; BLE.advertise(); }}voidinitBLE(void){ BLE.begin(); BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler); BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); BLE.setLocalName("TestName"); BLE.setDeviceName("Test Device Name"); TestService.addCharacteristic(TestData); TestData.addDescriptor(TestDescriptor); BLE.addService(TestService); BLE.setAdvertisedService(TestService); BLE.advertise();}
Example 2:
- Initialise BLE
- Disconnect and
end()
after 10 seconds of connection to central - Wait 15 seconds and try to re-start BLE system again
Expected behaviour - system disconnects, then ends BLE service, and restarts it correctly
Actual behaviour - unable to restart BLE withbegin()
after callingend()
#include<ArduinoBLE.h>BLEServiceTestService("DEAD");BLECharacteristicTestData("BEEF", BLEIndicate | BLENotify,2,true);BLEDescriptorTestDescriptor("BEEF","Test");uint32_t genericTimer =0;bool wasConnected =false;voidsetup(){initBLE();}voidloop(){ BLEDevice central = BLE.central();// begin listening for centrals to connectif(central){ genericTimer =millis();while(central.connected()){if(millis() - genericTimer >=10000){// Wait 10 seconds after connect BLE.disconnect();// Disconnect BLE BLE.end();// End BLE service wasConnected =true; } } }if(wasConnected){ genericTimer =millis();while(millis() - genericTimer <=15000){}// Wait 15 seconds after disconnect wasConnected =false;initBLE(); }}voidinitBLE(void){ BLE.begin(); BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler); BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); BLE.setLocalName("TestName"); BLE.setDeviceName("Test Device Name"); TestService.addCharacteristic(TestData); TestData.addDescriptor(TestDescriptor); BLE.addService(TestService); BLE.setAdvertisedService(TestService); BLE.advertise();}