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

296
Views
Web-Bluetooth API, no puede actualizar las características. ¿Es posible la actualización en función del tiempo?

Intento obtener las características cada vez que cambian, el problema es que cambian pero el eventListener no lo reconoce. Entonces solo obtengo el primer valor, después de conectarme a mi BLE, pero no sucede nada después de eso. ¿Hay algo mal en mi código?

Otra pregunta, ¿hay alguna forma de actualizar la característica cada, no sé 5 segundos, por ejemplo? ¿Y cómo haría eso? ¿Hay algún ejemplo de código? (¿Quizás con setInterval() ?)

Gracias !

 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. Te perdiste una llamada de feature.startNotifications characteristic.startNotifications() para comenzar a recibir notificaciones. ejemplo
  2. setInterval estaría bien llamar a readValue() cada 5 segundos.
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!