-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switching between Central an Peripheral #13
Comments
Can you provide more specifics? |
I call BLE.end() before switching.
|
you are right, there was something blocking the peripheral mode. a few points I noticed regarding the rest of the code:
|
Thank you for cooperation. I also want to note that the BLE.end() needs internal blocking and synchronization. Now we have to add delays when switching from scan mode to peripheral: |
can you clarify on the internal blocking and synchronization? |
I meant that BLE.end () should wait for the completion of the stop scan operation, or stopScan () should do it. Anyway, without delay (5000) this code does not work, this is not the correct behavior |
I have done some testing and could not replicate the behavior. From what I can see, the code still works without the delay(5000). Here is the code snippet:
and here is the log output:
|
Indeed, apparently I ran the code before the fix. |
That is good to hear, thanks for the your feedback |
I catch permanent freeze after switch between Central to Peripheral. Call of BLE.beginPeripheral() blocks program permanently.
void WifiLoop()
{
int connecting_flag = 0;
// attempt to connect to Wifi network
if (WiFi.status() != WL_CONNECTED)
{
Serial.println("WiFi disconnected");
connecting_flag = 1;
BLE.configScan()->stopScan();
BLE.end();
Serial.println("Begin per...");
BLE.beginPeripheral();
Serial.println("Start adv...");
BLE.configAdvert()->startAdv();
}
while (WiFi.status() != WL_CONNECTED) {
Serial.println("Wait WiFi config..");
// wait for connection
delay(5000);
}
if (connecting_flag)
{
connecting_flag = 0;
BLE.beginCentral(0);
BLE.configScan()->startScan();
}
}
void BleAdvSetup()
{
//ble conf service
BLE.configServer(1);
configService.addService();
configService.begin();
// Wifi config service requires a specific advertisement format to be recognised by the app
// The advertisement needs the local BT address, which can only be obtained after starting peripheral mode
// Thus, we stop advertising to update the advert data, wait for advertising to stop, then restart advertising with new data
BLE.configAdvert()->stopAdv();
BLE.configAdvert()->setAdvData(configService.advData());
BLE.configAdvert()->updateAdvertParams();
delay(100);
//BLE.beginPeripheral();
//BLE.configAdvert()->startAdv();
}
void BleSetup()
{
BLE.init();
BLE.configScan()->setScanMode(GAP_SCAN_MODE_PASSIVE); // Active mode requests for scan response packets
BLE.configScan()->setScanInterval(5000); // Start a scan every 500ms
BLE.configScan()->setScanWindow(1000); // Each scan lasts for 250ms
BLE.configScan()->updateScanParams();
BLE.configScan()->setScanDuplicateFilter(0);
// Provide a callback function to process scan data.
// If no function is provided, default BLEScan::printScanInfo is used
BLE.setScanCallback(BleScanFunction);
BleAdvSetup();
BLE.beginCentral(0);
BLE.configScan()->startScan(); // Repeat scans for 5 seconds, then stop
}
The text was updated successfully, but these errors were encountered: