In the documentation I found the following information:
Characteristics and descriptors have a default maximum size of 20 bytes. Anything written to them by a central 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 central to a given characteristic, use gatts_write after registration. e.g. gatts_write(char_handle, bytes(100)).
However, by using ESP32 I couldn't send a string longer than 20 characters/bytes. I tried several alternatives (refer above). Also I tried someting like:
Code: Select all
s = "This is my little test string, which doesn't seem to be transmitted in full length"
p = str.encode(s)
gatts_write(char_handle, p).
For the moment I ended up with the following function.
Code: Select all
def send(self, d):
self._ble.gatts_set_buffer(self._handle, 1000)
dp = chr(2) + d + chr(3)
p = str.encode(dp)
for x in range(0, len(p), 20):
self._ble.gatts_write(self._handle, p[x:x+20])
for conn_handle in self._connections:
# Notify connected centrals to issue a read.
self._ble.gatts_notify(conn_handle, self._handle)
time.sleep_ms(10)
So, actually it splits the string into chunks of 20 bytes and sending them one by one. Also, I add chr(2) and char(3) as an identifier for the host to recognize start and end of the string...This function reduces the number of transactions and also the number of print outputs, which was my original issue
GATT procedure initiated: notify; att_handle=13
However, it would be great to turn them off.....