BLE Questions regarding GATT and reading data

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
avela011
 
Posts: 3
Joined: Mon May 09, 2022 8:20 pm

BLE Questions regarding GATT and reading data

Post by avela011 »

Hey folks. I am semi-new to this whole embedded systems thing but I'm attempting to read packets from a Bluetooth Device over GATT.

Code: Select all

def scan():
    ble = BLERadio()
    print("scanning")
    found = set()
    scan_responses = set()
    # By providing Advertisement as well we include everything, not just specific advertisements.
    for advertisement in ble.start_scan(ProvideServicesAdvertisement, Advertisement):
        addr = advertisement.address
        if advertisement.scan_response and addr not in scan_responses:
            scan_responses.add(addr)
        elif not advertisement.scan_response and addr not in found:
            found.add(addr)
        else:
            continue
        if ("GotWay" in str(advertisement.complete_name)):
            print(advertisement.complete_name)
            print()
            connection = ble._adapter.connect(addr, timeout=10 )
            print(connection)
            
            for service in connection.discover_remote_services(service_uuids_whitelist=None):
                    print(service)

                    for char in service.characteristics:
                        print(char.READ)
Here is what I have so far to try and read some data from the device. However, what I'm getting back is this:
code.py output:
scanning
GotWay_55575

<Connection>
Service(UUID(0x1800))
8
8
8
8
8
Service(UUID(0x1801))
8
Service(UUID(0x180a))
8
8
8
8
8
8
8
8
8
Service(UUID(0xffe0))
8


Any help would be appreciated to move forward. I'm just not sure why I'm receiving a bunch of 8s and nothing else as I'm having trouble finding any examples/documentation to help guide me in this process.

User avatar
tannewt
 
Posts: 3314
Joined: Thu Oct 06, 2016 8:48 pm

Re: BLE Questions regarding GATT and reading data

Post by tannewt »

I think the 8s are the char.READ constant.

What device are you connecting to? Generally you'll need to define a Service class for the particular service you want to connect to.

User avatar
avela011
 
Posts: 3
Joined: Mon May 09, 2022 8:20 pm

Re: BLE Questions regarding GATT and reading data

Post by avela011 »

Hey tannewt. Thanks for the reply:
Essentially I am trying to read the basic data sent out from an Electric Unicycle. Unfortunately there are no data sheets for such a device, but the only thing I've found publicly available that does it is this repo here: https://github.com/freestyl3r/euc-dash/ ... /begode.js

However I am trying to figure out how to make sense of the js and translate it to what I'm attempting to do in Circuit Python via the Feather.

User avatar
tannewt
 
Posts: 3314
Joined: Thu Oct 06, 2016 8:48 pm

Re: BLE Questions regarding GATT and reading data

Post by tannewt »

CircuitPython is more declarative with its BLE API. So you'll need to create a service class with one characteristic where the UUIDs match: https://github.com/freestyl3r/euc-dash/ ... #L97-L100=

It looks like it then replies with packets of different types.

This is very similar to MIDI so that may be a good place to start: https://github.com/adafruit/Adafruit_Ci ... le_midi.py

User avatar
avela011
 
Posts: 3
Joined: Mon May 09, 2022 8:20 pm

Re: BLE Questions regarding GATT and reading data

Post by avela011 »

Alright, thats starting to make more sense. Appreciate it!
I'll follow the lead and see where it gets me

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”