Hello,
I have a problem with BLE communication with Nano33 over BLE.
The issue is that each time I connect to Nano performance drops, let me explain with fallowing short steps:
- plug-in Nano 33 into USB
- using my own application connect to device and start reading characteristics, (on Nano now I just increment int variable using string characteristics and send it)
- read changed characteristic on PC using application
- close application (this will automatically disconnect from BLE on Nano)
- repeat from 2
Issue:
I do have performance monitoring functionality written, with basically count amount of reply received from BLE within 1 sec, and here are results:
- on first connection to Nano I do receive around 51 messages / sec
- on second connection to Nano I do receive around 32-33 messages / sec
- on third connection to Nano I do receive around 16-17 messages / sec
- on forth connection I'm unable to connect as Nano is hung - led indicate that connection is still present
My questions:
- obviously why this happens ?
- why maximum only 51 updates ? This is only for sending string characteristics so I would assume it should be much faster (note code below should output around 100 messages, I tested without delay of course that hung loop() so did delay and below 10ms it will hang faster).
Could be that I did missed something obvious so I'm grateful for any advice.
Code for Nano:
#include <ArduinoBLE.h>
static const char* localName = "Nano_33_BLE";
BLEService bleService("28a72d52-35ca-4c57-8b21-b831066983a8"); // User defined service
BLEStringCharacteristic bleCharacteristic("c7f50871-a316-4926-b58a-26e7b58b78e4", BLERead | BLENotify, 128);
int enumerator = 0;
void setup() {
pinMode(LED_BUILTIN, OUTPUT); // initialize the built-in LED pin
if (!BLE.begin()) { // initialize BLE
Serial.println("starting BLE failed!");
while (1);
}
BLE.setLocalName(localName); // Set name for connection
BLE.setAdvertisedService(bleService); // Advertise service
bleService.addCharacteristic(bleCharacteristic); // Add characteristic to service
BLE.addService(bleService); // Add service
bleCharacteristic.setValue("0"); // Set greeting string
BLE.advertise(); // Start advertising
}
long previousMillis = 0;
void loop()
{
BLEDevice central = BLE.central();
if (central)
{
digitalWrite(LED_BUILTIN, HIGH);
while (central.connected())
{
// BLE.poll(); // <- doesn't change anything
long currentMillis = millis();
if (currentMillis - previousMillis >= 10) {
previousMillis = currentMillis;
bleCharacteristic.writeValue(String(enumerator));
enumerator++;
}
}
digitalWrite(LED_BUILTIN, LOW);
enumerator = 0;
}
}
Thanks for reply
Best regards