Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

I need Help (lots of it!) with BLE
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

I need Help (lots of it!) with BLE

by dougconran on Sun Jul 26, 2020 5:15 pm

I'm really struggling to get a handle on BLE. I think that I now have a sketchy understanding of the core functionality and I've looked at and tried the examples but I'm struggling to relate those to what I want to do.

My initial goal is to emulate a bluetooth (BLE) OBD2 dongle so that I can then develop an OBD2 reader without having to fire up the car the whole time. Using nRF Connect I can get the service and characteristic UUIDs of the dongle and see that it offers READ, WRITE, NOTIFY & INDICATE. What I now need to do is to write a Circuitpython program that will advertise itself as offering these features (and then be read and written from/to). The closest example I can come up with is the ble_demo_periph.py code but this advertises itself as accepting a UARTService. I'm not entirely certain what that is but from the reading I've done I think that it is a specific protocol used between Nordic devices and, as far as I can tell (again, using nRF Connect) the OBD2 dongle doesn't offer that. I think that the connect magic occurs in ProvideServicesAdvertisement but I can't work out how to invoke that magic.

The emulator I'm trying to develop needs to offer at least one service (I have a UUID for that) plus at least one characteristic (again I have a UUID for that) offering at least READ & WRITE.

How do I code a server to offer those services/characteristics (or where can I read up on how to do that)?

Many thanks for any help offered.

dougconran
 
Posts: 23
Joined: Wed Nov 08, 2017 8:25 am

Re: I need Help (lots of it!) with BLE

by tannewt on Mon Jul 27, 2020 4:41 pm

Hi Doug,
It's a bit of a trick because it is declarative API.

Here is where UARTService is defined: https://github.com/adafruit/Adafruit_Ci ... py#L39-L62

It contains the uuids for the specific things. Do you have a link to the BLE OBD2 ble service spec? I'm curious what exactly the characteristic is. Hopefully, once I know more I can point to you a more similar service we already support.

The ProvideServicesAdvertisement is used to advertise the device. The other device will initiate the connection and it'll appear in the connections list. This is know as the "peripheral" role. Here is the example code for UARTService: https://github.com/adafruit/Adafruit_Ci ... ho_test.py

For help with a faster turn around join our Discord server: https://adafru.it/discord

tannewt
 
Posts: 1716
Joined: Thu Oct 06, 2016 8:48 pm

Re: I need Help (lots of it!) with BLE

by dougconran on Mon Jul 27, 2020 4:57 pm

Hi,

Thanks once more for a quick reply. The best I can do at the moment is to attach a screen scrape of the nRF Connect screen for the dongle. I hope that might help a bit.
Attachments
Screenshot_20200722-182925_nRF Connect.jpg
Screenshot_20200722-182925_nRF Connect.jpg (393.49 KiB) Viewed 19 times

dougconran
 
Posts: 23
Joined: Wed Nov 08, 2017 8:25 am

Re: I need Help (lots of it!) with BLE

by tannewt on Tue Jul 28, 2020 1:54 pm

Ok, this will be a lot of work if the BLE API isn't documented. You'll likely want to mimic the UARTService if the protocol delimits packets itself. If not, you'll want to use PacketBuffer to buffer. (See MIDI for an example of PacketBuffer.)

Here is a bit of a clue: https://stackoverflow.com/questions/425 ... peripheral

BLE UUIDs are pretty easy to google. :-)

tannewt
 
Posts: 1716
Joined: Thu Oct 06, 2016 8:48 pm

Re: I need Help (lots of it!) with BLE

by dougconran on Thu Jul 30, 2020 2:13 pm

Hi. There are no OBD2 BLE UUIDs that I can find and precious little documentation (that doesn't cost an arm and a leg) so I think that it is going to take a fair amount of trial,error and experimenting. But, thanks for the pointers.

dougconran
 
Posts: 23
Joined: Wed Nov 08, 2017 8:25 am

Please be positive and constructive with your questions and comments.