2015-10-20 22:26:42

by Barry Byford

[permalink] [raw]
Subject: Python reading Eddystone beacons

Hello,

I’m looking to use a Raspberry Pi running the latest Raspbian Jessie operation
system with Bluez 5.23.

I’m trying to create a workshop for schools to interact with Eddystone
BLE beacons.
The workshop will show students the basics of reading the beacon data
and then it will
be up to the students to build applications from this using the Python
programming language.
The Raspberry Pi allows us to use them as the development platform and
to run the
final application also.
Python is the chosen language as this is what schools seem to be using the most.

The way that I’m currently doing the scanning for the beacon data is
with this bash
script:
#!/bin/bash
sudo hcitool lescan --duplicates 1>/dev/null &
trap "sudo kill $!" EXIT
sudo hcidump --raw

The output is then be parsed with a Python library that would be what
the students
called to get the data.

While I’m making some progress with the above shell script it doesn’t seem very
elegant. It looks like there should be a better way using the D-Bus API.
I’ve been looking in
https://git.kernel.org/cgit/bluetooth/bluez.git/tree/test?id=5.23
for inspiration but don’t seem to have anything that is showing me the beacon
advertisement.

Should I be able to get the Eddystone beacon payload using Python with
the D-Bus API
in Bluez 5.23?
Is there a good tutorial/example that I could look at?

Thanks in advance for any help or advice.

Regards,
Barry


$ uname -a
Linux raspberrypi 4.1.7+ #817 PREEMPT Sat Sep 19 15:25:36 BST 2015
armv6l GNU/Linux

$ bluetoothd -v
5.23


2015-10-23 08:08:52

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: Python reading Eddystone beacons

Hi Barry,

On Thu, Oct 22, 2015 at 3:47 PM, Barry Byford <[email protected]> wrote:
> Hi Luiz
>
> On 21 October 2015 at 09:31, Luiz Augusto von Dentz
> <[email protected]> wrote:
>> On Wed, Oct 21, 2015 at 1:26 AM, Barry Byford <[email protected]> wrote:
>>> I’m looking to use a Raspberry Pi running the latest Raspbian Jessie operation
>>> system with Bluez 5.23.
>>> The way that I’m currently doing the scanning for the beacon data is
>>> with this bash
>>> script:
>>> #!/bin/bash
>>> sudo hcitool lescan --duplicates 1>/dev/null &
>>> trap "sudo kill $!" EXIT
>>> sudo hcidump --raw
>>>
>>> Should I be able to get the Eddystone beacon payload using Python with
>>> the D-Bus API
>>> in Bluez 5.23?
>>> Is there a good tutorial/example that I could look at?
>>
>> bluetoothctl does actually print the advertising data:
>>
>> [bluetooth]# scan on
>> Discovery started
>> [CHG] Controller XX:XX:XX:XX:XX:XX Discovering: yes
>> [CHG] Device XX:XX:XX:XX:XX:XX RSSI: -34
>> [CHG] Device XX:XX:XX:XX:XX:XX Name: Test beacon
>> [CHG] Device XX:XX:XX:XX:XX:XX Alias: Test beacon
>> [CHG] Device XX:XX:XX:XX:XX:XX ServiceData Key: fed8
>> [CHG] Device XX:XX:XX:XX:XX:XX ServiceData Value: 0x00
>> [CHG] Device XX:XX:XX:XX:XX:XX ServiceData Value: 0x20
>> [CHG] Device XX:XX:XX:XX:XX:XX ServiceData Value: 0x02
>> [CHG] Device XX:XX:XX:XX:XX:XX ServiceData Value: 0x30
>> [CHG] Device XX:XX:XX:XX:XX:XX ServiceData Value: 0x31
>> [CHG] Device XX:XX:XX:XX:XX:XX ServiceData Value: 0x08
>
> Thanks for pointing me in the direction of bluetoothctl. However I'm
> not getting my beacon advertising data out with bluetoothctl.
> It reports things like my phone that is waiting to be paired but no beacons.
>
> What is the best way to get debug information out?.

I forgot to mention it was introduced in 5.31, so you probably need to
update if you want to use these properties.

>
>> It is basically using the properties ServiceData and ManufacturerData:
>>
>> https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/device-api.txt
>>
>> With this all you need to do is to listen for PropertiesChanged and
>> decode the values,
> I will get the bluetoothctl working before looking at this but thanks for
> the information this was what I was looking for.
>
>> it would probably be good idea to have a python
>> sample of decoding eddystone beacons, or beacons in general.
> I would certainly find it helpful. :-)
>
> Thanks,
> Barry
> --
> 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



--
Luiz Augusto von Dentz

2015-10-22 12:47:03

by Barry Byford

[permalink] [raw]
Subject: Re: Python reading Eddystone beacons

Hi Luiz

