Overview: number of bytes sent by ble_app_blinky at notification is determined by (note my changes for debug:
/* add_char_params.init_len = NRF_SDH_BLE_GATT_MAX_MTU_SIZE; add_char_params.max_len = NRF_SDH_BLE_GATT_MAX_MTU_SIZE; add_char_params.init_len = sizeof(uint8_t); add_char_params.max_len = sizeof(uint8_t); */ add_char_params.init_len = 4; add_char_params.max_len = 4;
in ble_lbs_init() of ble_lbs.c and not by:
params.p_data = test_data; uint16_t len = sizeof(test_data); params.p_len = &len;
in ble_lbs_on_button_change() as it should be. In addition, peeking at the size using:
errcode = sd_ble_evt_get(NULL, &len2); SEGGER_RTT_printf(0, "Peeked length %u\n",len2);
is returning 0 and not memory size of the notification characteristic.
Scenario 1 which works with:
add_char_params.init_len = 1; add_char_params.max_len = 1;
Peeked length 0 About to call sd_ble_gatts_hvx(), p_len 1, p_data: 5 Peeked length 0
from:
SEGGER_RTT_printf(0, "Peeked length %u\n",len2); SEGGER_RTT_printf(0, "About to call sd_ble_gatts_hvx(), p_len %d, p_data: %d\n", *params.p_len, *params.p_data); err_code = sd_ble_gatts_hvx(conn_handle, ¶ms); errcode = sd_ble_evt_get(NULL, &len2); SEGGER_RTT_printf(0, "Peeked length %u\n",len2);
Note: p_len and p_data are as I initialized, but also the peeked length appears to be inconsitent with documentation.
The output from the client (Raspberry Pi running python/bluepy is as expected:
(Pdb) b'\x05'
Next, the only change made was:
add_char_params.char_props.read = 4; add_char_params.char_props.write = 4;
The RTT output is still correct:
Peeked length 0 About to call sd_ble_gatts_hvx(), p_len 1, p_data: 5 Peeked length 0
However, the bytes actually sent are:
(Pdb) b'\x05\x01\x00\x05'
If the maximum data is initialized to 8 bytes, then 8 bytes are sent. Similarly, using:
add_char_params.init_len = NRF_SDH_BLE_GATT_MAX_MTU_SIZE; add_char_params.max_len = NRF_SDH_BLE_GATT_MAX_MTU_SIZE;
and no other changes sends:
(Pdb) b'\x05\xd1\xbc\xea_x#\x15\xde\xef\x12\x12%\x15\x00\x00\x00\x01\x00\x05'
while the RTT output is still correct:
Peeked length 0 About to call sd_ble_gatts_hvx(), p_len 1, p_data: 5 Peeked length 0
(well except for the peeked memory size which is still wrong). Finally, setting NRF_SDH_BLE_GAP_DATA_LENGTH = 251
and NRF_SDH_BLE_GATT_MAX_MTU_SIZE = 247, sends 20 bytes (extended length is not working)
(Pdb) b'\x05\x00\x00\x00\x00 \x00@\x00\x00\x00\x00\x00 \x00@\x00\x00\x00\x00'
and now the link disconnects always after 27s (as is described in a separate thread).
These behaviors do not seem correct to me, and unfortunately due to lack of documentation and visibility into the soft device, I can not debug
what is going wrong. For the last case, I can supply data from on-air sniffing, if you think it would help.