I have this simple function which writes some data to a characteristic:
export const writeAuthenticationCharacteristic = async (
device: Device,
value: string,
) => {
const valueToWrite = Buffer.from(value, 'hex').toString('base64');
await device.writeCharacteristicWithResponseForService(
SERVICE_AUTHENTICATION_UUID,
CHARACTERISTIC_AUTHENTICATION_UUID,
valueToWrite,
);
};
Where the value is 32 byte data, but the limit on the receiving side is 20 bytes, so I would need to chunk this data into two separate writes.
It works well on Android for some reason by automatically creating chunks, however on iOS it doesn't do that. I'll add logs on how the writes differ between these two:
iOS:
[0;32mI (1215066) [BT][SRV]: [app_1] GATT_WRITE_EVT prep: 0 rsp: 1 trnsfr: 5 handle: 51 len 32, offset 0, value: 5D4F310A26F3C5FD06622334FA5121B846B4B3D0FE2B6EAB8991CDFD6B [0;32mI (121506) [BT][SRV]: [app_1] GATT_WRITE_EVT needs response
Android:
[0;32mI (134336) [BT][SRV]: [app_1] GATT_WRITE_EVT prep: 1 rsp: 1 trnsfr: 3 handle: 51 len 18, offset 0, value: BE4BE1D56020B3CA0A2EC3DD265E48 [0;32mI (134336) [BT][SRV]: [app_1] GATT_WRITE_EVT needs response [0;32mI (1343916) [BT][SRV]: [app_1] GATT_WRITE_EVT prep: 1 rsp: 1 trnsfr: 4 handle: 51 len 14, offset 18, value: 60AA3A3EA95EAA1EEB24DB2B80 [0;32mI (1343916) [BT][SRV]: [app_1] GATT_WRITE_EVT needs response
What might be the difference between these two? I looked into manually chunking the data, but I didn't find a way to create a prepared write where I could specify the offset value of the second chunk, so it felt like I'm just overwriting the same thing instead of appending.
Or is there a configuration that I missed which would enable chunking for iOS as well?