Broadcast bluetooth messages

I want to send bluetooth broadcast messages from Esp32
Is this supported ?

Actually I don'T have much information about broadcast bluetooth messages , but I want to replicate the behaviour of following linux tool & command:

hcitool -i hci0 cmd 0x08 0x0008 1E 02 01 1A 1A ff *83 01* e9 0c 00 0f 0f 5d
46 5b f0 05 32 37 48 95 cf 8a ad

how can I do that ?

try something like that:

#include <BLEDevice.h>                   // Include BLEDevice library
#include <BLEUtils.h>                    // Include BLEUtils library
// #include <BLEServer.h>                   // Include BLEServer library if you need the server part

std::string advDataString = /* Length            */ "\x1E"                        
                            /* Flags             */ "\x02\x01\x1A"
                            /* Manufacturer info */ "\x1A\xFF"
                            /* Custom data       */ "\x83\x01\xE9\x0C\x00\x0F\x0F\x5D\x46\x5B\xF0\x05\x32\x37\x48\x95\xCF\x8A\xAD"; 

void setup() {
  BLEDevice::init("ESP32");                                     // Initialize BLE with a given name
 // BLEServer *pServer = BLEDevice::createServer();             // Create a BLE server (if you need to handle connections or services)
  BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();   // Create a BLE advertising object
  BLEAdvertisementData advertisementData;                       // Create a BLEAdvertisementData object
  advertisementData.setManufacturerData(advDataString);         // Set the advertisement data
  pAdvertising->setAdvertisementData(advertisementData);        // Apply the advertising data to the advertising object
  pAdvertising->start();                                        // Start advertising
}

void loop() {}

here is what I see in nRF Connect

I think you misunderstood.
I am not asking for bluetooth advertising. I am sking bluetooth broadcast message sending.
So one device sends broadcast to many devices.
and I need to replicate:
hcitool -i hci0 cmd 0x08 0x0008 1E 02 01 1A 1A ff 83 01 e9 0c 00 0f 0f 5d
46 5b f0 05 32 37 48 95 cf 8a ad

ok. broadcast message might mean advertising.
so I am trying the example, but BLEDevice library uses too much sketch space.
"arduino Sketch uses 1584965 bytes (120%) of program storage space. Maximum is 1310720 bytes."

how can I reduce this ?

Yes, broadcasting in Bluetooth Low Energy (BLE) can be somewhat confusing because the term "broadcasting" is often used interchangeably with "advertising". In BLE, advertising is the primary method used to broadcast data to all devices in range.

if you're referring to sending a generic BLE broadcast message (which still uses advertising channels), the data itself would be part of the advertising payload.

I compiled my code that fine on my ESP32. (but BLE is a lot of stuff so it needs lots of memory indeed)

because of the memory issue I switched to NimBLE which is recommended for its low resource use.
So now I tried :

NimBLEDevice::init("NimBLE");
  NimBLEAdvertising *pAdvertising = NimBLEDevice::getAdvertising(); // create advertising instance
  NimBLEAdvertisementData advertisementData;   
  advertisementData.setManufacturerData(advDataString);         // Set the advertisement data
  pAdvertising->setAdvertisementData(advertisementData);
  pAdvertising->start(); // start advertising

but I can't see the device NimBLE
what is wrong ?

I never used NimBLE... sorry

ok. I see you have embedded the data from my hcitool example to your initial example.
But I don't see the use of 0x08 and 0x0008
where should it go ?

hcitool -i hci0 cmd 0x08 0x0008 1E 02 01 1A 1A ff 83 01 e9 0c 00 0f 0f 5d
46 5b f0 05 32 37 48 95 cf 8a ad

The 0x08(OGF) and 0x0008 (OCF) form the opcode for the HCI command to set the advertising data.

When using the Arduino BLE library, I don't think you need to explicitly use these opcodes because the library abstracts these details away and provides higher-level functions to achieve the same result.

also, you had written an example code for sending single message without using BLEDevice library.
but now I can't see it ?
did you remove it ?

Yes I removed that as I could not get it to work (issues initializing the BT stack, probably arduino’s config was conflicting)

ok. NimBLE seems to work just as the standard BLE library.
I can see it being advertising if I add the service and characteristic.
But this advertisement does not work as expected.
Maybe I need a single message as you said before. How can I do that ?

the idea was to create a paylaod

#include <esp_bt.h>
#include <esp_bt_main.h>

// Global buffer for the HCI command
uint8_t hciCmdBuf[] = {
  0x08, 0x20,         // Opcode: 0x2008 (LE Set Advertising Data)
  0x1E,               // Length of the payload
  0x02, 0x01, 0x1A,   // Flags
  0x1A, 0xFF,         // Manufacturer specific data type and length
  0x83, 0x01,         // Custom data
  0xE9, 0x0C, 0x00, 0x0F, 0x0F, 0x5D,
  0x46, 0x5B, 0xF0, 0x05, 0x32, 0x37,
  0x48, 0x95, 0xCF, 0x8A, 0xAD
};

and use esp_vhci_host_send_packet() to send the it

  esp_vhci_host_send_packet(hciCmdBuf, sizeof hciCmdBuf);

you need to get the BLE stack ready before that. I don't have the time to explore this in details

may be check out the examples (possibly controller_vhci_ble_adv)

this is espressif IDE
I need it for Arduino

Anybody who knows ?

That’s just C code - you would need to adjust this into an Arduino sketch but the function calls should just work the same way (the IDE C++ compiler can deal with those C functions)

I’m on the road for the next 3 days so can’t look at that.

I've asked to the author of the code that I am trying to run.
He says "Try moving the 8301 to the manufacturing info and out of the data packet."

But in the example you wrote, everything is wrtten ,n manufacture data. There is no separate data, how can I do that ?

It depends what he meant as the definition of the data

As you see the 8301 is before the payload

just for reference, the following code worked:

NimBLEDevice::init("");
NimBLEAdvertising *pAdvertising = NimBLEDevice::getAdvertising();
//e100e905006f0ef5b0 - red
// 6F -> 0110 1111
// dec:15 - > 01111
// dec:26 - > 11010
// 0111 1010 -> 7A
//uint8_t Adv_DATA[] = {0x83, 0x01, 0xe1, 0x00, 0xe9, 0x05, 0x00, 0x6f, 0x0e, 0xf5, 0xb0};
uint8_t Adv_DATA[] = {0x83, 0x01, 0xe1, 0x00, 0xe9, 0x05, 0x00, 0x7a, 0x0e, 0xf5, 0xb0};
//e100e9080065d255005500b0 - custom color
//uint8_t Adv_DATA[] = {0x83, 0x01, 0xe1, 0x00, 0xe9, 0x08, 0x00, 0x65, 0xd2, 0x55, 0x00, 0x55, 0x00, 0xb0};
//e9 0b 0b 0f 0f 5c 5d 48 a5 d1 45 32 05 - circle animation
//uint8_t Adv_DATA[] = {0x83, 0x01, 0xe1, 0x00, 0xe9, 0x0b, 0x0b, 0x0f, 0x0f, 0x5c, 0x5d, 0x48, 0xa5, 0xd1, 0x45, 0x32, 0x05};

NimBLEAdvertisementData oAdvertisementCustom = NimBLEAdvertisementData();
oAdvertisementCustom.setManufacturerData(std::string((char *)&Adv_DATA[0],11));
pAdvertising->setAdvertisementData(oAdvertisementCustom);
pAdvertising->start(); // start advertising