2017-05-05 22:28:01

by Travis Griggs

[permalink] [raw]
Subject: BLE Advertisement frustrations with pydbus

I=E2=80=99m trying to switch to using pydbus (instead of deprecated =
dbus-python, which the bluez examples are based on). I=E2=80=99m running =
on stretch with bluez 5.43. My code is at the bottom (and here -> =
https://gist.github.com/travisgriggs/d8e14dcccf46751804456dc74da1e5e6). =
I=E2=80=99m running into a problem when I try to RegisterAdvertisement. =
What I can=E2=80=99t seem to discern is what is different between this =
and the old approach. The bluetooth driver fails around =
advertising:c:175

DBusMessageIter iter;
const char *msg_type;

if (!g_dbus_proxy_get_property(proxy, "Type", &iter))
return false;

The g_dbus_proxy_get_property() call fails. What I don=E2=80=99t =
understand though is this. If I modify my program to NOT =
RegisterAdvertisement(), but just sit there with the advertisement =
object on the bus, I can do the following:

$ sudo busctl get-property :1.5 /nic/twigpilot =
org.bluez.LEAdvertisement1 Type
s =E2=80=9Cperipheral"

So I *am* able to get the Type using busctl. Why is that bluetoothd =
cannot? Using busctl introspect, I see that the pydbus variant =
automagically makes a lot more available than the dubs-python variant =
did.

Any hints? Pointers? Help?

TIA

=E2=80=94=E2=80=94

#!/usr/bin/env python3

import pydbus
from gi.repository import GLib

class Advertisement(object):
"""
<node>
<interface name=3D"org.bluez.LEAdvertisement1">
<method name=3D"Release">
<annotation name=3D"org.freedesktop.DBus.Method.NoReply" =
value=3D"true"/>
</method>
<annotation =
name=3D"org.freedesktop.DBus.Properties.PropertiesChanged" =
value=3D"const"/>
<property name=3D"Type" type=3D"s" access=3D"read"/>
<property name=3D"ServiceUUIDs" type=3D"as" access=3D"read"/>
<property name=3D"ManufacturerData" type=3D"a{sv}" =
access=3D"read"/>
<property name=3D"SolicitUUIDs" type=3D"as" access=3D"read"/>
<property name=3D"ServiceData" type=3D"a{sv}" access=3D"read"/>
<property name=3D"IncludeTxPower" type=3D"b" access=3D"read"/>
</interface>
</node>
"""

def __init__(self, bus):
self.Type =3D 'peripheral'
self.ServiceUUIDs =3D []
self.ManufacturerData =3D {}
self.SolicitUUIDs =3D []
self.ServiceData =3D {}
self.IncludeTxPower =3D False
bus.register_object('/nic/twigpilot', self, None)

def Release(self):
print('{}: Advertisement Released!'.format(self))


def main():
bus =3D pydbus.SystemBus()
adaptor =3D bus.get('org.bluez', '/org/bluez/hci0')
adaptor.Powered =3D True
adaptor.Alias =3D 'SeeMe'

advertisement =3D Advertisement(bus)
advertisement.IncludeTxPower =3D True

#adaptor.RegisterAdvertisement('/nic/twigpilot', {})

loop =3D GLib.MainLoop()
try:
loop.run()
except KeyboardInterrupt:
loop.quit()

if __name__ =3D=3D '__main__':
main()=


2017-05-08 20:46:08

by Barry Byford

[permalink] [raw]
Subject: Re: BLE Advertisement frustrations with pydbus

Hello,

On 8 May 2017 at 11:18, Luiz Augusto von Dentz <[email protected]> wrote=
:
> Hi Barry,
>
> On Mon, May 8, 2017 at 11:51 AM, Barry Byford <[email protected]> wrote:
>> Hello Luiz & Travis,
>>
>> I've been taking a look at this also
>>
>> On 8 May 2017 at 09:01, Luiz Augusto von Dentz <[email protected]> wr=
ote:
>>> On Sat, May 6, 2017 at 1:28 AM, Travis Griggs <[email protected]> =
wrote:
>>>> $ sudo busctl get-property :1.5 /nic/twigpilot org.bluez.LEAdvertiseme=
nt1 Type
>>>> s =E2=80=9Cperipheral"
>>>>
>>>> So I *am* able to get the Type using busctl. Why is that bluetoothd ca=
nnot? Using busctl introspect, I see that the pydbus variant automagically =
makes a lot more available than the dubs-python variant did.
>>>>
>>>> Any hints? Pointers? Help?
>>>
>>> Does pydbus have ObjectManager support?
>>
>> Looking at the following entry in the libraries issue list it seems
>> like it does.
>> https://github.com/LEW21/pydbus/issues/28
>> Is there anything in particular we should be testing for?
>
> This is support for ObjectManager as a client, I was asking for the
> server side so we can query the advertisement objects. Though this
> used to work even without ObjectManager support so perhaps there is
> some regression.

Given the information below, this seems like it is the issue.
Does this mean it is a bug in BlueZ?
Or is this how it is intend to work going forward?

>
>>
>>> What about GetAll properties?
>> Yes it does. It creates these standard interfaces automatically based
>> on the XML in the Python class doc string. So for example Get and
>> GetAll give the following:
>>
>>
>> $ busctl call ukBaz.bluezero /ukBaz/bluezero
>> org.freedesktop.DBus.Properties Get ss org.bluez.LEAdvertisement1 Type
>>
>> v s "peripheral"
>>
>> $ busctl call ukBaz.bluezero /ukBaz/bluezero
>> org.freedesktop.DBus.Properties GetAll s org.bluez.LEAdvertisement1
>>
>> a{sv} 3 "Type" s "peripheral" "SolicitUUIDs" as 1 "180F"
>> "IncludeTxPower" b false
>>
>>
>>> You could perhaps try to sniff the message with eavesdrop option:
>>>
>>> https://wiki.ubuntu.com/DebuggingDBus

This was a good suggestion. And you were correct about your suspicion
that it was missing ObjectManager.

method call time=3D1494270131.995970 sender=3D:1.13 ->
destination=3Dorg.freedesktop.DBus serial=3D78 path=3D/org/freedesktop/DBus=
;
interface=3Dorg.freedesktop.DBus; member=3DAddMatch
string "type=3D'signal',sender=3D':1.51',path=3D'/ukBaz/bluezero',interf=
ace=3D'org.freedesktop.DBus.Properties',member=3D'PropertiesChanged',arg0=
=3D'org.bluez.LEAdvertisement1'"
method return time=3D1494270131.996002 sender=3Dorg.freedesktop.DBus ->
destination=3D:1.13 serial=3D33 reply_serial=3D78
method call time=3D1494270131.996317 sender=3D:1.13 -> destination=3D:1.51
serial=3D79 path=3D/ukBaz/bluezero;
interface=3Dorg.freedesktop.DBus.Properties; member=3DGetAll
string "org.bluez.LEAdvertisement1"
method call time=3D1494270131.996358 sender=3D:1.13 -> destination=3D:1.51
serial=3D80 path=3D/ukBaz/bluezero;
interface=3Dorg.freedesktop.DBus.ObjectManager; member=3DGetManagedObjects
error time=3D1494270131.997525 sender=3D:1.51 -> destination=3D:1.13
error_name=3Dorg.freedesktop.DBus.Error.UnknownMethod reply_serial=3D80
string "No such interface 'org.freedesktop.DBus.ObjectManager' on
object at path /ukBaz/bluezero"


I'll do some investigation as to how difficult it is to implement
ObjectManager for this.


>>
>> Good suggestion. I'll try that later.
>>
>>>
>>>> TIA
>>>>
>>>> =E2=80=94=E2=80=94
>>>>
>>>> #!/usr/bin/env python3
>>>>
>>>> import pydbus
>>>> from gi.repository import GLib
>>>>
>>>> class Advertisement(object):
>>>> """
>>>> <node>
>>>> <interface name=3D"org.bluez.LEAdvertisement1">
>>>> <method name=3D"Release">
>>>> <annotation name=3D"org.freedesktop.DBus.Method.NoReply" v=
alue=3D"true"/>
>>>> </method>
>>>> <annotation name=3D"org.freedesktop.DBus.Properties.Properti=
esChanged" value=3D"const"/>
>>>> <property name=3D"Type" type=3D"s" access=3D"read"/>
>>>> <property name=3D"ServiceUUIDs" type=3D"as" access=3D"read"/=
>
>>>> <property name=3D"ManufacturerData" type=3D"a{sv}" access=3D=
"read"/>
>>>> <property name=3D"SolicitUUIDs" type=3D"as" access=3D"read"/=
>
>>>> <property name=3D"ServiceData" type=3D"a{sv}" access=3D"read=
"/>
>>>> <property name=3D"IncludeTxPower" type=3D"b" access=3D"read"=
/>
>>>> </interface>
>>>> </node>
>>>> """
>>>>
>>>> def __init__(self, bus):
>>>> self.Type =3D 'peripheral'
>>>> self.ServiceUUIDs =3D []
>>>> self.ManufacturerData =3D {}
>>>> self.SolicitUUIDs =3D []
>>>> self.ServiceData =3D {}
>>>> self.IncludeTxPower =3D False
>>>> bus.register_object('/nic/twigpilot', self, None)
>>>>
>>>> def Release(self):
>>>> print('{}: Advertisement Released!'.format(self))
>>>>
>>>>
>>>> def main():
>>>> bus =3D pydbus.SystemBus()
>>>> adaptor =3D bus.get('org.bluez', '/org/bluez/hci0')
>>>> adaptor.Powered =3D True
>>>> adaptor.Alias =3D 'SeeMe'
>>>>
>>>> advertisement =3D Advertisement(bus)
>>>> advertisement.IncludeTxPower =3D True
>>>>
>>>> #adaptor.RegisterAdvertisement('/nic/twigpilot', {})
>>>>
>>>> loop =3D GLib.MainLoop()
>>>> try:
>>>> loop.run()
>>>> except KeyboardInterrupt:
>>>> loop.quit()
>>>>
>>>> if __name__ =3D=3D '__main__':
>>>> main()--
>>>> To unsubscribe from this list: send the line "unsubscribe linux-blueto=
oth" in
>>>> the body of a message to [email protected]
>>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>
>>>
>>>
>>> --
>>> Luiz Augusto von Dentz
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe linux-bluetoo=
th" in
>>> the body of a message to [email protected]
>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
>
> --
> Luiz Augusto von Dentz

2017-05-08 20:26:23

by Travis Griggs

[permalink] [raw]
Subject: Re: BLE Advertisement frustrations with pydbus


> On May 8, 2017, at 11:07 AM, Cody P Schafer <[email protected]> wrote:
>=20
>> NAME TYPE SIGNATURE RESULT/VALUE =
FLAGS
>> .GetAll method s a{sv} =
-
>=20
>>=20
>> BUT=E2=80=A6 if I try to access as GetAll as you suggest:
>>=20
>> $ sudo busctl call :1.5 /nic/twigpilot =
org.freedesktop.DBus.Properties GetAll
>> No such interface 'org.freedesktop.DBus.Properties' on object at path =
/nic/twigpilot
>=20
> GetAll takes a string argument which is the interface name. Try:
>=20
> $ sudo busctl call :1.5 /nic/twigpilot org.freedesktop.DBus.Properties
> GetAll org.bluez.LEAdvertisement1

Argh (pun). I *thought* I had had that query working on Friday and was =
surprised when I was running it this morning to report that it =
wouldn=E2=80=99t work. So yes,

$ sudo busctl call :1.5 /nic/twigpilot org.freedesktop.DBus.Properties =
GetAll s org.bluez.LEAdvertisement1
a{sv} 6 "ServiceData" a{sv} 0 "ServiceUUIDs" as 0 "SolicitUUIDs" as 0 =
"Type" s "peripheral" "IncludeTxPower" b true "ManufacturerData" a{sv} 0

I *can* do the GetAll() query as Luis asked for. And resolves my =
intermediate question. But brings me back to the original question which =
behavior still persists.

As I said, dbus is a relatively new thing for me. I *think* naively that =
the problem lies somewhere around this call:

bus.register_object('/nic/twigpilot', self, None)

When I look at just simple `busctl` output, I see (amongst others):

$ busctl
NAME PID PROCESS USER =
CONNECTION UNIT SESSION DESCRIPTION =20
...
:1.15 1677 python3 root =
:1.15 [email protected]=E2=80=A6ce - - =
=20
...
:1.4 1385 bluetoothd root =
:1.4 bluetooth.service - - =20
org.bluez 1385 bluetoothd root =
:1.4 bluetooth.service - - =20

In my naive understanding=E2=80=A6 my python3 has an unnamed connection =
to the system bus (i.e. :1.15). And the bluetoothd has an unnamed =
connection at :1.14. But bluetoothd has also set up a repeatably =
accessible service at org.bluez. My python program has registered an =
object that has the necessary interfaces at the path /nic/twigpilot, =
but it hasn=E2=80=99t done anything to tie it in to the org.bluez =
service. And yet, when I look at the docs =
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/advertising-ap=
i.txt=E2=80=A6 It describes this object as belonging to the org.bluez =
service.

pydbus has an API higher up than register_object() called publish() =
(https://github.com/LEW21/pydbus/blob/master/doc/tutorial.rst#object-publi=
cation) which not only places the object at the given path, but also =
"binds the service to the given bus name=E2=80=9D. But if I use that api =
instead of register_object(), I get the following error=20

RuntimeError: name already exists on the bus

It could be that I=E2=80=99m barking up the completely wrong tree with =
this. I do find myself wishing BLE were exposed via a good old fashioned =
C library or some sort of pseudo file system thing like sysfs. But I=E2=80=
=99m trying to keep an open mind and hope the value-of-dbus light bulb =
will trigger soon.



2017-05-08 18:07:12

by Cody P Schafer

[permalink] [raw]
Subject: Re: BLE Advertisement frustrations with pydbus

> NAME TYPE SIGNATURE RESULT/VALUE FLAG=
S
> .GetAll method s a{sv} -

>
> BUT=E2=80=A6 if I try to access as GetAll as you suggest:
>
> $ sudo busctl call :1.5 /nic/twigpilot org.freedesktop.DBus.Properties Ge=
tAll
> No such interface 'org.freedesktop.DBus.Properties' on object at path /ni=
c/twigpilot

GetAll takes a string argument which is the interface name. Try:

$ sudo busctl call :1.5 /nic/twigpilot org.freedesktop.DBus.Properties
GetAll org.bluez.LEAdvertisement1

Or similar.

2017-05-08 17:43:09

by Travis Griggs

[permalink] [raw]
Subject: Re: BLE Advertisement frustrations with pydbus


> On May 8, 2017, at 1:01 AM, Luiz Augusto von Dentz =
<[email protected]> wrote:
>=20
> Hi Travis,
>=20
> On Sat, May 6, 2017 at 1:28 AM, Travis Griggs <[email protected]> =
wrote:
>> I=E2=80=99m trying to switch to using pydbus (instead of deprecated =
dbus-python, which the bluez examples are based on). I=E2=80=99m running =
on stretch with bluez 5.43. My code is at the bottom (and here -> =
https://gist.github.com/travisgriggs/d8e14dcccf46751804456dc74da1e5e6). =
I=E2=80=99m running into a problem when I try to RegisterAdvertisement. =
What I can=E2=80=99t seem to discern is what is different between this =
and the old approach. The bluetooth driver fails around =
advertising:c:175
>>=20
>> DBusMessageIter iter;
>> const char *msg_type;
>>=20
>> if (!g_dbus_proxy_get_property(proxy, "Type", &iter))
>> return false;
>>=20
>> The g_dbus_proxy_get_property() call fails. What I don=E2=80=99t =
understand though is this. If I modify my program to NOT =
RegisterAdvertisement(), but just sit there with the advertisement =
object on the bus, I can do the following:
>>=20
>> $ sudo busctl get-property :1.5 /nic/twigpilot =
org.bluez.LEAdvertisement1 Type
>> s =E2=80=9Cperipheral"
>>=20
>> So I *am* able to get the Type using busctl. Why is that bluetoothd =
cannot? Using busctl introspect, I see that the pydbus variant =
automagically makes a lot more available than the dubs-python variant =
did.
>>=20
>> Any hints? Pointers? Help?
>=20
> Does pydbus have ObjectManager support? What about GetAll properties?
> You could perhaps try to sniff the message with eavesdrop option:
>=20
> https://wiki.ubuntu.com/DebuggingDBus
>=20
>>=20

That=E2=80=99s a great question. My neophyte skills with dbus are not =
that strong, but the following DOES seem odd to me:

$ sudo busctl introspect :1.5 /nic/twigpilot
NAME TYPE SIGNATURE RESULT/VALUE =
FLAGS
org.bluez.LEAdvertisement1 interface - - -
.Release method - - =
no-reply
.IncludeTxPower property b true =
emits-change
.ManufacturerData property a{sv} 0 =
emits-change
.ServiceData property a{sv} 0 =
emits-change
.ServiceUUIDs property as 0 =
emits-change
.SolicitUUIDs property as 0 =
emits-change
.Type property s "peripheral" =
emits-change
org.freedesktop.DBus.Introspectable interface - - -
.Introspect method - s -
org.freedesktop.DBus.Peer interface - - -
.GetMachineId method - s -
.Ping method - - -
org.freedesktop.DBus.Properties interface - - -
.Get method ss v -
.GetAll method s a{sv} -
.Set method ssv - -
.PropertiesChanged signal sa{sv}as - -

So it seems to think it does=E2=80=A6 And as aforementioned, I can get =
the Type:

$ sudo busctl get-property :1.5 /nic/twigpilot =
org.bluez.LEAdvertisement1 Type
s =E2=80=9Cperipheral"

BUT=E2=80=A6 if I try to access as GetAll as you suggest:

$ sudo busctl call :1.5 /nic/twigpilot org.freedesktop.DBus.Properties =
GetAll
No such interface 'org.freedesktop.DBus.Properties' on object at path =
/nic/twigpilot

Which is really weird, because the `introspect` command seems to show it =
is there.=20

(sorry if this is sent twice, I got a weird response back the first time =
I submitted this message)=

2017-05-08 10:18:33

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: BLE Advertisement frustrations with pydbus

Hi Barry,

On Mon, May 8, 2017 at 11:51 AM, Barry Byford <[email protected]> wrote:
> Hello Luiz & Travis,
>
> I've been taking a look at this also
>
> On 8 May 2017 at 09:01, Luiz Augusto von Dentz <[email protected]> wro=
te:
>> On Sat, May 6, 2017 at 1:28 AM, Travis Griggs <[email protected]> w=
rote:
>>> $ sudo busctl get-property :1.5 /nic/twigpilot org.bluez.LEAdvertisemen=
t1 Type
>>> s =E2=80=9Cperipheral"
>>>
>>> So I *am* able to get the Type using busctl. Why is that bluetoothd can=
not? Using busctl introspect, I see that the pydbus variant automagically m=
akes a lot more available than the dubs-python variant did.
>>>
>>> Any hints? Pointers? Help?
>>
>> Does pydbus have ObjectManager support?
>
> Looking at the following entry in the libraries issue list it seems
> like it does.
> https://github.com/LEW21/pydbus/issues/28
> Is there anything in particular we should be testing for?

This is support for ObjectManager as a client, I was asking for the
server side so we can query the advertisement objects. Though this
used to work even without ObjectManager support so perhaps there is
some regression.

>
>> What about GetAll properties?
> Yes it does. It creates these standard interfaces automatically based
> on the XML in the Python class doc string. So for example Get and
> GetAll give the following:
>
>
> $ busctl call ukBaz.bluezero /ukBaz/bluezero
> org.freedesktop.DBus.Properties Get ss org.bluez.LEAdvertisement1 Type
>
> v s "peripheral"
>
> $ busctl call ukBaz.bluezero /ukBaz/bluezero
> org.freedesktop.DBus.Properties GetAll s org.bluez.LEAdvertisement1
>
> a{sv} 3 "Type" s "peripheral" "SolicitUUIDs" as 1 "180F"
> "IncludeTxPower" b false
>
>
>> You could perhaps try to sniff the message with eavesdrop option:
>>
>> https://wiki.ubuntu.com/DebuggingDBus
>
> Good suggestion. I'll try that later.
>
>>
>>> TIA
>>>
>>> =E2=80=94=E2=80=94
>>>
>>> #!/usr/bin/env python3
>>>
>>> import pydbus
>>> from gi.repository import GLib
>>>
>>> class Advertisement(object):
>>> """
>>> <node>
>>> <interface name=3D"org.bluez.LEAdvertisement1">
>>> <method name=3D"Release">
>>> <annotation name=3D"org.freedesktop.DBus.Method.NoReply" va=
lue=3D"true"/>
>>> </method>
>>> <annotation name=3D"org.freedesktop.DBus.Properties.Propertie=
sChanged" value=3D"const"/>
>>> <property name=3D"Type" type=3D"s" access=3D"read"/>
>>> <property name=3D"ServiceUUIDs" type=3D"as" access=3D"read"/>
>>> <property name=3D"ManufacturerData" type=3D"a{sv}" access=3D"=
read"/>
>>> <property name=3D"SolicitUUIDs" type=3D"as" access=3D"read"/>
>>> <property name=3D"ServiceData" type=3D"a{sv}" access=3D"read"=
/>
>>> <property name=3D"IncludeTxPower" type=3D"b" access=3D"read"/=
>
>>> </interface>
>>> </node>
>>> """
>>>
>>> def __init__(self, bus):
>>> self.Type =3D 'peripheral'
>>> self.ServiceUUIDs =3D []
>>> self.ManufacturerData =3D {}
>>> self.SolicitUUIDs =3D []
>>> self.ServiceData =3D {}
>>> self.IncludeTxPower =3D False
>>> bus.register_object('/nic/twigpilot', self, None)
>>>
>>> def Release(self):
>>> print('{}: Advertisement Released!'.format(self))
>>>
>>>
>>> def main():
>>> bus =3D pydbus.SystemBus()
>>> adaptor =3D bus.get('org.bluez', '/org/bluez/hci0')
>>> adaptor.Powered =3D True
>>> adaptor.Alias =3D 'SeeMe'
>>>
>>> advertisement =3D Advertisement(bus)
>>> advertisement.IncludeTxPower =3D True
>>>
>>> #adaptor.RegisterAdvertisement('/nic/twigpilot', {})
>>>
>>> loop =3D GLib.MainLoop()
>>> try:
>>> loop.run()
>>> except KeyboardInterrupt:
>>> loop.quit()
>>>
>>> if __name__ =3D=3D '__main__':
>>> main()--
>>> To unsubscribe from this list: send the line "unsubscribe linux-bluetoo=
th" in
>>> the body of a message to [email protected]
>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
>>
>>
>> --
>> Luiz Augusto von Dentz
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-bluetoot=
h" in
>> the body of a message to [email protected]
>> More majordomo info at http://vger.kernel.org/majordomo-info.html



--=20
Luiz Augusto von Dentz

2017-05-08 08:51:12

by Barry Byford

[permalink] [raw]
Subject: Re: BLE Advertisement frustrations with pydbus

Hello Luiz & Travis,

I've been taking a look at this also

On 8 May 2017 at 09:01, Luiz Augusto von Dentz <[email protected]> wrote=
:
> On Sat, May 6, 2017 at 1:28 AM, Travis Griggs <[email protected]> wr=
ote:
>> $ sudo busctl get-property :1.5 /nic/twigpilot org.bluez.LEAdvertisement=
1 Type
>> s =E2=80=9Cperipheral"
>>
>> So I *am* able to get the Type using busctl. Why is that bluetoothd cann=
ot? Using busctl introspect, I see that the pydbus variant automagically ma=
kes a lot more available than the dubs-python variant did.
>>
>> Any hints? Pointers? Help?
>
> Does pydbus have ObjectManager support?

Looking at the following entry in the libraries issue list it seems
like it does.
https://github.com/LEW21/pydbus/issues/28
Is there anything in particular we should be testing for?


> What about GetAll properties?
Yes it does. It creates these standard interfaces automatically based
on the XML in the Python class doc string. So for example Get and
GetAll give the following:


$ busctl call ukBaz.bluezero /ukBaz/bluezero
org.freedesktop.DBus.Properties Get ss org.bluez.LEAdvertisement1 Type

v s "peripheral"

$ busctl call ukBaz.bluezero /ukBaz/bluezero
org.freedesktop.DBus.Properties GetAll s org.bluez.LEAdvertisement1

a{sv} 3 "Type" s "peripheral" "SolicitUUIDs" as 1 "180F"
"IncludeTxPower" b false


> You could perhaps try to sniff the message with eavesdrop option:
>
> https://wiki.ubuntu.com/DebuggingDBus

Good suggestion. I'll try that later.

>
>> TIA
>>
>> =E2=80=94=E2=80=94
>>
>> #!/usr/bin/env python3
>>
>> import pydbus
>> from gi.repository import GLib
>>
>> class Advertisement(object):
>> """
>> <node>
>> <interface name=3D"org.bluez.LEAdvertisement1">
>> <method name=3D"Release">
>> <annotation name=3D"org.freedesktop.DBus.Method.NoReply" val=
ue=3D"true"/>
>> </method>
>> <annotation name=3D"org.freedesktop.DBus.Properties.Properties=
Changed" value=3D"const"/>
>> <property name=3D"Type" type=3D"s" access=3D"read"/>
>> <property name=3D"ServiceUUIDs" type=3D"as" access=3D"read"/>
>> <property name=3D"ManufacturerData" type=3D"a{sv}" access=3D"r=
ead"/>
>> <property name=3D"SolicitUUIDs" type=3D"as" access=3D"read"/>
>> <property name=3D"ServiceData" type=3D"a{sv}" access=3D"read"/=
>
>> <property name=3D"IncludeTxPower" type=3D"b" access=3D"read"/>
>> </interface>
>> </node>
>> """
>>
>> def __init__(self, bus):
>> self.Type =3D 'peripheral'
>> self.ServiceUUIDs =3D []
>> self.ManufacturerData =3D {}
>> self.SolicitUUIDs =3D []
>> self.ServiceData =3D {}
>> self.IncludeTxPower =3D False
>> bus.register_object('/nic/twigpilot', self, None)
>>
>> def Release(self):
>> print('{}: Advertisement Released!'.format(self))
>>
>>
>> def main():
>> bus =3D pydbus.SystemBus()
>> adaptor =3D bus.get('org.bluez', '/org/bluez/hci0')
>> adaptor.Powered =3D True
>> adaptor.Alias =3D 'SeeMe'
>>
>> advertisement =3D Advertisement(bus)
>> advertisement.IncludeTxPower =3D True
>>
>> #adaptor.RegisterAdvertisement('/nic/twigpilot', {})
>>
>> loop =3D GLib.MainLoop()
>> try:
>> loop.run()
>> except KeyboardInterrupt:
>> loop.quit()
>>
>> if __name__ =3D=3D '__main__':
>> main()--
>> To unsubscribe from this list: send the line "unsubscribe linux-bluetoot=
h" in
>> the body of a message to [email protected]
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
>
> --
> Luiz Augusto von Dentz
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth=
" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2017-05-08 08:01:53

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: BLE Advertisement frustrations with pydbus

Hi Travis,

On Sat, May 6, 2017 at 1:28 AM, Travis Griggs <[email protected]> wrot=
e:
> I=E2=80=99m trying to switch to using pydbus (instead of deprecated dbus-=
python, which the bluez examples are based on). I=E2=80=99m running on stre=
tch with bluez 5.43. My code is at the bottom (and here -> https://gist.git=
hub.com/travisgriggs/d8e14dcccf46751804456dc74da1e5e6). I=E2=80=99m running=
into a problem when I try to RegisterAdvertisement. What I can=E2=80=99t s=
eem to discern is what is different between this and the old approach. The =
bluetooth driver fails around advertising:c:175
>
> DBusMessageIter iter;
> const char *msg_type;
>
> if (!g_dbus_proxy_get_property(proxy, "Type", &iter))
> return false;
>
> The g_dbus_proxy_get_property() call fails. What I don=E2=80=99t understa=
nd though is this. If I modify my program to NOT RegisterAdvertisement(), b=
ut just sit there with the advertisement object on the bus, I can do the fo=
llowing:
>
> $ sudo busctl get-property :1.5 /nic/twigpilot org.bluez.LEAdvertisement1=
Type
> s =E2=80=9Cperipheral"
>
> So I *am* able to get the Type using busctl. Why is that bluetoothd canno=
t? Using busctl introspect, I see that the pydbus variant automagically mak=
es a lot more available than the dubs-python variant did.
>
> Any hints? Pointers? Help?

Does pydbus have ObjectManager support? What about GetAll properties?
You could perhaps try to sniff the message with eavesdrop option:

https://wiki.ubuntu.com/DebuggingDBus

> TIA
>
> =E2=80=94=E2=80=94
>
> #!/usr/bin/env python3
>
> import pydbus
> from gi.repository import GLib
>
> class Advertisement(object):
> """
> <node>
> <interface name=3D"org.bluez.LEAdvertisement1">
> <method name=3D"Release">
> <annotation name=3D"org.freedesktop.DBus.Method.NoReply" valu=
e=3D"true"/>
> </method>
> <annotation name=3D"org.freedesktop.DBus.Properties.PropertiesC=
hanged" value=3D"const"/>
> <property name=3D"Type" type=3D"s" access=3D"read"/>
> <property name=3D"ServiceUUIDs" type=3D"as" access=3D"read"/>
> <property name=3D"ManufacturerData" type=3D"a{sv}" access=3D"re=
ad"/>
> <property name=3D"SolicitUUIDs" type=3D"as" access=3D"read"/>
> <property name=3D"ServiceData" type=3D"a{sv}" access=3D"read"/>
> <property name=3D"IncludeTxPower" type=3D"b" access=3D"read"/>
> </interface>
> </node>
> """
>
> def __init__(self, bus):
> self.Type =3D 'peripheral'
> self.ServiceUUIDs =3D []
> self.ManufacturerData =3D {}
> self.SolicitUUIDs =3D []
> self.ServiceData =3D {}
> self.IncludeTxPower =3D False
> bus.register_object('/nic/twigpilot', self, None)
>
> def Release(self):
> print('{}: Advertisement Released!'.format(self))
>
>
> def main():
> bus =3D pydbus.SystemBus()
> adaptor =3D bus.get('org.bluez', '/org/bluez/hci0')
> adaptor.Powered =3D True
> adaptor.Alias =3D 'SeeMe'
>
> advertisement =3D Advertisement(bus)
> advertisement.IncludeTxPower =3D True
>
> #adaptor.RegisterAdvertisement('/nic/twigpilot', {})
>
> loop =3D GLib.MainLoop()
> try:
> loop.run()
> except KeyboardInterrupt:
> loop.quit()
>
> if __name__ =3D=3D '__main__':
> main()--
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth=
" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html



--=20
Luiz Augusto von Dentz