[web-bluetooth] No trigger characteristicvaluechanged method

brave2016 has just created a new issue for https://github.com/WebBluetoothCG/web-bluetooth:

== No trigger characteristicvaluechanged method ==
There is no problem with the following code

 let chosenHeartRateService = null;
 

function search(){
 document.getElementById("demo").innerHTML="My First JavaScript";
 let options = {
  optionalServices:['00000000-0000-1000-8000-00805f9b34fb']
 };
 let filters = [];
 
 let  services = document.querySelector('#services').value;
 let  filterName = document.querySelector('#name').value;
 let  Prefix = document.querySelector('#Prefix').value;
 if(services || filterName || Prefix){
    if (filterName) {
    filters.push({name:filterName});
 }
  if(services){
   filters.push({services:[services]});
  }
  if(Prefix){
    filters.push({namePrefix: Prefix});
  }
  options.filters = filters;
  
  
    }else{
     options.acceptAllDevices = true;
    }
  
 navigator.bluetooth.requestDevice(options).then(device => {
  
 return device.gatt.connect();
 
         }).then(server => {  
    return server.getPrimaryService('00000000-0000-1000-8000-00805f9b34fb');
   }).then(service => {
    chosenHeartRateService = service;
   return Promise.all([
   
      service.getCharacteristic('00000001-0000-1000-8000-00805f9b34fb').then(w),
      service.getCharacteristic('00000003-0000-1000-8000-00805f9b34fb').then(read)
   ]);
 
             }).catch(error => {
             document.getElementById("demo").innerHTML=error;
   });
}

function read(characteristic){
  return characteristic.startNotifications()
  .then(char => {
    characteristic.addEventListener('characteristicvaluechanged',
                                   onHeartRateChanged );
  });
 
}
//var tmp_count = 0 ;
function onHeartRateChanged (event) {
     var value = event.target.value;
   document.getElementById("data").innerHTML="Received"+sensorLocation;
 //tmp_count ++ ;
  //document.getElementById("data").innerHTML=tmp_count;
}



function w(characteristic){
    let resetEnergyExpended = new Uint8Array([34,8,35,7]);
    characteristic.writeValue(resetEnergyExpended);
 document.getElementById("w").innerHTML="write";
}






Please view or discuss this issue at https://github.com/WebBluetoothCG/web-bluetooth/issues/372 using your GitHub account

Received on Thursday, 17 August 2017 08:01:13 UTC