Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

295
Views
Web-Bluetooth API, can not update characteristics. time-dependent updating possible?

I try to get the characteristics everytime they change, the problem is, they change but the eventListener doesn't recognize it. So i only get the first value, after connecting to my BLE, but nothing happen after that. Is there something wrong in my code ?

Another Question, is there a way to update the characteristic every, i dont know 5 Seconds for example? And how would you do that, are there any code examples?(Maybe with setInterval() ? )

Thank you !

function test() {
  console.log('Requesting Bluetooth Device...');
  navigator.bluetooth.requestDevice({
    acceptAllDevices: true,
    optionalServices: ['af07ecb8-e525-f189-9043-0f9c532a02c7']
    })                     //c7022a53-9c0f-4390-89f1-25e5b8ec07af
  .then(device => {
    console.log('Gatt Server Verbindung');
    return device.gatt.connect();
  })
  .then(server => {
    console.log('Dose Service...');
    return server.getPrimaryService('af07ecb8-e525-f189-9043-0f9c532a02c7');
  })
  .then(service => {
    console.log('mgyh Characteristic...');
    return service.getCharacteristic('a99e0be6-f705-f59c-f248-230f7d55c3c1');
  })
  .then(characteristic => {
    // Set up event listener for when characteristic value changes.
    characteristic.addEventListener('characteristicvaluechanged',dosechanged);
    
    return characteristic.readValue();
  })
  .catch(error => {
    console.log('Das geht nicht: ' + error);
  });
}

function dosechanged(event) {
  
  let dose = event.target.value.getUint8(0)+event.target.value.getUint8(1)*10+event.target.value.getUint8(2)*100 + event.target.value.getUint8(3)*1000+ event.target.value.getUint8(4)*10000;
  console.log('Received ' + dose);

} 
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  1. You missed a characteristic.startNotifications() call to start receive notification. example
  2. setInterval would be fine to call readValue() every 5 seconds.
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!