BLE buffer problem.

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
prem111
Posts: 127
Joined: Sun Feb 23, 2020 3:18 pm

BLE buffer problem.

Post by prem111 » Sun Jul 19, 2020 5:54 am

Hi, im have problem in buffer gatts_read. With a single data transfer to the BLE buffer, there is no problem, but when it sends 10-20 separate packets, some are cut off.

This is my code:

Code: Select all


self._ble.gatts_set_buffer(self.tele, rx_tele_buf, True)

... ble.py:
        elif event == _IRQ_GATTS_WRITE:
            conn_handle, attr_handle, = data
            if (attr_handle == self.telemetry_val):
                tb = self._ble.gatts_read(attr_handle)
                tele_buf.append(tb)

Code: Select all

... main.py
import ble.py
async def read_ble_buffer_telemetry():

    while True:
        if (len(ble.tele_buf) > 0):
            for b_item in ble.tele_buf:
                print("DATA: "+str(b_item))
                await xbee_uart_send(b_item)
        await uasyncio.sleep_ms(0)

prem111
Posts: 127
Joined: Sun Feb 23, 2020 3:18 pm

Re: BLE buffer problem.

Post by prem111 » Sun Jul 19, 2020 8:14 pm

I see some dependency, everything works fine until I run xbee_uart_send function. When the xbee_uart_send function is executed, when irqm comes, I have gats_read empty (attr_handle)

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: BLE buffer problem.

Post by jimmo » Mon Jul 20, 2020 4:11 am

prem111 wrote:
Sun Jul 19, 2020 8:14 pm
When the xbee_uart_send function is executed
Why does it xbee_uart_send one byte at a time? Could you send the whole buffer in one go?
prem111 wrote:
Sun Jul 19, 2020 5:54 am
but when it sends 10-20 separate packets, some are cut off.
What do you mean by "cut off"? Where do you detect this?

Can you try printing the "tb" when you receive it in the IRQ_GATTS_WRITE to see if it's cut off there? Or is it only when you look at the tele_buf that stuff is missing?

prem111
Posts: 127
Joined: Sun Feb 23, 2020 3:18 pm

Re: BLE buffer problem.

Post by prem111 » Mon Jul 20, 2020 8:49 am

tb it was null... but the problem passed when I changed:
From:

Code: Select all

self._ble.gatts_set_buffer(self.tele, rx_tele_buf, True)
To:

Code: Select all

self._ble.gatts_set_buffer(self.tele, rx_tele_buf, False)
Why could this be happening because of "True"?

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: BLE buffer problem.

Post by jimmo » Mon Jul 20, 2020 9:36 am

is self.telemetry_val the same as self.tele ? Otherwise it's setting the buffering on the wrong handle?

Are you able to share more of the code?

prem111
Posts: 127
Joined: Sun Feb 23, 2020 3:18 pm

Re: BLE buffer problem.

Post by prem111 » Mon Jul 20, 2020 9:39 am

yes self.tele is the same self.telemetry_val. sorry, I rewrote the code wrong earlier. But the problem is the same :)

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: BLE buffer problem.

Post by jimmo » Mon Jul 20, 2020 11:32 am

Ok, can you answer the other questions?

Post Reply