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

186
Visualizações
Noble BLE in Node.js - sometimes works, sometimes doesn't

I have the following code I'm trying to run and I'm getting different results every time I run it. Sometimes I just get "Powered Off". Sometimes I get that plus "Powered on". Sometimes I get all of the above plus "Scanning started". And sometimes it runs all the way thru and I get a bunch of "still searching..." and it eventually hits the BLE device and returns the advertisement.

I have no idea why this is working sometimes and not others.

var async = require('async');
var noble = require('../index');

var peripheralIdOrAddress = "8cf681a590f3";

noble.on('stateChange', function(state) {
  if (state === 'poweredOn') {
    noble.startScanning();
    console.log("Powered On")
  } else {
    noble.stopScanning();
    console.log("Powered Off")
  }
});

noble.on('scanStart', ()=>console.log("Scanning started"))
noble.on('scanStop', ()=>console.log("Scanning stopped"))

noble.on('discover', function(peripheral) {
  console.log("Discovered something!");
  if (peripheral.id === peripheralIdOrAddress || peripheral.address === peripheralIdOrAddress) 
  {
    noble.stopScanning();
    console.log('peripheral with ID ' + peripheral.id + ' found');
    var advertisement = peripheral.advertisement;
    console.log(JSON.stringify(advertisement));

    peripheral.on('disconnect', function() {
      console.log("Peripheral disconnected");
      process.exit(0);
    });

    peripheral.on('connect', ()=>console.log("Peripheral connected"));
  
    peripheral.connect(function(error) {
      peripheral.discoverServices("a0521000-2a63-479e-9d0a-09dfa7c8fd98",()=>console.log("Service discovered"));

    });
  }
  else{console.log("Not the one.  still searching...")}
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Crazy addition to this question. I tried a lot of things with turning stuff off and unplugging things.

In the end I found out it was the power port. If I'm plugged into wall power, I get about 1 out of ever 10 runs that works. If I unplug wall power and go off battery, it works every time.

So bizarre.

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