Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

299
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda