Baffled by Bluetooth - Help

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
User avatar
russ_h
Posts: 88
Joined: Thu Oct 03, 2019 2:26 am
Contact:

Re: Baffled by Bluetooth - Help

Post by russ_h » Mon Jul 19, 2021 12:02 am

Here is a firmware.bin file for the T-Display with MicroPython v1.16-107-g9f71a11d3 and the st7789 driver compiled with esp-idf42.

Russ
Last edited by russ_h on Tue Jul 20, 2021 8:01 pm, edited 1 time in total.

dougconran
Posts: 27
Joined: Sat Jul 03, 2021 5:10 pm

Re: Baffled by Bluetooth - Help

Post by dougconran » Mon Jul 19, 2021 7:14 am

russ_h wrote:
Mon Jul 19, 2021 12:02 am
Here is a firmware.bin file for the T-Display with MicroPython v1.16-107-g9f71a11d3 and the st7789 driver compiled with esp-idf42.

Russ
That's awesome! Many thanks.

dougconran
Posts: 27
Joined: Sat Jul 03, 2021 5:10 pm

Re: Baffled by Bluetooth - Help

Post by dougconran » Tue Jul 20, 2021 11:18 am

I'm wondering whether the lack of data coming back is something to do with notifications having to be enabled. This is the nrfConnect Mobile log:

Code: Select all

Unknown Service (0000ffe0-0000-1000-8000-00805f9b34fb)
- Unknown Characteristic [N R W] (0000ffe1-0000-1000-8000-00805f9b34fb)
   Client Characteristic Configuration (0x2902)
   Characteristic User Description (0x2901)
- Unknown Characteristic [R W] (0000ffee-0000-1000-8000-00805f9b34fb)
   Characteristic User Description (0x2901)
   Unknown Descriptor (fe3cf737-79ed-f667-fdff-bfd4eeb3b7ff)
   Unknown Descriptor (fe3cf737-79ed-f667-fdff-bfd4eeb3b7ff)
   Unknown Descriptor (fe3cf737-79ed-f667-fdff-bfd4eeb3b7ff)
   Unknown Descriptor (fe3cf737-79ed-f667-fdff-bfd4eeb3b7ff)
   Unknown Descriptor (fe3cf737-79ed-f667-fdff-bfd4eeb3b7ff)
   Unknown Descriptor (fe3cf737-79ed-f667-fdff-bfd4eeb3b7ff)
   Unknown Descriptor (fe3cf737-79ed-f667-fdff-bfd4eeb3b7ff)
   Unknown Descriptor (fe3cf737-79ed-f667-fdff-bfd4eeb3b7ff)
   Unknown Descriptor (fe3cf737-79ed-f667-fdff-bfd4eeb3b7ff)
D	17:38:45.456	gatt.setCharacteristicNotification(00002a05-0000-1000-8000-00805f9b34fb, true)
D	17:38:45.459	gatt.setCharacteristicNotification(0000ffe1-0000-1000-8000-00805f9b34fb, true)
I	17:38:45.474	Connection parameters updated (interval: 45.0ms, latency: 0, timeout: 5000ms)
V	17:38:59.284	Writing request to characteristic 0000ffe1-0000-1000-8000-00805f9b34fb
D	17:38:59.284	gatt.writeCharacteristic(0000ffe1-0000-1000-8000-00805f9b34fb, value=0x41545A0D)
I	17:38:59.425	Data written to 0000ffe1-0000-1000-8000-00805f9b34fb, value: (0x) 41-54-5A-0D
which seems to point to nrfConnect doing that.

If that is the case then I don't understand why my ESP32 emulator (based on ble_simple_peripheral.py) doesn't require notifications to be explicitly enabled :?

zedman9991
Posts: 1
Joined: Sat Jul 06, 2019 3:10 am

Re: Baffled by Bluetooth - Help

Post by zedman9991 » Tue Jul 20, 2021 7:48 pm

I note link with firmware is no longer valid. I compiling and deploying for a TTGO T-Display per your GitHub directions but but see no graphics. I would love to try your precompile.

User avatar
russ_h
Posts: 88
Joined: Thu Oct 03, 2019 2:26 am
Contact:

Re: Baffled by Bluetooth - Help

Post by russ_h » Tue Jul 20, 2021 8:02 pm

I'm not sure how that happened but the link is live again: https://penfold.owt.com/tdisplay/v1.16- ... rmware.bin

dougconran
Posts: 27
Joined: Sat Jul 03, 2021 5:10 pm

Re: Baffled by Bluetooth - Help

Post by dougconran » Tue Jul 20, 2021 9:23 pm

russ_h wrote:
Mon Jul 19, 2021 12:02 am
Here is a firmware.bin file for the T-Display with MicroPython v1.16-107-g9f71a11d3 and the st7789 driver compiled with esp-idf42.

