How many packets per second can be transmitted using Adafruit Feather nRF52 Bluefruit LE - nRF52832?
In my tests, I was able to transmit only 5 to 6 packets per second, not more than that. Is there any example code or optimisation techniques to increase this rate?
Bluetooth packet transfer limit on Feather nRF52
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- eceng04
- Posts: 4
- Joined: Tue Aug 02, 2022 9:46 am
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Bluetooth packet transfer limit on Feather nRF52
Looking through the guide there are some examples of fast mode down to 20ms and slow mode at 150ms which would match what you have observed. Have you messed withe advertising inteval?
https://cdn-learn.adafruit.com/download ... -guide.pdf
Code: Select all
/* Start Advertising
* - Enable auto advertising if disconnected
* - Interval: fast mode = 20 ms, slow mode = 152.5 ms
* - Timeout for fast mode is 30 seconds
* - Start(timeout) with timeout = 0 will advertise forever (until connected)
*
* For recommended advertising interval
* https://developer.apple.com/library/content/qa/qa1931/_index.html
*/
Bluefruit.Advertising.restartOnDisconnect(true);
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising
after n seconds
}
- eceng04
- Posts: 4
- Joined: Tue Aug 02, 2022 9:46 am
Re: Bluetooth packet transfer limit on Feather nRF52
Code: Select all
Bluefruit.Advertising.setInterval(32, 244);
And how do we actually select the transfer mode, fast or slow? This statement is simply setting the interval values for both the modes.
I have done a few tests and found that each successful packet transfer takes 85 ms.
Another issue is that every time it runs the loop, the first packet transfer is always unsuccessful, which takes 100 ms. Then the second successful transfer takes 85 ms.
Code: Select all
do { uartsent = bleuart.write(bytes,sizeof(idat));
} while(!uartsent);
- eceng04
- Posts: 4
- Joined: Tue Aug 02, 2022 9:46 am
Re: Bluetooth packet transfer limit on Feather nRF52
So I tried to dig deeper in to the issue and found that this statement takes up to 100 ms to execute:
It is inside the notify function of BLECharacteristic.cpp file.
getHvnPacket is defined in BLEConnection.cpp
I couldn't find _hvn_sem but reducing BLE_GENERIC_TIMEOUT in bluefruit_common.h from 100 to 50 or 80 did not help much in solving the issue. Instead, it increased the number of failed packets, and sometimes caused connection issues with the device.
Code: Select all
// Failed if there is no free buffer
if ( !conn->getHvnPacket() ) return false;
Code: Select all
bool BLECharacteristic::notify(uint16_t conn_hdl, const void* data, uint16_t len)
Code: Select all
bool BLEConnection::getHvnPacket (void)
{
return xSemaphoreTake(_hvn_sem, ms2tick(BLE_GENERIC_TIMEOUT));
}
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Bluetooth packet transfer limit on Feather nRF52
Good work digging into this. You have turned up some clues.
1) Which library are you running? Are you running Adafruit_nRF52_Arduino v1.3.0? I ask because the side issue you brought up about the first packet failing with getHvnPacket() that is within:
has been resolved.
_hvn_sem btw:
https://github.com/adafruit/Adafruit_nR ... q=_hvn_sem
Another technique for improving performance would be to try setting this before Bluefruit.begin() to increase the queue length from 1 to 256.
1) Which library are you running? Are you running Adafruit_nRF52_Arduino v1.3.0? I ask because the side issue you brought up about the first packet failing with getHvnPacket() that is within:
Code: Select all
bool BLECharacteristic::notify(uint16_t conn_hdl, const void* data, uint16_t len)
_hvn_sem btw:
https://github.com/adafruit/Adafruit_nR ... q=_hvn_sem
Another technique for improving performance would be to try setting this before Bluefruit.begin() to increase the queue length from 1 to 256.
Code: Select all
Bluefruit.configPrphConn(BLE_GATT_ATT_MTU_DEFAULT, BLE_GAP_EVENT_LENGTH_MIN, 256, 256);
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
- eceng04
- Posts: 4
- Joined: Tue Aug 02, 2022 9:46 am
Re: Bluetooth packet transfer limit on Feather nRF52
Thanks for the tip, I was able to get much faster throughput using the following,
While using BANDWIDTH_MAX, the device couldn't connect and the max values for QSize would be 255, not 256.
Code: Select all
// GATT ATT MTU (23 bytes/packet), GAP Event len (6*1.25 ms), HVN Tx Queue size (25), Wr CMD Tx Queue size (25)
Bluefruit.configPrphConn(23, 6, 25, 25);
Please be positive and constructive with your questions and comments.