-
-
Notifications
You must be signed in to change notification settings - Fork 186
Closed
Description
Hi,
I am tring to send and receive BLE extended advertising frames with 2x ESP32 C3.
TX is working up to 233 bytes in the ServiceData (verifyed by nRF Connect).
But RX does not work and I get 2 onDiscovered callbacks and getServiceData
does not find any data.
I tried dumping the raw data and in there are only parts of the original data.
The docs talk about up to 1650 bytes total for the compleate advertisement.
NimBLE-Arduino/docs/Command_line_config.md
Lines 157 to 161 in e6e8019
`CONFIG_BT_NIMBLE_MAX_EXT_ADV_DATA_LEN` | |
Set the max extended advertising data size, | |
- Range: 31 - 1650 | |
- Default is 255 |
bellow the code to reproduce the problem with to c3 mini boards.
platformio.ini:
[env:esp32-c3-mini]
platform = espressif32
board = esp32-c3-devkitm-1
framework = arduino
lib_deps =
h2zero/NimBLE-Arduino@^2.3.5
build_flags =
-DCONFIG_BT_NIMBLE_EXT_ADV=1
-DCONFIG_BT_NIMBLE_MAX_EXT_ADV_INSTANCES=2
-DCONFIG_BT_NIMBLE_MAX_EXT_ADV_DATA_LEN=512
-DMYNEWT_VAL_BLE_TRANSPORT_ACL_SIZE=512
-DMYNEWT_VAL_BLE_LL_MAX_PKT_SIZE=512
-DMYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE=550
-DMYNEWT_VAL_BLE_ACL_BUF_SIZE=550
-DCONFIG_BT_NIMBLE_DEBUG
-DCONFIG_NIMBLE_CPP_LOG_LEVEL=3
-DCONFIG_NIMBLE_CPP_ENABLE_RETURN_CODE_TEXT
#include <Arduino.h>
#include <NimBLEDevice.h>
#define UUID "11787a26-1b23-4ba5-8556-c3b6dbebf71e"
#define LED_PIN 8
class scanCallbacks : public NimBLEScanCallbacks {
void onDiscovered(const NimBLEAdvertisedDevice * advertisedDevice) override {
printf("\n");
printf("Discovered Device: %s\n", advertisedDevice->toString().c_str());
printf("AdvLength: %d ManufacturerDataCount: %d\n", advertisedDevice->getAdvLength(), advertisedDevice->getManufacturerDataCount());
auto payload = advertisedDevice->getPayload();
printf("RAW: %.*s\n", payload.size(), payload.data());
}
void onResult(const NimBLEAdvertisedDevice * advertisedDevice) override {
}
void onScanEnd(const NimBLEScanResults & results, int reason) override {
printf("Scan ended reason = %d; restarting scan\n", reason);
NimBLEDevice::getScan()->start(0, false, true);
}
} scanCallbacks;
void runRX() {
// RX
NimBLEScan * pBLEScan = NimBLEDevice::getScan();
pBLEScan->setScanCallbacks(&scanCallbacks, true);
pBLEScan->setActiveScan(false);
pBLEScan->setMaxResults(0);
pBLEScan->start(0, false, true);
printf("Scanning...\n");
}
void runTX() {
NimBLEExtAdvertising * pAdvertising = NimBLEDevice::getAdvertising();
NimBLEExtAdvertisement leAdvertising(BLE_HCI_LE_PHY_CODED, BLE_HCI_LE_PHY_2M);
std::string raw("A fork of the NimBLE library structured for compilation with Arduino, for use with ESP32, nRF5x. A fork of the NimBLE library structured for compilation with Arduino, for use with ESP32, nRF5x. 123456789ABCDEF-123456789ABCDEF-1234567");
// len max seams to be 233,
// increasing CONFIG_BT_NIMBLE_MAX_EXT_ADV_DATA_LEN does not work
// why no 0xFF / 255 ?
if(!leAdvertising.setServiceData(NimBLEUUID(UUID), raw)) {
printf("failed to setServiceData\n");
} else {
printf("ok to setServiceData len: %d\n", raw.size());
}
leAdvertising.setAnonymous(true);
leAdvertising.setConnectable(false);
leAdvertising.setScannable(false);
leAdvertising.setMinInterval(100);
leAdvertising.setMaxInterval(200);
printf("BLE leAdvertising len: %d\n", leAdvertising.getDataSize());
if(!pAdvertising->setInstanceData(0, leAdvertising)) {
printf("BLE failed to set leAdvertising\n");
} else if(!pAdvertising->start(0, 0, 0)) {
printf("BLE failed to start leAdvertising\n");
} else {
printf("BLE started leAdvertising\n");
}
}
void setup() {
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, false);
printf("Wait...\n");
delay(1000);
printf("Wait...\n");
delay(1000);
printf("Wait...\n");
delay(1000);
printf("Staring...\n");
NimBLEDevice::setScanFilterMode(CONFIG_BTDM_SCAN_DUPL_TYPE_DATA_DEVICE);
NimBLEDevice::init("");
// runTX();
}
void loop() {
runRX();
static bool led = false;
led = !led;
digitalWrite(LED_PIN, led);
delay(200);
}
RX log:
Scanning...
I NimBLEScan: New advertiser: 00:00:00:00:00:00
Discovered Device: Name: , Address: 00:00:00:00:00:00
AdvLength: 229 ManufacturerDataCount: 0
RAW: �!��۶�V��K#zxA fork of the NimBLE library structured for compilation with Arduino, for use with ESP32, nRF5x. A fork of the NimBLE library structured for compilation with Arduino, for 1
I NimBLEScan: New advertiser: 00:00:00:00:00:00
Discovered Device: Name: , Address: 00:00:00:00:00:00
AdvLength: 22 ManufacturerDataCount: 0
RAW: 23456789ABCDEF-1234567
TX log 233 bytes:
Staring...
I NimBLEDevice: BLE Host Task Started
I NimBLEDevice: NimBle host synced.
ok to setServiceData len: 233
BLE leAdvertising len: 251
BLE started leAdvertising
TX log 234 bytes:
Staring...
I NimBLEDevice: BLE Host Task Started
I NimBLEDevice: NimBle host synced.
ok to setServiceData len: 234
BLE leAdvertising len: 252
E NimBLEExtAdvertising: Invalid advertisement data: rc = 530
BLE failed to set leAdvertising

Metadata
Metadata
Assignees
Labels
No labels