Russ
russ_h wrote:
Tue Jul 20, 2021 8:02 pm
I'm not sure how that happened but the link is live again: https://penfold.owt.com/tdisplay/v1.16- ... rmware.bin
A bit cheeky, I know, but is there any chance you could upgrade your M5 Core 2 firmware as well? 8-)

User avatar
russ_h
Posts: 88
Joined: Thu Oct 03, 2019 2:26 am
Contact:

Re: Baffled by Bluetooth - Help

Post by russ_h » Wed Jul 21, 2021 2:21 am

dougconran wrote:
Tue Jul 20, 2021 9:23 pm
A bit cheeky, I know, but is there any chance you could upgrade your M5 Core 2 firmware as well? 8-)
No problem, just updated the firmware files in the repo to v1.16.

dougconran
Posts: 27
Joined: Sat Jul 03, 2021 5:10 pm

Re: Baffled by Bluetooth - Help

Post by dougconran » Wed Jul 21, 2021 5:23 pm

russ_h wrote:
Wed Jul 21, 2021 2:21 am
dougconran wrote:
Tue Jul 20, 2021 9:23 pm
A bit cheeky, I know, but is there any chance you could upgrade your M5 Core 2 firmware as well? 8-)
No problem, just updated the firmware files in the repo to v1.16.
That is truly fantastic, thank you so much. It means that I can try out @Jimmo's aioble stuff on the larger screen. I'm really grateful, thanks - Doug

dougconran
Posts: 27
Joined: Sat Jul 03, 2021 5:10 pm

Re: Baffled by Bluetooth - Help

Post by dougconran » Thu Jul 22, 2021 6:17 pm

Sadly, I think that I'm going to have to admit defeat on this and revert to Arduino :cry:

I have added code (I think) to enable notifications

Code: Select all

        elif event == _IRQ_GATTC_CHARACTERISTIC_DONE:
            # Characteristic query complete.
            if self._tx_handle is not None and self._rx_handle is not None:
                # We've finished connecting and discovering device, fire the connect callback.
                self._ble.gattc_discover_descriptors(
                    self._conn_handle, self._start_handle, self._end_handle
                )
                
                if self._conn_callback:
                    self._conn_callback()
            else:
                print("Failed to find uart rx characteristic.")
                
        elif event == _IRQ_GATTC_DESCRIPTOR_RESULT:
            # Called for each descriptor found by gattc_discover_descriptors().
            conn_handle, dsc_handle, uuid = data
            if _UART_CCCD_UUID == uuid:                #   _UART_CCCD_UUID = 0x2902
                print("Descr details : ",data)
                self._ble.gattc_write(self._conn_handle, dsc_handle, b'\x01\x00',1)

            
        elif event == _IRQ_GATTC_DESCRIPTOR_DONE:
            # Called once service discovery is complete.
            # Note: Status will be zero on success, implementation-specific value otherwise.
            conn_handle, status = data
            print("descr sts : ",data)
this returns

Code: Select all

Service done :  35
characteristic :  UUID(0xffe1)  - props :  26
characteristic :  UUID(0xffee)  - props :  10
Connected
Descr details :  (0, 38, UUID(0x2902))
TX complete (0, 38, 0)
descr sts :  (0, 0)
However, I still get nothing back from the OBDII reader.

One further issue that I have is that whilst both 16 bit and 128 bit service uuids are recognised I get a 'Failed to find uart service.' error message if I use 128 bit uuids for the characteristics. I suspect that this is the root of the problem and that neither 16 bit nor 128 bit uuids are being recognised.

This is all very frustrating because MP ESP32 to MP ESP32 works fine and nrfConnect Mobile to OBDII works fine, it is just MP ESP32 to OBDII (and my lack of knowledge ;) ) that seems to be the problem.

dougconran
Posts: 27
Joined: Sat Jul 03, 2021 5:10 pm

Re: Baffled by Bluetooth - Help

Post by dougconran » Wed Sep 08, 2021 8:33 pm

After a lot of trial and error using both aioble and basic ubluetooth I have had sufficient success for my purposes.

The main problem I experienced (and still experience to an extent) is the processing of multiple notifications. Fundamentally, aioble is not fast enough and basic ble is - just. One particular OBD command gets 9 14 byte notifications returned at a speed that Android/iOS can handle but MP on an ESP32 struggles with. However I found that as long as the notification callback did nothing more than just add the returned data to a bytearray for processing once all notifications had been received (assumed after a set period of time) this was reasonably foolproof and, where there were dropped notifications, it was possible, because of the format of the data, to cover this.

As far as the problems I was having with characteristics, this was easily dealt with by just ignoring them and searching for name instead.

In conclusion I would say that aioble makes life a lot easier but at the cost (I think) of additional processing which may adversely affect the robustness of the app being developed.

Post Reply