Page 1 of 1

BLE buffer problem.

Posted: Sun Jul 19, 2020 5:54 am
by prem111
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)

Re: BLE buffer problem.

Posted: Sun Jul 19, 2020 8:14 pm
by prem111
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)

Re: BLE buffer problem.

Posted: Mon Jul 20, 2020 4:11 am
by jimmo
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?

Re: BLE buffer problem.

Posted: Mon Jul 20, 2020 8:49 am
by prem111
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"?

Re: BLE buffer problem.

Posted: Mon Jul 20, 2020 9:36 am
by jimmo
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?

Re: BLE buffer problem.

Posted: Mon Jul 20, 2020 9:39 am
by prem111
yes self.tele is the same self.telemetry_val. sorry, I rewrote the code wrong earlier. But the problem is the same :)

Re: BLE buffer problem.

Posted: Mon Jul 20, 2020 11:32 am
by jimmo
Ok, can you answer the other questions?