noble is an open source BLE stack library created for Nodejs.
We support BLE with obniz.js, and we also publish the obniz-noble project.
obniz-noble allows remote operation of BLE gateways with obnizOS, while retaining the normal noble program. (The only difference from official noble is that you need to use obniz-noble and obnizID.)
(Note: obniz-noble works, but not guaranteed. Use obniz.js instead.)
Installation
In the case of Nodejs
If it's Nodejs, install obniz-noble instead of noble.
npm install obniz-noble
Then instantiates the noble using the obnizID.
At this time, you can specify obnizOptions as the second argument and specify any obnizClass as the third argument.
If obnizClass not specified, obniz specified in the package.json of obniz-noble will be used automatically.
// use default obniz
var obnizNoble = require('obniz-noble')
var noble = obnizNoble("OBNIZ_ID_HERE")
// or var noble = obnizNoble("OBNIZ_ID_HERE", {obnizOptions})
When specifying any obnizClass, the code is as follows.
// use a specific obniz
var obniz = require('obniz')
var obnizNoble = require('obniz-noble')
var noble = obnizNoble("OBNIZ_ID_HERE", {}, obniz)
In the case of a browser
If you are using a browser, take the following Script and instantiate it.
<!-- use default obniz -->
<script src="https://unpkg.com/obniz-noble/obniz-noble.js" crossorigin="anonymous"></script>
<script>
var noble = obnizNoble("OBNIZ_ID_HERE")
</script>
When specifying any obnizClass, the code is as follows.
<!-- use a specific obniz -->
<script src="https://unpkg.com/obniz/obniz.js"></script>
<script src="https://unpkg.com/obniz-noble/obniz-noble.js" crossorigin="anonymous"></script>
<script>
var noble = obnizNoble("OBNIZ_ID_HERE", {}, Obniz)
</script>
Example program (scan)
The following is a sample code when the BLE scan is performed most easily.
noble.startScanning(); // any service UUID, no duplicates
noble.on('discover', function(peripheral) {
console.log('Found device with local name: ' + peripheral.advertisement.localName);
console.log('advertising the following service uuid\'s: ' + peripheral.advertisement.serviceUuids);
console.log();
});
To learn how to use noble, please visit the official noble website or obniz-noble. For more information about connections, services, and characteristics, please follow the noble official operating instructions.