BLE, GATT and having it auto-reconnect. Possible ?

Hello all,
I've got a small BLE device (an iTag) which I'm able to communicate with
using a GATT class I found here:
formatting link

It works fine, but for one thing: Whenever I get outof range (which is
rather easy to do) I have to re-run the python program to reconnect.
Question: Is there a setting somewhere that causes my my RPi's BLE to
automatically reconnect to the device when it comes in range again ?
Remark:
I can either wrap a never-ending loop around the whole program and perhaps
add some code that will go into discovery mode until the devices
advertisdement is receieved again, but as the need for reconnection isn't
something that seldom happens (especially not with short-ranged BLE devices)
I could imagine its already build into the BLE stack. But if so, where/how
to enable it ...
Regards,
Rudy Wieser
Reply to
R.Wieser
Loading thread data ...
It is SDK and it shows you the way to write the code you need in following sections
Discovering nearby Bluetooth Low Energy devices Connecting to a Bluetooth Low Energy device and ...
So you better write a small python program that fits your needs
if you were using section "Running the GATT control script", it clearly states
So I assume this "GATT control script" can be used as a starting point
Also have a look at the dbus API
formatting link
Reply to
Deloptes
Deloptes,
I've been googeling for a couple of hours to find stuff related to the RPi's BLE, but have not found anything like that. Could you provide a link to that SDK ?
Nothing like that. I took that Github code that I mentioned and just altered it a bit, using the included example scripts as well as the main gatt_linux one as a lead. Going thru those scripts I did not see any auto-reconnection possibility. Hence my question.
Regards, Rudy Wieser
Reply to
R.Wieser
The link you pasted is a link to SDK getsenic/gatt-python: Bluetooth GATT SDK for Python - GitHub
I assume (because I have no time or need at the moment to look into the detail) the SDK offers implementation of the GATT API. In the examples you have the code for discovery and also the code to connect and read values etc. It looks like you have to put the puzzle in the right way, no?
From my experience with dbus and bluez5, you would register a listener that will reconnect as soon as the device appears, but I am unfortunately neither GATT nor python expert. I have done some work on synchronization and audio. Though if you look at the GATT API spec under GATT Manager hierarchy, you would note
"To make service registration simple, BlueZ requires that all objects that belong to a GATT service be grouped under a D-Bus Object Manager that solely manages the objects of that service."[1] Check also the ObjectManager API [2].
And also under GATT Profile hierarchy
"Local profile (GATT client) instance. By registering this type of object an application effectively indicates support for a specific GATT profile and requests automatic connections to be established to devices supporting it." [1]
For me this one looks promising. Perhaps you need to register this type of object and the magic will work. I'm telling you (jokingly) BT is magic. After spending few weeks may be 7y ago and was probably more frustrated than you are ATM, I laughed for an hour or so after reading this blog article. (it was written in the time of bluez4 I think) [3]. I must admit now the bluez5 is a blessing to work with, so take it from the positive side.
I hope it helps
[1]
formatting link
[2]
formatting link
[3]
formatting link
Reply to
Deloptes
Deloptes,
Whoops. For some reason I assumed that an SDK is something bulky, much bigger than that. At least, the last time I downloaded an SDK it was hundreds of MBs.
Yep. Which is what my post is all about. I can go make a number of assumptions and hit my shins on every rock on the road, or I could check if anyone already knows - which looked like a good idea to me. :-)
Knowing that it most likely exists makes my job a /lot/ easier.
I've seen some talk about profiles, but nothing (code) specific (what it is for, looks like and/or how to handle it). It certainly gives me something to throw into Google and see what it comes up with.
And thanks for the links. Both the D-Bus spec as well as that "best kept secret" one. :-)
Regards, Rudy Wieser
Reply to
R.Wieser
That will have been a Windows SDK.
On Linux there is no reason for a shared library, a few header files and some documentation to be that big.
---druck
Reply to
druck
Druck,
Indeed. And ofcourse packaged into a "must install" file (.EXE IIRC), which made it cumbersome to get at the included documentation (which was all I needed at that time).
Regards, Rudy Wieser
Reply to
R.Wieser
Apart from the other comments I focus on this one. As mentioned I am not an expert in GATT, but it tells me that your device can match the offered profile and auto connect to it.
For the sync or audio services I use the defined UUIDs. When they are registered properly the other part knows that the device supports them and magic works.
You did not mention or I missed what your device is, but you could look for specification of the service and the profile expected.
In any way when the device is connected you could find out on the dbus what are the specifics.
Another option is this here:
formatting link
Find out if something listed matches.
regards
Reply to
Deloptes
Deloptes,
Its a basic pear-shaped "iTag" device. It can be told to "sound the alarm", and it has a single button to ask for attention. It also "sounds the alarm" when it loses connection.
...
I've displayed all services (just found that the last one is an "Over The Air Download Service"), characteristics and descriptors, but nothing seems to be obviously related to a profile. Doesn't matter though, I just have to google a bit more.
The biggest problem was not having anything to start with. Now I have plenty. :-)
Alas. Although the page displays, clicking any "downloaddoc.ashx" related link times out. Might be related to trying that on an XP machine though.
Thanks for the help. :-)
Regards, Rudy Wieser
Reply to
R.Wieser
XP machine?!
welcome
Reply to
Deloptes
Deloptes,
Short for "Windows XPsp3 machine". Yeah, I know. Old. Good enough for me though. :-)
Oh, before you wonder: That GATT experimenting is on a RPi 3B+.
Regards, Rudy Wieser
Reply to
R.Wieser

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.