Skip to content
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

Arduino BLE (micro)freezes on weak Bluetooth connection. #315

Open
pyciko opened this issue Aug 2, 2023 · 0 comments
Open

Arduino BLE (micro)freezes on weak Bluetooth connection. #315

pyciko opened this issue Aug 2, 2023 · 0 comments
Labels
type: imperfection Perceived defect in any part of project

Comments

@pyciko
Copy link

pyciko commented Aug 2, 2023

I noticed that my code execution starts to freeze on weak BLE connection. This is totally unacceptable in my case, since the device should just "throw data into the air" and go on to the next sensor reading cycle. I wrote a simple program to test things out:

#include <ArduinoBLE.h>

BLEService primaryService("66ec126a-bae4-4647-9f1d-8188d638b9b7");
//using pure BLECharacteristic cuz it allows control over "withResponse" argument
BLECharacteristic testChar("48297668-4f22-43c6-bcf5-d10c21388055", BLERead | BLENotify, 20, true);

unsigned long last = 0;

char buf[20];

void setup () {
  Serial.begin(9600);
  BLE.begin();

  BLE.setLocalName("Test 1");
  
  primaryService.addCharacteristic(testChar);

  BLE.addService(primaryService);
  
  BLE.setEventHandler(BLEConnected, [](BLEDevice central){BLE.stopAdvertise();});
  BLE.setEventHandler(BLEDisconnected, [](BLEDevice central){BLE.advertise();});

  BLE.advertise();
}

void loop() {
  Serial.println(millis() - last);
  last = millis();
  snprintf(buf, sizeof(buf), "%d", random(10000000, 99999999));

  BLE.poll();
  
  testChar.writeValue(buf, 20, false);
}

When Bluetooth is in advertising state, the loop execution delay is 0-1 ms. When smartphone is connected to the board, the delay is STILL 0-1 ms. But once I subscribe to the characteristic, it raises to ~50 ms (which is fine for me) with spikes of up to 800ms (which is not fine) on long distances.
It seems to me that the board is awaiting confirmations from the smartphone for every packet it sends. But wait, what? The "withResponse" argument is set to false. I tried (just out of curiosity) setting it to true - same results.

I guess there are 2 options: either I'm doing something completely wrong (or understanding something wrong), or the argument does not do anything?

Testing was conducted on original NANO 33 BLE as well as SEEED XIAO nRF52840.

@per1234 per1234 added the type: imperfection Perceived defect in any part of project label Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants