- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
window.ble = function(){
console.log('handling click');
navigator.bluetooth.requestDevice({
filters:[
{name: 'gatt_mark', services: [0xffd0]}
]
})
.then(function(device){
console.log('device');
return device.gatt.connect();
})
.then(function(server){
console.log('server');
return server.getPrimaryService(0xffd0);
})
.then(function(service){
console.log('service');
return Promise.all([service.getCharacteristic(0xfff1), service.getCharacteristic(0xfff2)]);
})
.then(function(gatt_char){
debugger;
gatt_char[0].readValue().then(function(buf){ alert( (new TextDecoder()).decode(buf) ) })
//gatt_char.startNotifications
//
})
.catch(function(e){ debugger; })
}
var dn = false;
if(!dn) {
document.addEventListener('click', window.ble);
dn = true;
}