Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

184
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda