13
votes

I am trying to change a raspberry pi's bluetooth name to something else (an ip address) so that when I scan and pair my android device it will see this ip as the device name. It worked once but then went back to appearing as "raspberrypi-0"

I have tried both the hciconfig set name command, and have also changed the device name inside /etc/bluetooth/main.conf but still all my device sees is "raspberrypi-0". Its driving me crazy so if anyone knows what the issue is please help!

6

6 Answers

25
votes

If you want to change the bluetooth device name permanently, you have to create a file called /etc/machine-info which should have the following content:

PRETTY_HOSTNAME=device-name

Then issue "service bluetooth restart" after that

9
votes

@Evangelos Nannos answer still works (BlueZ 5.50) but if you want to change bluetooth alias on the fly you may try bluetoothctl (tested on Pi Zero W running Raspbian Stretch & BlueZ 5.50)

To set new alias open terminal:

    pi@raspberrypi:~ $ bluetoothctl
    [bluetooth]# system-alias 'Your New BT Alias'
    Changing Your New BT Alias succeeded        
    [CHG] Controller AA:BB:CC:DD:EE:FF Alias: Your New BT Alias

Use show to see current bluetooth settings:

    [bluetooth]# show
    Controller AA:BB:CC:DD:EE:FF
    Name: Some_other_name #default or as PRETTY_HOSTNAME
    Alias: Your New BT Alias #alias will be shown when scanning for bt devices
    (...)

Reset alias and go back to using system device name with:

    [bluetooth]# reset-alias

Exit bluetootctl with:

    [bluetooth]# quit

With Discoverable on (yes) the device will show up during scaning as Your New BT Alias.

Take note that alias will be kept after reboot!

I've use pexpect to manipulate bluetoothctl, bash works too. There were problems registering Agent on BlueZ 5.43 via pexpect, had to upgrade to 5.50


Alternative command (note it will not return a response):

    pi@raspberrypi:~ $ sudo hciconfig hci0 name 'New device name'
1
votes

It stores the display name in /var/lib/bluetooth/xx:xx:xx:xx:xx:xx/config file. If you wants to change the bluetooth display(broadcast) name then you need to follow the below steps:

  1. delete /var/lib/bluetooth/xx:xx:xx:xx:xx:xx/config file.
  2. Edit /etc/bluetooth/main.conf(For ex: Name=%d-%h to Name=abcd-5)
  3. service bluetooth restart.

Note: If this already paired with some other BT devices, so you need to remove the pairing to see the new BT name of the same device(MAC).

1
votes

You can also just disable the hostname plugin and configure the name.

Run sudo vim /etc/systemd/system/bluetooth.target.wants/bluetooth.service and append --noplugin=hostname, like this:

ExecStart=/usr/lib/bluetooth/bluetoothd --noplugin=hostname

Then edit the bluetooth config and set your desired name: sudo vim /etc/bluetooth/main.conf

Name = YourNewName
0
votes

Just follow the below steps

step 1 - write below code in terminal

sudo nano /etc/machine-info

step 2 - It will open a blank file, Now write this line into it

PRETTY_HOSTNAME=PutYourDeviceNameHere

step 3 - Now restart Bluetooth service OR You can reboot Raspberry Pi

service bluetooth restart

OR

sudo reboot

Hope it's Work For you

0
votes

Use hostnamectl command for change or set your bluetooth name.

hostnamectl --pretty set-hostname <PutYourDeviceNameHere>