low energy: does gatt client/server work in current version? How to test?
Hi!
I'm trying to get gatt client/server to run; my ultimate goal is to turn Linux machine into "low-energy device", providing services similar to heartbeat measurement.
I do have existing qt application (running on Android and PC) I'd like "device" to talk to.
TODO says:
- Add complete GATT test coverage in unit/test-gatt following the GATT test
spec. This could use shared/gatt-client and shared/gatt-server at
the same
time to test both against each other. We should definitely have
tests for
gatt-server and gatt-client simultaneously on one side of the
connection.
Priority: High
Complexity: C4
Which tells me that maybe I should consider helping with that. But so far I was not able to get it to work...
I can use gatt-server and connect to it using gatttool, but depending on details during the server start (?) and phase of moon, either device is not enumerated by the QT code, or it is not detected as low-energy device, or no UUIDs are detected.
My attempt at launching server is below (using python gatt-server, (1) ). I was doing "hciconfig leadv 0" manually at some point.
Using hciconfig while bluetoothd is running sounds kind-of dangerous. Stackoverflow (2) suggests using btmgmt (3) instead, and things got slightly different, but did not start to work for me. Is there documentation how to get this to work somewhere?
Thanks and best regards,
Pavel
(3)
sudo tools/btmgmt -i hci0 power off
sudo tools/btmgmt -i hci0 le on
sudo tools/btmgmt -i hci0 connectable on sudo tools/btmgmt -i hci0 name "some friendly name" sudo tools/btmgmt -i hci0 advertising on sudo tools/btmgmt -i hci0 power on tools/btgatt-server -i hci0 -s low -t public -r -v
(1)
#!/usr/bin/python3
# -*- python -*-
import os
import re
import time
def pcmd(c):
return os.popen(c).readline()[:-1]
class Ble:
def down(m):
print("Shutting down BLEE")
os.system("sudo killall bluetoohd")
os.system("sudo killall gatt-server")
os.system("sudo hciconfig hci0 down")
def up(m):
print("Starting up BLEE")
os.system("sudo ../bluez/src/bluetoothd -d -n &")
time.sleep(2)
os.system("sudo ./gatt-server &")
time.sleep(2)
os.system("sudo hciconfig hci0 up")
##os.system("../bluez/test/example-gatt-server &")
while True:
#os.system("sudo hciconfig hci0 leadv 0")
time.sleep(5)
def run(m):
m.down()
time.sleep(1)
m.up()b = Ble()b.run()
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
There has been a discussion on the mailing previously that covered some of this.
Is there anything in this thread that helps:
https://marc.info/?t=149208458400001&r=1&w=2
Quoted 99 lines · Pavel Machek
Hi!
I'm trying to get gatt client/server to run; my ultimate goal is to turn Linux machine into "low-energy device", providing services similar to heartbeat measurement.
I do have existing qt application (running on Android and PC) I'd like "device" to talk to.
TODO says:
- Add complete GATT test coverage in unit/test-gatt following the GATT test
spec. This could use shared/gatt-client and shared/gatt-server at
the same
time to test both against each other. We should definitely have
tests for
gatt-server and gatt-client simultaneously on one side of the
connection.Priority: High
Complexity: C4Which tells me that maybe I should consider helping with that. But so far I was not able to get it to work...
I can use gatt-server and connect to it using gatttool, but depending on details during the server start (?) and phase of moon, either device is not enumerated by the QT code, or it is not detected as low-energy device, or no UUIDs are detected.
My attempt at launching server is below (using python gatt-server, (1) ). I was doing "hciconfig leadv 0" manually at some point.
Using hciconfig while bluetoothd is running sounds kind-of dangerous. Stackoverflow (2) suggests using btmgmt (3) instead, and things got slightly different, but did not start to work for me. Is there documentation how to get this to work somewhere?
Thanks and best regards,
Pavel(3)
sudotools/btmgmt-i hci0 power off
sudotools/btmgmt-i hci0 le on
sudotools/btmgmt-i hci0 connectable on sudotools/btmgmt-i hci0 name "some friendly name" sudotools/btmgmt-i hci0 advertising on sudotools/btmgmt-i hci0 power ontools/btgatt-server-i hci0 -s low -t public -r -v(1)
#!/usr/bin/python3
# -*- python -*-import os
import re
import timedef pcmd(c):
return os.popen(c).readline()[:-1]class Ble:
def down(m): print("Shutting down BLEE") os.system("sudo killall bluetoohd") os.system("sudo killall gatt-server") os.system("sudo hciconfig hci0 down") def up(m): print("Starting up BLEE") os.system("sudo ../bluez/src/bluetoothd -d -n &") time.sleep(2) os.system("sudo ./gatt-server &") time.sleep(2) os.system("sudo hciconfig hci0 up") ##os.system("../bluez/test/example-gatt-server &") while True: #os.system("sudo hciconfig hci0 leadv 0") time.sleep(5) def run(m): m.down() time.sleep(1) m.up()b =
Ble()b.run()Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Luiz Augusto von Dentz
maintainerHi Barry, Pavel,
Quoted 33 lines · Barry Byford
There has been a discussion on the mailing previously that covered some of this.
Is there anything in this thread that helps:
https://marc.info/?t=149208458400001&r=1&w=2Quoted 26 lines · Pavel Machek
Hi!
I'm trying to get gatt client/server to run; my ultimate goal is to turn Linux machine into "low-energy device", providing services similar to heartbeat measurement.
I do have existing qt application (running on Android and PC) I'd like "device" to talk to.
TODO says:
- Add complete GATT test coverage in unit/test-gatt following the GATT test
spec. This could use shared/gatt-client and shared/gatt-server at
the same
time to test both against each other. We should definitely have
tests for
gatt-server and gatt-client simultaneously on one side of the
connection.Priority: High
Complexity: C4Which tells me that maybe I should consider helping with that. But so far I was not able to get it to work...
This is unit testing with a socket pair, so I don't think it has anything to do with what follows bellow.
Quoted 5 lines
Quoted 5 lines
I can use gatt-server and connect to it using gatttool, but depending on details during the server start (?) and phase of moon, either device is not enumerated by the QT code, or it is not detected as low-energy device, or no UUIDs are detected.
Quoted 7 lines
Quoted 7 lines
My attempt at launching server is below (using python gatt-server, (1) ). I was doing "hciconfig leadv 0" manually at some point.
Using hciconfig while bluetoothd is running sounds kind-of dangerous. Stackoverflow (2) suggests using btmgmt (3) instead, and things got slightly different, but did not start to work for me. Is there documentation how to get this to work somewhere?
Have a look at bluetoothctl first, all the necessary commands are there to enable to act as peripheral:
Menu advertise:
Available commands:
-------------------
uuids [uuid1 uuid2 ...] Set/Get advertise uuids service [uuid] [data=xx xx ...] Set/Get advertise service data manufacturer [id] [data=xx xx ...] Set/Get advertise manufacturer data data [type] [data=xx xx ...] Set/Get advertise data discoverable [on/off] Set/Get advertise discoverable discoverable-timeout [seconds] Set/Get advertise
discoverable timeout
tx-power [on/off] Show/Enable/Disable
TX power to be advertised
name [on/off/name] Configure local name
to be advertised
appearance [on/off/value] Configure custom
appearance to be advertised
duration [seconds] Set/Get advertise duration
timeout [seconds] Set/Get advertise timeout
clear [uuids/service/manufacturer/config-name...] Clear advertise config
GATT Services can be registered with:
Menu gatt:
Available commands:
-------------------
list-attributes [dev] List attributes select-attribute <attribute/UUID> Select attribute attribute-info [attribute/UUID] Select attribute read [offset] Read attribute value write <data=xx xx ...> [offset] Write attribute value acquire-write Acquire Write file descriptor release-write Release Write file descriptor acquire-notify Acquire Notify file descriptor release-notify Release Notify file descriptor notify <on/off> Notify attribute value register-application [UUID ...] Register profile to connect unregister-application Unregister profile register-service <UUID> Register application service. unregister-service <UUID/object> Unregister application service register-includes <UUID> Register as Included
service in.
unregister-includes <Service-UUID><Inc-UUID> Unregister Included service.
register-characteristic <UUID> <Flags=read,write,notify...> Register application characteristic
unregister-characteristic <UUID/object> Unregister
application characteristic
register-descriptor <UUID> <Flags=read,write...> Register application descriptor
unregister-descriptor <UUID/object> Unregister
application descriptor
Quoted 11 lines
Quoted 11 lines
Thanks and best regards,
Pavel(3)
sudotools/btmgmt-i hci0 power off
sudotools/btmgmt-i hci0 le on
sudotools/btmgmt-i hci0 connectable on sudotools/btmgmt-i hci0 name "some friendly name" sudotools/btmgmt-i hci0 advertising on sudotools/btmgmt-i hci0 power ontools/btgatt-server-i hci0 -s low -t public -r -v
No need to use btmgmt, applications should use the D-Bus API which has pretty much everything you are doing with btmgmt.
Quoted 21 lines
Quoted 21 lines
(1)
#!/usr/bin/python3
# -*- python -*-import os
import re
import timedef pcmd(c):
return os.popen(c).readline()[:-1]class Ble:
def down(m):
print("Shutting down BLEE")
os.system("sudo killall bluetoohd")
os.system("sudo killall gatt-server")
os.system("sudo hciconfig hci0 down")
Quoted 5 lines
Quoted 5 lines
def up(m): print("Starting up BLEE") os.system("sudo ../bluez/src/bluetoothd -d -n &") time.sleep(2) os.system("sudo ./gatt-server &")
bluetoothd is already acting as a GATT server.
Quoted 5 lines
Quoted 5 lines
time.sleep(2)
os.system("sudo hciconfig hci0 up")##os.system("../bluez/test/example-gatt-server &") while True:
#os.system("sudo hciconfig hci0 leadv 0")
You may want to use example-advertisement instead of calling hciconfig.
Quoted 16 lines
Quoted 16 lines
time.sleep(5) def run(m): m.down() time.sleep(1) m.up()b =
Ble()b.run()Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Signature · 1 line
Luiz Augusto von Dentz
Hi!
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
dangerous. Stackoverflow (2) suggests using btmgmt (3) instead, and things got slightly different, but did not start to work for me. Is there documentation how to get this to work somewhere?
Have a look at bluetoothctl first, all the necessary commands are there to enable to act as peripheral:
Thanks for the pointer. How are you getting the help? It looks to me like machine is having fun with me:
[bluetooth]# help advertise
Too many arguments
[bluetooth]# advertise
Missing on/off/type argument
[bluetooth]# advertise help
Invalid argument help
Aha. "menu advertise" is the magic command.
Is this expected?
[bluetooth]# uuids advertise on
[bluetooth]#
Aha, thanks for hints. This looks like missing piece of puzzle... and yes, communication seems to work now.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi!
Quoted 10 lines
Quoted 7 lines
Quoted 7 lines
My attempt at launching server is below (using python gatt-server, (1) ). I was doing "hciconfig leadv 0" manually at some point.
Using hciconfig while bluetoothd is running sounds kind-of dangerous. Stackoverflow (2) suggests using btmgmt (3) instead, and things got slightly different, but did not start to work for me. Is there documentation how to get this to work somewhere?
Have a look at bluetoothctl first, all the necessary commands are there to enable to act as peripheral:
And indeed it does, and it does work when done this way.
Quoted 11 lines
Quoted 8 lines
Quoted 8 lines
(3)
sudotools/btmgmt-i hci0 power off
sudotools/btmgmt-i hci0 le on
sudotools/btmgmt-i hci0 connectable on sudotools/btmgmt-i hci0 name "some friendly name" sudotools/btmgmt-i hci0 advertising on sudotools/btmgmt-i hci0 power ontools/btgatt-server-i hci0 -s low -t public -r -vNo need to use btmgmt, applications should use the D-Bus API which has pretty much everything you are doing with btmgmt.
Yes, that works, thanks.
As far as I understand, with bluetoothd running, neither btmgmt nor hciconfig should be used. Unfortunately they are easy to find and "seem" to work.
[bluetooth]# agent KeyboardDisplay
Agent is already registered
[bluetooth]# info FC:CE:56:3B:D1:6C
Device FC:CE:56:3B:D1:6C not available
[NEW] Device FC:CE:56:3B:D1:6C FC-CE-56-3B-D1-6C
[FC-CE-56-3B-D1-6C]# info FC:CE:56:3B:D1:6C
Device FC:CE:56:3B:D1:6C (random)
Alias: FC-CE-56-3B-D1-6C Paired: no Trusted: no Blocked: no Connected: yes LegacyPairing: no
[FC-CE-56-3B-D1-6C]# pair FC:CE:56:3B:D1:6C Attempting to pair with FC:CE:56:3B:D1:6C Request passkey
[agent] Enter passkey (number in 0-999999): 000000 [FC-CE-56-3B-D1-6C]# info FC:CE:56:3B:D1:6C Device FC:CE:56:3B:D1:6C (random)
Alias: FC-CE-56-3B-D1-6C Paired: no Trusted: no Blocked: no Connected: yes LegacyPairing: no
[FC-CE-56-3B-D1-6C]# pair FC:CE:56:3B:D1:6C
If I retry the pairing, nothing happens:
[FC-CE-56-3B-D1-6C]# pair FC:CE:56:3B:D1:6C
Attempting to pair with FC:CE:56:3B:D1:6C
If I retry, it is busy:
[FC-CE-56-3B-D1-6C]# pair FC:CE:56:3B:D1:6C Attempting to pair with FC:CE:56:3B:D1:6C Failed to pair: org.bluez.Error.InProgress Failed to pair: org.freedesktop.DBus.Error.NoReply Failed to pair: org.freedesktop.DBus.Error.NoReply
I tried power cycling the device, re-connect and re-pair.
[CHG] Device FC:CE:56:3B:D1:6C Connected: no
[bluetooth]#
[CHG] Device FC:CE:56:3B:D1:6C Connected: no
[CHG] Device FC:CE:56:3B:D1:6C Connected: yes
[FC-CE-56-3B-D1-6C]# pair FC:CE:56:3B:D1:6C
Attempting to pair with FC:CE:56:3B:D1:6C
[FC-CE-56-3B-D1-6C]# info FC:CE:56:3B:D1:6C
Device FC:CE:56:3B:D1:6C (random)
Alias: FC-CE-56-3B-D1-6C Paired: no Trusted: no Blocked: no Connected: yes LegacyPairing: no
[FC-CE-56-3B-D1-6C]# pair FC:CE:56:3B:D1:6C
Attempting to pair with FC:CE:56:3B:D1:6C
Failed to pair: org.bluez.Error.InProgress
[FC-CE-56-3B-D1-6C]#
Which does not work :-(.
Best regards,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi!
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Using hciconfig while bluetoothd is running sounds kind-of dangerous. Stackoverflow (2) suggests using btmgmt (3) instead, and things got slightly different, but did not start to work for me. Is there documentation how to get this to work somewhere?
Have a look at bluetoothctl first, all the necessary commands are there to enable to act as peripheral:
First, thanks a lot. With bluetoothctl, it indeed works.
Quoted 11 lines
Quoted 8 lines
Quoted 8 lines
(3)
sudotools/btmgmt-i hci0 power off
sudotools/btmgmt-i hci0 le on
sudotools/btmgmt-i hci0 connectable on sudotools/btmgmt-i hci0 name "some friendly name" sudotools/btmgmt-i hci0 advertising on sudotools/btmgmt-i hci0 power ontools/btgatt-server-i hci0 -s low -t public -r -vNo need to use btmgmt, applications should use the D-Bus API which has pretty much everything you are doing with btmgmt.
Pretty much, yes.
There's one piece I'm missing. I need to use "random address", because that's what other side of link wants to talk to. "privacy on" from btmgmt does randomize address (and sets the right bit). I have not found equivalent in bluetoothctl.
Plus... I'd really like to use "random, but fixed for given machine" address, as this is device other side is expected to pair with.
Ideas woudl be welcome.
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
def up(m): print("Starting up BLEE") os.system("sudo ../bluez/src/bluetoothd -d -n &") time.sleep(2) os.system("sudo ./gatt-server &")bluetoothd is already acting as a GATT server.
I may have misnamed the component, but something needs to tell which attributes to implement to bluetoothd.
Thanks,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi!
Quoted 4 lines
There has been a discussion on the mailing previously that covered some of this.
Is there anything in this thread that helps:
https://marc.info/?t=149208458400001&r=1&w=2
Thanks for the pointer; it indeed tells me how it is suppossed to work. (It does not, but now I understand that advertising is quite separate from the gatt protocol).
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html