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

158
Visualizações
¿Por qué Bluetooth.entonces no es una función?

Estoy escribiendo un programa Javascript para imprimir información del dispositivo.

Tengo dos servicios: 'battery_service' e 'device_information', y la característica debajo de 'battery_service' es 'battery_information'.

Quiero implementar algún código en funciones separadas para hacerlo más ordenado, pero cuando quiero hacerlo, aparece el siguiente error:

 deviceInfo3.js:11 Uncaught TypeError: bluetoothDevice is not a function

de llamar a la siguiente función: My getBatteryFunction:

 function getBatteryPercent() { bluetoothDevice .then( value => { console.console.log("Battery = "+value.getUint8(0)) document.getElementById("battery").value=value.getUint8(0); } ) }

y esta es mi función de controlador principal cuando se hace clic en el botón:

 var bluetoothDevice; function onScanButtonClick() { let options = {filters: []}; options.filters.push({services: ['battery_service', 'device_information' ]}); console.log('Requesting Bluetooth Device...'); navigator.bluetooth.requestDevice(options) .then(device => { bluetoothDevice = device; bluetoothDevice.addEventListener('gattserverdisconnected', onDisconnected); return device.gatt.connect(); }) .then((server) => { // Set the isConnected variable to true bluetoothDevice.isConnected = true; console.log('Getting Accelerometer service (UUID: ' + 'battery_service' + ')... '); // Get the accelerometer service (if it's not enabled, the error will be caught below) return server.getPrimaryServices(); }) .then(services => { console.log("Getting characteristics..."); let queue=Promise.resolve(); services.forEach(service => { console.log(service.uuid); switch(service.uuid) { case ('0000180f-0000-1000-8000-00805f9b34fb'): { getBatteryPercent(); } } }) }) }

¿Cómo puedo conseguir esto?

about 4 years ago · Juan Pablo Isaza
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