Skip to content

ExtAdvertisement on ESP32 - data length issue #910

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

Closed
Jeronimo59 opened this issue Mar 7, 2025 · 7 comments
Closed

ExtAdvertisement on ESP32 - data length issue #910

Jeronimo59 opened this issue Mar 7, 2025 · 7 comments
Labels
bug Something isn't working

Comments

@Jeronimo59
Copy link

Jeronimo59 commented Mar 7, 2025

Hello,

Thank you for this great work.

When trying to send/receive extended advertisements (using NimBLEExt.setManufacturerdata()) with more than 28 bytes, I get the following message on the receiver's logs:
E (22095) NimBLE: Received HCI data length at host (74) exceeds maximum configured HCI event buffer size (70).

After some investigation, I found the log originates from file esp_nimble_hci.c (line 198):

if (totlen > MYNEWT_VAL(BLE_TRANSPORT_EVT_SIZE)) {
            ESP_LOGE(LOG_TAG, "Received HCI data length at host (%d) exceeds maximum configured HCI event buffer size (%d).",
                     totlen, MYNEWT_VAL(BLE_TRANSPORT_EVT_SIZE));  
            ble_hs_sched_reset(BLE_HS_ECONTROLLER);  
            return 0;  
        }

The message size appears to be limited by MYNEWT_VAL(BLE_TRANSPORT_EVT_SIZE)) that translates after macro processing to MYNEWT_VAL_BLE_TRANSPORT_EVT_SIZE, which is defined (for ESP platform) in esp_nimble_cfg.h (line 1592) with a value of 70 (in line with the log message) :

#ifndef MYNEWT_VAL_BLE_TRANSPORT_EVT_SIZE
#   define MYNEWT_VAL_BLE_TRANSPORT_EVT_SIZE (70)
#endif

Changing the value to 200 seems to solve the problem, as I managed to receive the data properly.

I guess this definition of MYNEWT_VAL_BLE_TRANSPORT_EVT_SIZE should be somehow increased to over 200 when Extended Advertisement is enabled (CONFIG_BT_NIMBLE_EXT_ADV defined).

Any help on how to do this properly (not sure what should be the correct value) will be welcome.

@davidk88
Copy link

davidk88 commented Mar 12, 2025

Hello,

I'm getting similiar error on ESP32-C3:

E (7254378) NimBLE: Received HCI data length at host (165) exceeds maximum configured HCI event buffer size (70).

@davidk88
Copy link

I added -DDMYNEWT_VAL_BLE_TRANSPORT_EVT_SIZE=256 to build_flags (platformIO)

@Jeronimo59
Copy link
Author

Hello

I did the same, and got it to broadcast (100ms interval) up to 220 bytes. Works perfectly with 2 receiving devices , but I guess it should work with any number of them.

I am still interested by h2zero's feedback on this fix, as there may be side effects, and it should be better applied in the original code.

Hello,

I'm getting similiar error on ESP32-C3:

E (7254378) NimBLE: Received HCI data length at host (165) exceeds maximum configured HCI event buffer size (70).

@h2zero
Copy link
Owner

h2zero commented Mar 12, 2025

Thank you for reporting this. There was a change in the available config settings and the default for this is supposed to be 257 when extended advertising is enabled. I will make this correction for the next release, in the mean time you should set this value yourself either in nimconfig.h or on the command line.

@h2zero h2zero added the bug Something isn't working label Mar 12, 2025
@Jeronimo59
Copy link
Author

Jeronimo59 commented Mar 18, 2025

Thank you for reporting this. There was a change in the available config settings and the default for this is supposed to be 257 when extended advertising is enabled. I will make this correction for the next release, in the mean time you should set this value yourself either in nimconfig.h or on the command line.

Thank you for that.

FYI, all is fine with messages up to 223 bytes (+6 byte-header). With 224 bytes (=230 bytes incl. header), logs show that packet is received (NimBLEScanCallbacks: Discovered), but NimBLEAdvertisedDevice::haveManufacturerData() returns false.

Maybe this is expected behavior, or another little fix with config settings could give us a few more bytes...

But this is already a huge benefit vs 31 bytes, as it makes my project (real-time control of a dozen lego trains) possible !

In case this helps someone, I found that restraining the scan to a single PHY (hence avoiding channel change) on the receiver side ensures low latency & 100% reception of packets when broadcasting every 100ms.
Now I need to figure out how to use other PHYs to establish occasional connections while keeping the broadcast going ...

Thank you again.

@Jeronimo59
Copy link
Author

I added -DDMYNEWT_VAL_BLE_TRANSPORT_EVT_SIZE=256 to build_flags (platformIO)

I guess you mean -DMYNEWT_VAL_BLE_TRANSPORT_EVT_SIZE=256 ;-)

@h2zero
Copy link
Owner

h2zero commented Apr 23, 2025

Closing as resolved in 8f32a23

@h2zero h2zero closed this as completed Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants