2016-01-19 19:39:38

by Travis Griggs

[permalink] [raw]
Subject: Preferred way to set name of device?

I’m intersted in setting the name of my device, when I’m acting as a BLE Peripheral. I see at least two, maybe three, ways to do it:

1) Set the `Name=` line near the top of /etc/bluetooth/main.conf
2) Use hciconfig hc0 name FooBar
3) Maybe something with the dbus interface?

So I’m curious which is the preferred/idiomatic way? In particular for my use case as a BLE Peripheral.

I’ve discovered the following issues already:

1) If I use main.conf, that will be tricky, because I’d like to set the name based on dynamic information computed by the device in startup (serial number from an attached piece of equipment). So I’d have to modify the file after I have gotten that information, and then restart the service. Not undoable, but far from elegant.
2) Though hciconfig will show back the name set, it doesn’t seem to actually show up when I scan.
3) Not sure how I figure out what the dbus interface is. Is this documented anywhere? Or does one just explore and guess with tools? Maybe it’s too early in the experimental phase to really document?

TIA


2016-01-21 11:07:41

by Marcel Holtmann

[permalink] [raw]
Subject: Re: Preferred way to set name of device?

Hi Travis,

> I’m intersted in setting the name of my device, when I’m acting as a BLE Peripheral. I see at least two, maybe three, ways to do it:
>
> 1) Set the `Name=` line near the top of /etc/bluetooth/main.conf
> 2) Use hciconfig hc0 name FooBar
> 3) Maybe something with the dbus interface?
>
> So I’m curious which is the preferred/idiomatic way? In particular for my use case as a BLE Peripheral.
>
> I’ve discovered the following issues already:
>
> 1) If I use main.conf, that will be tricky, because I’d like to set the name based on dynamic information computed by the device in startup (serial number from an attached piece of equipment). So I’d have to modify the file after I have gotten that information, and then restart the service. Not undoable, but far from elegant.
> 2) Though hciconfig will show back the name set, it doesn’t seem to actually show up when I scan.
> 3) Not sure how I figure out what the dbus interface is. Is this documented anywhere? Or does one just explore and guess with tools? Maybe it’s too early in the experimental phase to really document?

if you are actually more into the BLE space, then the LE Advertising D-Bus API is something you might want to look into. With a recent kernel and recent BlueZ, you can build your own advertising reports and include more dynamic naming if you want to.

Otherwise there is also a plugin mechanism for setting the device name. That is a preferred one and for example on a system running systemd-hostnamed it will take the device name from there. You could write your own plugin.

Regards

Marcel


2016-01-20 20:00:38

by Travis Griggs

[permalink] [raw]
Subject: Re: Preferred way to set name of device?


> On Jan 19, 2016, at 2:33 PM, Othman, Ossama <[email protected]> wrote:
>
> Hi,
>
> On Tue, Jan 19, 2016 at 11:39 AM, Travis Griggs <[email protected]> wrote:
>> I’m intersted in setting the name of my device, when I’m acting as a BLE Peripheral. I see at least two, maybe three, ways to do it:
>>
>> 1) Set the `Name=` line near the top of /etc/bluetooth/main.conf
>> 2) Use hciconfig hc0 name FooBar
>> 3) Maybe something with the dbus interface?
>>
>> So I’m curious which is the preferred/idiomatic way? In particular for my use case as a BLE Peripheral.
>>
>> I’ve discovered the following issues already:
>>
>> 1) If I use main.conf, that will be tricky, because I’d like to set the name based on dynamic information computed by the device in startup (serial number from an attached piece of equipment). So I’d have to modify the file after I have gotten that information, and then restart the service. Not undoable, but far from elegant.
>> 2) Though hciconfig will show back the name set, it doesn’t seem to actually show up when I scan.
>> 3) Not sure how I figure out what the dbus interface is. Is this documented anywhere? Or does one just explore and guess with tools? Maybe it’s too early in the experimental phase to really document?
>
> I'm not sure of the preferred way, but I believe the D-Bus interface
> you want is the "Alias" property in the org.bluez.Adapter1 interace:
>
> http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n119

It helped a lot, thank you. And now I have a link to all of the other DBus api descriptions too.


2016-01-19 22:33:03

by Othman, Ossama

[permalink] [raw]
Subject: Re: Preferred way to set name of device?

Hi,

On Tue, Jan 19, 2016 at 11:39 AM, Travis Griggs <[email protected]> wrote:
> I’m intersted in setting the name of my device, when I’m acting as a BLE Peripheral. I see at least two, maybe three, ways to do it:
>
> 1) Set the `Name=` line near the top of /etc/bluetooth/main.conf
> 2) Use hciconfig hc0 name FooBar
> 3) Maybe something with the dbus interface?
>
> So I’m curious which is the preferred/idiomatic way? In particular for my use case as a BLE Peripheral.
>
> I’ve discovered the following issues already:
>
> 1) If I use main.conf, that will be tricky, because I’d like to set the name based on dynamic information computed by the device in startup (serial number from an attached piece of equipment). So I’d have to modify the file after I have gotten that information, and then restart the service. Not undoable, but far from elegant.
> 2) Though hciconfig will show back the name set, it doesn’t seem to actually show up when I scan.
> 3) Not sure how I figure out what the dbus interface is. Is this documented anywhere? Or does one just explore and guess with tools? Maybe it’s too early in the experimental phase to really document?

I'm not sure of the preferred way, but I believe the D-Bus interface
you want is the "Alias" property in the org.bluez.Adapter1 interace:

http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n119

HTH
-Ossama