All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: Barry Byford <31baz66@gmail.com>
Cc: Pavel Machek <pavel@ucw.cz>,
	"linux-bluetooth@vger.kernel.org"
	<linux-bluetooth@vger.kernel.org>,
	Marcel Holtmann <marcel@holtmann.org>
Subject: Re: low energy: does gatt client/server work in current version? How to test?
Date: Tue, 2 Oct 2018 11:53:24 +0300	[thread overview]
Message-ID: <CABBYNZ+R5M+gDyFZ6+fuJyXtNbvPiM7bh+BVeYQOn8oP9JJgSQ@mail.gmail.com> (raw)
In-Reply-To: <CAAu3APYAmr9M5NQkvqsG1-J_zn=Jiq4M18NYLx50WAAU3eb93w@mail.gmail.com>

Hi Barry, Pavel,

On Mon, Oct 1, 2018 at 4:53 PM Barry Byford <31baz66@gmail.com> wrote:
>
> 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
>
> On Mon, 1 Oct 2018 at 11:25, Pavel Machek <pavel@ucw.cz> wrote:
> >
> > 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...

This is unit testing with a socket pair, so I don't think it has
anything to do with what follows bellow.

> > 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?

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

> > 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

No need to use btmgmt, applications should use the D-Bus API which has
pretty much everything you are doing with btmgmt.

> > (2)
> > https://stackoverflow.com/questions/29128586/bluetooth-low-energy-in-c-using-bluez-to-create-a-gatt-server#31030321
> >
> > (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 &")

bluetoothd is already acting as a 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")

You may want to use example-advertisement instead of calling hciconfig.

> >             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

  reply	other threads:[~2018-10-02  8:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-01 10:24 low energy: does gatt client/server work in current version? How to test? Pavel Machek
2018-10-01 13:53 ` Barry Byford
2018-10-02  8:53   ` Luiz Augusto von Dentz [this message]
2018-10-02 12:26     ` Pavel Machek
2018-10-05  9:15     ` Pavel Machek
2018-10-14 21:40     ` Pavel Machek
2018-10-02 12:09   ` Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CABBYNZ+R5M+gDyFZ6+fuJyXtNbvPiM7bh+BVeYQOn8oP9JJgSQ@mail.gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=31baz66@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=marcel@holtmann.org \
    --cc=pavel@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.