{"id":18330365,"url":"https://github.com/mbientlab/noble-device","last_synced_at":"2025-08-22T06:43:25.119Z","repository":{"id":41978213,"uuid":"95712635","full_name":"mbientlab/noble-device","owner":"mbientlab","description":"MetaWear Javascript SDK - Fork of NobleDevice - BLE Peripheral","archived":false,"fork":false,"pushed_at":"2023-07-12T09:23:07.000Z","size":315,"stargazers_count":1,"open_issues_count":4,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-08T17:40:44.948Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://mbientlab.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mbientlab.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-28T21:19:44.000Z","updated_at":"2022-04-20T21:06:23.000Z","dependencies_parsed_at":"2024-11-05T19:29:09.436Z","dependency_job_id":"8a94b2e2-b413-442b-8cb6-a4b4e0400076","html_url":"https://github.com/mbientlab/noble-device","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/mbientlab/noble-device","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbientlab%2Fnoble-device","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbientlab%2Fnoble-device/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbientlab%2Fnoble-device/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbientlab%2Fnoble-device/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mbientlab","download_url":"https://codeload.github.com/mbientlab/noble-device/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbientlab%2Fnoble-device/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271599733,"owners_count":24787801,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-22T02:00:08.480Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T19:22:09.786Z","updated_at":"2025-08-22T06:43:25.044Z","avatar_url":"https://github.com/mbientlab.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"noble-device\n============\n\nA Node.js lib to abstract BLE (Bluetooth Low Energy) peripherals, using [noble](https://github.com/sandeepmistry/noble)\n\n## Install\n```\nnpm install noble-device\n```\n\n## Usage\n\nTake a look at the [Tethercell](https://github.com/sandeepmistry/node-tethercell/) and [unofficial LightBlue Bean](https://github.com/jacobrosenthal/ble-bean) devices for examples, but this is how you make a basic device:\n\n```javascript\nvar NobleDevice = require('noble-device');\n\nvar YOUR_THING_SERVICE_UUID = 'xxxxxxxxxxxxxxxxxxxxxxxx';\nvar YOUR_THING_NOTIFY_CHAR  = 'xxxxxxxxxxxxxxxxxxxxxxxx';\nvar YOUR_THING_READ_CHAR    = 'xxxxxxxxxxxxxxxxxxxxxxxx';\nvar YOUR_THING_WRITE_CHAR   = 'xxxxxxxxxxxxxxxxxxxxxxxx';\n\n// then create your thing with the object pattern\nvar YourThing = function(peripheral) {\n  // call nobles super constructor\n  NobleDevice.call(this, peripheral);\n\n  // setup or do anything else your module needs here\n};\n\n// tell Noble about the service uuid(s) your peripheral advertises (optional)\nYourThing.SCAN_UUIDS = [YOUR_THING_SERVICE_UUID];\n\n// and/or specify method to check peripheral (optional)\nYourThing.is = function(peripheral) {\n  return (peripheral.advertisement.localName === 'My Thing\\'s Name');\n};\n\n// inherit noble device\nNobleDevice.Util.inherits(YourThing, NobleDevice);\n\n// you can mixin other existing service classes here too,\n// noble device provides battery and device information,\n// add the ones your device provides\nNobleDevice.Util.mixin(YourThing, NobleDevice.BatteryService);\nNobleDevice.Util.mixin(YourThing, NobleDevice.DeviceInformationService);\n\n// export your device\nmodule.exports = YourThing;\n```\n\nNow to use `YourThing` you must use one of the discover functions [documented below](#discovery-api) which will find your device(s) and pass instances of your object to their callback where you must call `connectAndSetUp`.\n\n```javascript\nvar YourThing = require('YourThing');\n\nvar id = '\u003cyour devices id\u003e';\nYourThing.discoverById(function(id, yourThingInstance) {\n\n  // you can be notified of disconnects\n  yourThingInstance.on('disconnect', function() {\n    console.log('we got disconnected! :( ');\n  });\n\n  // you'll need to call connect and set up\n  yourThingInstance.connectAndSetUp(function(error) {\n    console.log('were connected!');\n  });\n\n});\n```\n\nIt doesn't do much yet, let's go back and add to our Device definition (right before ``module.exports``)\n\n```javascript\n// you could send some data\nYourThing.prototype.send = function(data, done) {\n  this.writeDataCharacteristic(YOUR_THING_SERVICE_UUID, YOUR_THING_WRITE_CHAR, data, done);\n};\n\n// read some data\nYourThing.prototype.receive = function(callback) {\n  this.readDataCharacteristic(YOUR_THING_SERVICE_UUID, YOUR_THING_READ_CHAR, callback);\n};\n```\n\n\nNow in our connect and setup we can:\n\n```javascript\n    yourThing.send(new Buffer([0x00, 0x01]), function() {\n      console.log('data sent');\n    });\n\n    yourThing.receive(function(error, data) {\n      console.log('got data: ' + data);\n    });\n```\n\nOptionally, if you need to do some device setup or close something down before disconnect, you can override those functions:\n\n```javascript\nYourThing.prototype.connectAndSetup = function(callback) {\n  NobleDevice.prototype.connectAndSetUp.call(this, function(error) {\n    // maybe notify on a characteristic ?\n    this.notifyCharacteristic(YOUR_THING_SERVICE_UUID, YOUR_THING_NOTIFY_CHAR, true, this._onRead.bind(this), function(err) {\n      callback(err);\n    });\n  }.bind(this);\n};\n\nYourThing.prototype.onDisconnect = function(reason) {\n  // clean up ...\n\n  // call super's onDisconnect\n  NobleDevice.prototype.onDisconnect.call(this, reason);\n};\n```\n\n\n### Discovery API\n\n__Discover All__\n\n``` javascript\nfunction onDiscover(yourThingInstance) {\n  // called for all devices discovered\n}\n\nYourThing.discoverAll(onDiscover);\n```\n\n__Stopping a Discover All__\n\n```javascript\n\nYourThing.stopDiscoverAll(onDiscover);\n```\n\n__Discover a single device__\n\n``` javascript\nYourThing.discover(function(yourThingInstance) {\n  // called for only the first device discovered\n});\n```\n\n__Stopping a Discover__\n\n```javascript\n\nYourThing.stopDiscover(onDiscoverCallback);\n```\n\n__Discover with Filter__\n\n``` javascript\nYourThing.discoverWithFilter(function(device), {\n  // filter callback for device,\n  //   return true to stop discovering and choose device\n  //   return false to continue discovery\n\n  return true; // or false\n}, function(yourThingInstance) {\n  // called for only one device discovered that matches filter\n});\n```\n\n__Discover by ID__\n\n``` javascript\nvar id = \" ... \"; // id of device we want to discover\n\nYourThing.discoverById(id, function(yourThingInstance) {\n  // called for only one device discovered\n});\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbientlab%2Fnoble-device","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmbientlab%2Fnoble-device","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbientlab%2Fnoble-device/lists"}