On 21 October 2015 at 09:31, Luiz Augusto von Dentz
<[email protected]> wrote:
> On Wed, Oct 21, 2015 at 1:26 AM, Barry Byford <[email protected]> wrote:
>> I’m looking to use a Raspberry Pi running the latest Raspbian Jessie operation
>> system with Bluez 5.23.
>> The way that I’m currently doing the scanning for the beacon data is
>> with this bash
>> script:
>> #!/bin/bash
>> sudo hcitool lescan --duplicates 1>/dev/null &
>> trap "sudo kill $!" EXIT
>> sudo hcidump --raw
>>
>> Should I be able to get the Eddystone beacon payload using Python with
>> the D-Bus API
>> in Bluez 5.23?
>> Is there a good tutorial/example that I could look at?
>
> bluetoothctl does actually print the advertising data:
>
> [bluetooth]# scan on
> Discovery started
> [CHG] Controller XX:XX:XX:XX:XX:XX Discovering: yes
> [CHG] Device XX:XX:XX:XX:XX:XX RSSI: -34
> [CHG] Device XX:XX:XX:XX:XX:XX Name: Test beacon
> [CHG] Device XX:XX:XX:XX:XX:XX Alias: Test beacon
> [CHG] Device XX:XX:XX:XX:XX:XX ServiceData Key: fed8
> [CHG] Device XX:XX:XX:XX:XX:XX ServiceData Value: 0x00
> [CHG] Device XX:XX:XX:XX:XX:XX ServiceData Value: 0x20
> [CHG] Device XX:XX:XX:XX:XX:XX ServiceData Value: 0x02
> [CHG] Device XX:XX:XX:XX:XX:XX ServiceData Value: 0x30
> [CHG] Device XX:XX:XX:XX:XX:XX ServiceData Value: 0x31
> [CHG] Device XX:XX:XX:XX:XX:XX ServiceData Value: 0x08

Thanks for pointing me in the direction of bluetoothctl. However I'm
not getting my beacon advertising data out with bluetoothctl.
It reports things like my phone that is waiting to be paired but no beacons.

What is the best way to get debug information out?.


> It is basically using the properties ServiceData and ManufacturerData:
>
> https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/device-api.txt
>
> With this all you need to do is to listen for PropertiesChanged and
> decode the values,
I will get the bluetoothctl working before looking at this but thanks for
the information this was what I was looking for.

> it would probably be good idea to have a python
> sample of decoding eddystone beacons, or beacons in general.
I would certainly find it helpful. :-)

Thanks,
Barry

2015-10-21 08:31:21

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: Python reading Eddystone beacons

Hi Barry,

On Wed, Oct 21, 2015 at 1:26 AM, Barry Byford <[email protected]> wrote:
> Hello,
>
> I’m looking to use a Raspberry Pi running the latest Raspbian Jessie operation
> system with Bluez 5.23.
>
> I’m trying to create a workshop for schools to interact with Eddystone
> BLE beacons.
> The workshop will show students the basics of reading the beacon data
> and then it will
> be up to the students to build applications from this using the Python
> programming language.
> The Raspberry Pi allows us to use them as the development platform and
> to run the
> final application also.
> Python is the chosen language as this is what schools seem to be using the most.
>
> The way that I’m currently doing the scanning for the beacon data is
> with this bash
> script:
> #!/bin/bash
> sudo hcitool lescan --duplicates 1>/dev/null &
> trap "sudo kill $!" EXIT
> sudo hcidump --raw
>
> The output is then be parsed with a Python library that would be what
> the students
> called to get the data.
>
> While I’m making some progress with the above shell script it doesn’t seem very
> elegant. It looks like there should be a better way using the D-Bus API.
> I’ve been looking in
> https://git.kernel.org/cgit/bluetooth/bluez.git/tree/test?id=5.23
> for inspiration but don’t seem to have anything that is showing me the beacon
> advertisement.
>
> Should I be able to get the Eddystone beacon payload using Python with
> the D-Bus API
> in Bluez 5.23?
> Is there a good tutorial/example that I could look at?

bluetoothctl does actually print the advertising data:

[bluetooth]# scan on
Discovery started
[CHG] Controller XX:XX:XX:XX:XX:XX Discovering: yes
[CHG] Device XX:XX:XX:XX:XX:XX RSSI: -34
[CHG] Device XX:XX:XX:XX:XX:XX Name: Test beacon
[CHG] Device XX:XX:XX:XX:XX:XX Alias: Test beacon
[CHG] Device XX:XX:XX:XX:XX:XX ServiceData Key: fed8
[CHG] Device XX:XX:XX:XX:XX:XX ServiceData Value: 0x00
[CHG] Device XX:XX:XX:XX:XX:XX ServiceData Value: 0x20
[CHG] Device XX:XX:XX:XX:XX:XX ServiceData Value: 0x02
[CHG] Device XX:XX:XX:XX:XX:XX ServiceData Value: 0x30
[CHG] Device XX:XX:XX:XX:XX:XX ServiceData Value: 0x31
[CHG] Device XX:XX:XX:XX:XX:XX ServiceData Value: 0x08

It is basically using the properties ServiceData and ManufacturerData:

https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/device-api.txt

With this all you need to do is to listen for PropertiesChanged and
decode the values, it would probably be good idea to have a python
sample of decoding eddystone beacons, or beacons in general.


--
Luiz Augusto von Dentz