Skip to content

Commit

Permalink
update ffi for node 10, update to use @abandonware official releases
Browse files Browse the repository at this point in the history
  • Loading branch information
lkasso committed Dec 23, 2020
1 parent 5045fcf commit 739afff
Show file tree
Hide file tree
Showing 7 changed files with 822 additions and 292 deletions.
55 changes: 47 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ node -v
Check the latest version of NVM before you install (it might be higher than v0.35.3). You can go online to learn how to use NVM to switch node versions on the fly.

##### Using sudo - a Warning
It is important to note that because our scripts use OS level Bluetooth libraries, it may be required to use sudo (or you will get a warning and the scripts won't work). You need to decide if you are ok to use sudo or not.
It is important to note that because our scripts use OS level Bluetooth libraries, it may be required to use sudo (or you will get a warning and the scripts won't work). You need to decide if you are ok to use sudo or not. If you are not, follow this [guide](https://github.com/sandeepmistry/noble#running-on-linux)

You also need to check that the version of node you are using is as expected for sudo:
```
Expand All @@ -84,10 +84,28 @@ $ sudo node -v
v0.11.8-pre
```
As you can see here, the sudo node version is not the same as the current user version. Here's a [workaround](https://stackoverflow.com/questions/21215059/cant-use-nvm-from-root-or-sudo). You can google-fu more about this topic.
```
n=$(which node); \
n=${n%/bin/node}; \
chmod -R 755 $n/bin/*; \
sudo cp -r $n/{bin,lib,share} /usr/local
```

##### Using bluez, BLE Dongles, and Node
At the time of this release, Node 10 is supported. Node 12 is not currently supported as `node-ffi` and some other libraries have not been updated.
We have to use a custom fork of node-ffi until then (see package.json). Hopefully node-ffi will be updated to support Node 10 and Node 12 officially.

Bluez 5.50 works but 5.54 might not work. Here's a good [tutorial](https://learn.adafruit.com/install-bluez-on-the-raspberry-pi/installation)

If you are not using a BLE dongle, you need to make sure your system is working and supports Bluetooth 4.0 or later (Bluetooth low energy).

If you are using a BLE dongle, you need to make sure it's working. You can google-fu how to use tools such as `bluetoothctl`, `hciconfig`, `btmon` and more to confirm this.

This may or may not work on arm64. Works on armhf and raspberryPi 3 and RaspberryPi 4.

### Installation

You have two options for installation:
You have three options for installation:

#### 1. Use NPM
The Mbient JavaScript SDK relies on [Noble](https://github.com/mbientlab/noble) and [Noble-Device](https://github.com/mbientlab/noble-device) for Bluetooth Low Energy communications.
Expand All @@ -104,6 +122,13 @@ npm update metawear
```

#### 2. Use our Repository
You can install the metawear package straight from our repository by using:
```
npm install https://github.com/mbientlab/MetaWear-SDK-JavaScript.git
```
This step takes a long time as all the packages are installed and the MetaWear CPP library will be compiled on your machine.

#### 3. Clone our Repository
We packaged everything for you already in this repository with the package.json file ready to be installed with npm.

Make sure that when you clone this repository, that you clone the submodule with it.
Expand All @@ -117,7 +142,24 @@ npm install
```
This step takes a long time as all the packages are installed and the MetaWear CPP library will be compiled as well.

Once the install is success, you can run our example scripts in the example folder:
#### Errors and Issues
If you have any issues with the npm installation, make sure you are using the correct version of node, npm, nvm (if used), bluez, and that your machine is bluetoothLE compliant. Follow the errors and correct them as indicated by the npm output log.

If you have any issues compiling the `MetaWear-CPP-SDK` (this is a post script that runs at the end of npm install), simply build it from source.
If you cloned the repo:
```
cd MetaWear-SDK-Cpp/
make
```
If you ran an npm command:
```
cd node_modules/
cd MetaWear-SDK-Cpp/
make
```

#### Running your first Script
Once the install is successful, you can run our example scripts in the example folder (see the example folder in our repository):
```javascript
node led.js
```
Expand All @@ -126,25 +168,23 @@ Please note that depending on your node and npm installation, you may need to ru
```javascript
sudo node led.js
```
This can be avoided with proper installation steps but it will depend on whether or not your application and requirements are ok with sudo or not (to each their own).

Please note that the examples in our examples folder will use the local metawear libraries (as this repository is meant for development):
```javascript
var MetaWear = require('../index')
```
This would be using the local metawear code. You will probably never need this unless you are planning to change our internal libraries.
This is using the local metawear code.

Simply change it to this:
```javascript
var MetaWear = require('metawear');
```
This would be using the metawear code in your local npm `node_modules` directory as installed. This is the prefered way.
This would be using the metawear code in your local npm `node_modules` directory as installed with npn.

#### Notes
You should familiarize yourself with this README and our tutorials since there a few limitiations and other gotchas spelled out, such as the maximum number of simultaneous Bluetooth connections.

### Usage

Require the metawear package

```javascript
Expand Down Expand Up @@ -197,5 +237,4 @@ MetaWear.discover(function (device) {
```
### Tutorials
Tutorials can be found [here](https://mbientlab.com/tutorials/).
2 changes: 1 addition & 1 deletion examples/full_reset.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var MetaWear = require('../index')//require('metawear');

MetaWear.discoverByAddress('f9:b5:f9:81:3f:77', function(device) {
MetaWear.discoverByAddress('c8:4b:aa:97:50:05', function(device) {
console.log('Discovered');
//MetaWear.discover(function (device) {
device.connectAndSetUp(function (error) {
Expand Down
4 changes: 2 additions & 2 deletions examples/log_acc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ var ref = require('ref');
var accelLogger = null;

// If you know the MAC address, you can uncomment this line
//MetaWear.discoverByAddress('f3:97:6b:cc:71:97', function (device) {
MetaWear.discover(function (device) {
MetaWear.discoverByAddress('c8:4b:aa:97:50:05', function (device) {
//MetaWear.discover(function (device) {
console.log('discovered ' + device.address);
device.connectAndSetUp(function (error) {
if (error) {
Expand Down
4 changes: 2 additions & 2 deletions examples/scan_connect.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var MetaWear = require('../index')//require('metawear');

// If you know the MAC address, you can uncomment this line
//MetaWear.discoverByAddress('cb:7d:c5:b0:20:8f', function(device) {
MetaWear.discover(function (device) {
MetaWear.discoverByAddress('c8:4b:aa:97:50:05', function(device) {
//MetaWear.discover(function (device) {
console.log('got em');
// you can be notified of disconnects
device.on('disconnect', function () {
Expand Down
4 changes: 2 additions & 2 deletions lib/metawear.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var debug = require('debug')('metawear');
var debugRaw = require('debug')('metaboot');

var NobleDevice = require('noble-device');
var noble = require('noble');
var noble = require('@abandonware/noble');
var ref = require('ref');
var events = require('events');
var util = require('util');
Expand Down Expand Up @@ -99,7 +99,7 @@ MetaWear.prototype.writeCommandCharacteristic = function (data, callback) {

MetaWear.prototype.connectAndSetUp = function (callback, initBuf) {
var initializeCallback = (typeof callback === 'function') ? callback : function () { };

NobleDevice.prototype.connectAndSetUp.call(this, function (error) {
if (error) {
initializeCallback(error);
Expand Down
Loading

0 comments on commit 739afff

Please sign in to comment.