BluetoothSerial.h bluetooth name to include one time variable (serial#)?

Hello all,

I am working with bluetoothserial.h for the first time and have not had much luck finding good documentation, do you know where I can find it?

I have it working fine in my script but I would like to add a serial number after the bluetooth device name, I have tried as many of the logical naming conventions as I could think of but none have worked. My serial is generated in setup, based on the mac address of my ESP32 and saved as a variable "id" prior to the bluetooth naming.

I am looking for something like:

    for(int i=0; i<17; i=i+8) {
    id |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
    }

    //bluetooth
    Serial.begin(115200);
    SerialBT.begin("BluetoothName " id); //Bluetooth device name
    Serial.println("The device started, now you can pair it with bluetooth!");

Is this not possible? or what am I doing wrong?

Thanks

The source code for the library is here
https://github.com/espressif/arduino-esp32/tree/master/libraries/BluetoothSerial

SerialBT.begin("BluetoothName " id); //Bluetooth device name

To use the id as the local name for the .begin, you will have to convert the id number to a character array.

SerialBluteooth.begin("local name")

1 Like

Awesome, thanks cattledog. That solved the serial number name broadcast issue but it will only display the serial number or name, not both.

These work:

SerialBT.begin("BluetoothName " );
or
SerialBT.begin(ID);

These do not work:

SerialBT.begin("BluetoothName " ID);
SerialBT.begin("BluetoothName ",ID );
SerialBT.begin("BluetoothName ", ID );

Any ideas?

I also just tried a shorter version with a total of 7 characters including a shortened name and first four of the serial, to no avail.

You will want something like this to combine the integer ID and the name into one for use in .begin().

 int ID = 1234; 
 String name = "BluetoothName: ";
 String nameID;
 nameID = name + String(ID); 
 SerialBT.begin(nameID);
1 Like

Awesome, that make perfect sense when you point it out cattledog. It works great. Thank you for your help.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.