espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.71k stars 7.43k forks source link

Unable to advertise binary payload with BLE server #10590

Closed bilogic closed 1 week ago

bilogic commented 1 week ago

Board

ESP32

Device Description

WROOM32

Hardware Configuration

Nothing else.

Version

latest master (checkout manually)

IDE Name

PlatformIO on VSCode

Operating System

Windows 10

Flash frequency

40Mhz

PSRAM enabled

yes

Upload speed

115200

Description

https://github.com/espressif/arduino-esp32/blob/09a6770320b75c219053aa19d630afe1a7c61147/libraries/BLE/src/BLEAdvertising.cpp#L472

My payload is truncated when it contains 0x0 because expected type of string is a null character terminated type.

Sketch

char buf[3];
buf[0] = 1;
buf[1] = 0;
buf[2] = 1;

pAdvertistmentDataa->setServiceData(BLEUUID(0x181D), buf); 
// only 1 character set as payload instead of 3 because buf[1] is null

Debug Message

N/A

Other Steps to Reproduce

Can we please add a length parameter?

I have checked existing issues, online documentation and the Troubleshooting Guide

SuGlider commented 1 week ago

There is no issue. Just use it as suggested below:

char buf[3];
buf[0] = 1;
buf[1] = 0;
buf[2] = 1;

// String is just a binary holder created from a byte array
pAdvertistmentDataa->setServiceData(BLEUUID(0x181D), String(buf, sizeof(buf))); 
bilogic commented 1 week ago

ok thanks