Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No trigger characteristicvaluechanged method #372

Open
brave2016 opened this issue Aug 17, 2017 · 12 comments

Comments

@brave2016
Copy link

commented Aug 17, 2017

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";
}
@beaufortfrancois

This comment has been minimized.

Copy link
Member

commented Aug 17, 2017

Can you provide some logs?

@brave2016

This comment has been minimized.

Copy link
Author

commented Aug 17, 2017

@brave2016

This comment has been minimized.

Copy link
Author

commented Aug 17, 2017

@beaufortfrancois

This comment has been minimized.

Copy link
Member

commented Aug 17, 2017

When do you get this error exactly?
It may be because your device is not Bluetooth Low Energy.

@brave2016

This comment has been minimized.

Copy link
Author

commented Aug 17, 2017

@brave2016

This comment has been minimized.

Copy link
Author

commented Aug 17, 2017

@brave2016

This comment has been minimized.

Copy link
Author

commented Aug 18, 2017

@beaufortfrancois

This comment has been minimized.

Copy link
Member

commented Aug 18, 2017

Can you reproduce with Google Chrome?

@brave2016

This comment has been minimized.

Copy link
Author

commented Aug 18, 2017

@beaufortfrancois

This comment has been minimized.

Copy link
Member

commented Aug 18, 2017

Can you reproduce with Google Chrome, not Opera?

@brave2016

This comment has been minimized.

Copy link
Author

commented Aug 18, 2017

@beaufortfrancois

This comment has been minimized.

Copy link
Member

commented Aug 18, 2017

Does it work fine for you now with Google Chrome?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.