Page 1 of 1

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

Posted: Tue Jul 26, 2022 3:10 pm
by Yannick
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

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

Posted: Wed Aug 17, 2022 12:11 pm
by jimmo
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