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

185
Views
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 answers
Answer question

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 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!