Open
Description
Hi!
I am using ARDUINO NANO 33 BLE SENSE as peripheral and Web Bluetooth API to write a characteristic value on it.
The value size is 512 bytes.
I am using this sketch: https://github.com/arduino-libraries/ArduinoBLE/tree/master/examples/Peripheral/LED with the following modification:
//BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
BLECharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite, 512);
I can successfully write to the characteristic first few times but then it gets stuck.
The issue also occurs if I write to four different characteristics (512 each) one after another.
Occurs even if I disconnect between writes.
From my observation, this issue never occurs for value size<200 bytes. It occurs sporadically for size=256.
Web Bluetooth script to reproduce the issue:
Connect then Write<br>
<button id="connect">Connect</button>
<button id="write1">Write</button>
<script>
var bleService = '19b10000-e8f2-537e-4f6c-d104768a1214'
var bleCharacteristic1 = '19b10001-e8f2-537e-4f6c-d104768a1214'
var arduinoDevice;
var gattService;
var gattCharacteristic1;
const testbyte1= new Uint8Array([0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x41,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x71,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
0x51,0x42, 0x43, 0x44 , 0x45, 0x46,0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50]);
console.log(testbyte1);
function connect(){
navigator.bluetooth.requestDevice({ filters: [{services: [bleService]}] })
.then(device => {arduinoDevice= device;
return arduinoDevice.gatt.connect();})
.then(server => server.getPrimaryService(bleService))
.then(service => {gattService= service;
return gattService.getCharacteristic(bleCharacteristic1)})
.then(characteristic1 => {gattCharacteristic1= characteristic1;
console.log("Connect done");})
.catch(error => { console.error(error);
Promise.resolve();});
}
function write(){
if(arduinoDevice.gatt.connected){
gattCharacteristic1.writeValue(testbyte1.slice(0,512))
.then(_ =>{
console.log('Written')
})
.catch(error => { console.error(error)
Promise.resolve();});
}
else{ alert('Device not connected');
}
}
document.getElementById('connect').addEventListener('click', connect, false);
document.getElementById('write1').addEventListener('click', write, false);
</script>