BLE char limited to 20 bytes on STM32 NUCLEO-WB55 ?

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
Yannick
Posts: 4
Joined: Mon Mar 15, 2021 5:51 pm

BLE char limited to 20 bytes on STM32 NUCLEO-WB55 ?

Post by Yannick » Tue Jul 26, 2022 3:10 pm

Hello

This post is an update of the one I did almost a year ago (viewtopic.php?f=2&t=10465), with no solution found up to now.
I am facing exactly this issue, an trying to apply this solution :

Characteristics and descriptors have a default maximum size of 20 bytes. Anything written to them by a client will be truncated to this length. However, any local write will increase the maximum size, so if you want to allow larger writes from a client to a given characteristic, use gatts_write after registration. e.g. gatts_write(char_handle, bytes(100)).
(from https://docs.micropython.org/en/latest/ ... tooth.html, "GATT Server" section)

My BLE peripheral (not completely reproduced) code is looking like this :

Code: Select all


...

# Maximum number of bytes that can be exchanged
_MAX_NB_BYTES = const(128)

class BLEperipheral:

	# Initializations
	def __init__(self, ble, name="mpy-uart", charbuf=_MAX_NB_BYTES):
		self._ble = ble
		self._ble.active(True)
		self._ble.irq(self._irq)
		# Registration of the service
		((self._tx_handle, self._rx_handle),) = self._ble.gatts_register_services((_UART_SERVICE,))

		# Extending chars buffers to 100 bytes
        	self._ble.gatts_write(self._tx_handle, bytes(charbuf))
		self._ble.gatts_write(self._rx_handle, bytes(charbuf))
		
		self._connections = set()
		self._rx_buffer = bytearray()
		self._handler = None
		# Advertising of the service (services=[_UART_UUID] is required for the exchange to identify the service)
		self._payload = advertising_payload(name=name, services=[_UART_UUID])
		self._advertise()

...


Despites I added the required instruction, when my Central script is writing inside RX characteristic using gattc_write it's message remains truncated to 20 bytes on Peripheral side !

It seems limitation is on gattc_write (Central client side) which is not able to write more than 20 bytes, not on the setup of the characteristic served by the Peripheral.

Maybe I am facing a limitation of BLE implementation on my NUCLEO WB55 board ?

If anybody has an idea ...

Best regards

Yannick

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

Re: BLE char limited to 20 bytes on STM32 NUCLEO-WB55 ?

Post by jimmo » Wed Aug 17, 2022 12:11 pm

Yannick wrote:
Tue Jul 26, 2022 3:10 pm
It seems limitation is on gattc_write (Central client side) which is not able to write more than 20 bytes, not on the setup of the characteristic served by the Peripheral.
You also need to do an MTU exchange. See https://docs.micropython.org/en/latest/ ... change_mtu

Post Reply