Re: Serial communication over BT using the DBus API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 9 Oct 2018 at 21:56, Sylvain Leroux <sylvain@xxxxxxxxxxx> wrote:
>
> Hi Barry,
>
> Thanks for the reply:
>
> On 10/09/2018 10:30 PM, Barry Byford wrote:
> > You might want to take a look at the Bluedot library that has used the
> > DBus API to communicate over the Serial Port Profile.
> > Server:
> > https://github.com/martinohanlon/BlueDot/blob/master/bluedot/btcomm.py#L141
> > Client:
> > https://github.com/martinohanlon/BlueDot/blob/master/bluedot/btcomm.py#L466
> >
> > The main section using DBus is in:
> > https://github.com/martinohanlon/BlueDot/blob/master/bluedot/utils.py
>
> I started to explore the bluedot sources. From what I understand, I need
> in the shell something like the `register_spp` function
> (https://github.com/martinohanlon/BlueDot/blob/master/bluedot/utils.py#L101)
>
>
> I'm currently investigating how I could use `busctl` to reproduce that
> behavior.

Not my area of expertise but it seems like it might be difficult
because there would be no event loop.
Hopefully someone else can jump in on that point.

>
> I noticed the function mostly send some XML description to the
> `org.bluez.ProfileManager1` interface (see code below).

The author has decided to do it that way. You don't have to. Here is a
different example:
https://gist.github.com/ukBaz/217875c83c2535d22a16ba38fc8f2a91#file-spp-profile

> There are a
> couple of hard coded constants in the code, including the UUID
> "00001101-0000-1000-8000-00805f9b34fb". Are those "well known" values I
> can blindly use?

That UUID refers to the Serial Port Profile. You can see the full list
of assigned numbers at:
https://www.bluetooth.com/specifications/assigned-numbers/service-discovery


>
>
> - Sylvain
>
>
> ----
> def register_spp(port):
>
>     service_record = """
>     <?xml version="1.0" encoding="UTF-8" ?>
>     <record>
>       <attribute id="0x0001">
>         <sequence>
>           <uuid value="0x1101"/>
>         </sequence>
>       </attribute>
>       <attribute id="0x0004">
>         <sequence>
>           <sequence>
>             <uuid value="0x0100"/>
>           </sequence>
>           <sequence>
>             <uuid value="0x0003"/>
>             <uint8 value="{}" name="channel"/>
>           </sequence>
>         </sequence>
>       </attribute>
>       <attribute id="0x0100">
>         <text value="Serial Port" name="name"/>
>       </attribute>
>     </record>
>     """.format(port)
>
>     bus = dbus.SystemBus()
>
>     manager = dbus.Interface(bus.get_object(SERVICE_NAME, "/org/bluez"),
> PROFILE_MANAGER)
>
>     path = "/bluez"
>     uuid = "00001101-0000-1000-8000-00805f9b34fb"
>     opts = {
> #        "AutoConnect" : True,
>         "ServiceRecord" : service_record
>     }
>
>     try:
>         manager.RegisterProfile(path, uuid, opts)
>     except dbus.exceptions.DBusException as e:
>         #the spp profile has already been registered, ignore
>         if str(e) != "org.bluez.Error.AlreadyExists: Already Exists":
>             raise(e)
> ----



[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux