Skip to content
This repository was archived by the owner on Jul 20, 2025. It is now read-only.

Commit da1177e

Browse files
authored
Merge pull request #19 from mbientlab/development
Development
2 parents bde950e + 9f50643 commit da1177e

File tree

5 files changed

+127
-1407
lines changed

5 files changed

+127
-1407
lines changed

README.md

Lines changed: 111 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
1-
# MetaWear SDK for Javascript by MBIENTLAB
1+
# MetaWear SDK for Javascript by MBIENTLAB
22

3-
[![Platforms](https://img.shields.io/badge/platform-linux--64%20%7C%20win--32%20%7C%20osx--64%20%7C%20win--64-lightgrey?style=flat)](https://github.com/mbientlab/MetaWear-SDK-JavaScript)
3+
[![Platforms](https://img.shields.io/badge/platform-linux%20%7C%20-lightgrey?style=flat)](https://github.com/mbientlab/MetaWear-SDK-JavaScript)
44
[![License](https://img.shields.io/cocoapods/l/MetaWear.svg?style=flat)](https://github.com/mbientlab/MetaWear-SDK-JavaScript/blob/master/LICENSE.md)
5-
[![Version](https://img.shields.io/badge/node-%3D%208.0.0-brightgreen?style=flat)](https://github.com/mbientlab/MetaWear-SDK-JavaScript)
5+
[![Version](https://img.shields.io/badge/node-%3D%2010.23.0-brightgreen?style=flat)](https://github.com/mbientlab/MetaWear-SDK-JavaScript)
66

77
![alt tag](https://raw.githubusercontent.com/mbientlab/MetaWear-SDK-iOS-macOS-tvOS/master/Images/Metawear.png)
88

9-
SDK for creating MetaWear apps that run on node.js. Supported mainly on Linux but can also work on Windows, OS X and the Browser (web-bluetooth support not widespread yet, but growing) if Noble is setup correctly. This is a thin wrapper around the [MetaWear C++ API](https://github.com/mbientlab/Metawear-CppAPI) so you will find the C++ [documentation](https://mbientlab.com/cppdocs/latest/) and [API reference](https://mbientlab.com/docs/metawear/cpp/latest/globals.html) useful.
9+
SDK for creating MetaWear apps that run on node.js. Supported on Linux only.
1010

11-
Also, check out the JavaScript [examples](https://github.com/mbientlab/MetaWear-SDK-JavaScript/tree/master/examples). Again, supported on Linux only out-of-the-box.
11+
This is a thin wrapper around the [MetaWear C++ API](https://github.com/mbientlab/Metawear-CppAPI) so you will find the C++ [documentation](https://mbientlab.com/cppdocs/latest/) and [API reference](https://mbientlab.com/docs/metawear/cpp/latest/globals.html) useful.
1212

13-
Under the hood it uses [Noble](https://github.com/mbientlab/noble) for Bluetooth Low Energy communications.
13+
Also, check out the JavaScript [examples](https://github.com/mbientlab/MetaWear-SDK-JavaScript/tree/master/examples).
14+
15+
Under the hood it uses [Noble-Device](https://github.com/mbientlab/noble-device) and [Noble](https://github.com/mbientlab/noble) for Bluetooth Low Energy communications. These third party libraries have been abandoned and we are currently supporting a custom fork (with help from @abandonware).
1416

1517
> ADDITIONAL NOTES
16-
You can try to get our JS SDK running on OSX or Windows at your own risk as this requires that you get Noble to work under those OSs yourself. We do not provide examples or support for this. Please see the Noble README.
18+
You can try to get our JS SDK running on OSX or Windows at your own risk. This requires that you get Noble to work under those OSs yourself. We do not provide examples or support for this; experts ONLY. Please see the Noble README.
1719

1820
### Overview
1921

2022
[MetaWear](https://mbientlab.com) is a complete development and production platform for wearable and connected device applications.
2123

22-
MetaWear features a number of sensors and peripherals all easily controllable over Bluetooth 4.0 Low Energy using this SDK, no firmware or hardware experience needed!
24+
MetaWear features a number of sensors and peripherals all easily controllable over Bluetooth 4.0/5.0 Low Energy using this SDK, no firmware or hardware experience needed!
2325

2426
The MetaWear hardware comes pre-loaded with a wirelessly upgradeable firmware, so it keeps getting more powerful over time.
2527

2628
### Requirements
2729
- [MetaWear board](https://mbientlab.com/store/)
28-
- A linux machine with Bluetooth 4.0 (or the other OSs w/ Bluetooth support at your own risk)
30+
- A linux machine with Bluetooth 4.0/5.0
2931

3032
### License
3133
See the [License](https://github.com/mbientlab/MetaWear-SDK-JavaScript/blob/master/LICENSE.md).
@@ -35,15 +37,111 @@ Reach out to the [community](https://mbientlab.com/community/) if you encounter
3537

3638
## Getting Started
3739

40+
### Pre-Installation
41+
42+
#### Node and NPM
43+
You need to make sure you have node and npm installed on your machine. Here's a quick rundown but you should google-fu proper steps for your specific OS and Node version.
44+
45+
We are currently supporting Node 10.23.0. Here are steps to install Node on Linux (Ubuntu). You have 3 options:
46+
47+
##### 1. You can install Node from the repositories:
48+
```
49+
sudo apt install nodejs
50+
sudo apt install npm
51+
nodejs -v
52+
```
53+
This will install the latest Node. You may need to alias nodejs to node.
54+
55+
##### 2. You can install Node from a PPA:
56+
```
57+
cd ~
58+
curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh
59+
sudo bash nodesource_setup.sh
60+
sudo apt install nodejs
61+
nodejs -v
62+
```
63+
This will install node v10.23.0 (latest stable release of node 10). You can replace the 10 with 12 if you want to install node 12. You may need to alias nodejs to node.
64+
65+
##### 3. Using NVM (preferred method):
66+
```
67+
curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.35.3/install.sh -o install_nvm.sh
68+
bash install_nvm.sh
69+
source ~/.profile
70+
nvm install 10.23.0
71+
nvm use 10.23.0
72+
node -v
73+
```
74+
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.
75+
76+
##### Using sudo - a Warning
77+
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.
78+
79+
You also need to check that the version of node you are using is as expected for sudo:
80+
```
81+
$ node -v
82+
v0.10.23
83+
$ sudo node -v
84+
v0.11.8-pre
85+
```
86+
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.
87+
3888
### Installation
39-
The Mbient JavaScript SDK relies on [Noble](https://github.com/mbientlab/noble) for Bluetooth Low Energy communications. You need to setup the relevant [prerequisites for Noble](https://github.com/mbientlab/noble#prerequisites) and then [install Noble](https://github.com/mbientlab/noble#install).
4089

41-
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.
90+
You have two options for installation:
4291

43-
Then you can simply install the MetaWear NPM module with command line:
44-
```javascript
92+
#### 1. Use NPM
93+
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.
94+
95+
You need to setup the relevant [prerequisites for Noble](https://github.com/mbientlab/noble#prerequisites) and then [install Noble](https://github.com/mbientlab/noble#install). Make sure you use our versions of these libraries as the original packages have been abandoned.
96+
97+
Then you can simply install the MetaWear package lib with NPM using the command line:
98+
```
4599
npm install metawear
46100
```
101+
This step takes a long time as all the packages are installed and the MetaWear CPP library will be compiled on your machine. You may or may not need to update.
102+
```
103+
npm update metawear
104+
```
105+
106+
#### 2. Use our Repository
107+
We packaged everything for you already in this repository with the package.json file ready to be installed with npm.
108+
109+
Make sure that when you clone this repository, that you clone the submodule with it.
110+
```
111+
git clone --recurse-submodules https://github.com/mbientlab/MetaWear-SDK-JavaScript.git
112+
```
113+
114+
Then you can simply install all the dependencies you need by building the npm project with command line:
115+
```javascript
116+
npm install
117+
```
118+
This step takes a long time as all the packages are installed and the MetaWear CPP library will be compiled as well.
119+
120+
Once the install is success, you can run our example scripts in the example folder:
121+
```javascript
122+
node led.js
123+
```
124+
125+
Please note that depending on your node and npm installation, you may need to run sudo:
126+
```javascript
127+
sudo node led.js
128+
```
129+
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).
130+
131+
Please note that the examples in our examples folder will use the local metawear libraries (as this repository is meant for development):
132+
```javascript
133+
var MetaWear = require('../index')
134+
```
135+
This would be using the local metawear code. You will probably never need this unless you are planning to change our internal libraries.
136+
137+
Simply change it to this:
138+
```javascript
139+
var MetaWear = require('metawear');
140+
```
141+
This would be using the metawear code in your local npm `node_modules` directory as installed. This is the prefered way.
142+
143+
#### Notes
144+
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.
47145

48146
### Usage
49147

lib/metawear.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,15 @@ function onDisconnect(context, caller, handler) {
298298
}
299299

300300
MetaWear.prototype.updateFirmwareToRev = function (rev, callback) {
301+
this.updateFirmwareToRevAndFlavor(rev, 'vanilla', callback);
302+
}
303+
304+
MetaWear.prototype.updateFirmwareToRevAndFlavor = function (rev, flavor, callback) {
301305
var sanitaizedCallback = (typeof callback === 'function') ? callback : function () { };
302306
// Helper block to do the update
303307
var doUpdate = function () {
304308
debug('updating...');
305-
findAndPerformDfu.call(this, rev, function (error) {
309+
findAndPerformDfu.call(this, rev, flavor, function (error) {
306310
debug('metaboot updateFirmware: ' + error);
307311
sanitaizedCallback(error);
308312
});
@@ -317,7 +321,8 @@ MetaWear.prototype.updateFirmwareToRev = function (rev, callback) {
317321
sanitaizedCallback(error);
318322
return;
319323
}
320-
if (firmwareRev === rev) {
324+
var currentFlavor = MetaWear.mbl_mw_settings_get_firmware_build_id(this.board).toString();
325+
if ((firmwareRev === rev) && (currentFlavor === flavor)) {
321326
sanitaizedCallback(null);
322327
return;
323328
}
@@ -370,7 +375,7 @@ MetaWear.prototype.updateFirmwareWithUrl = function (url, callback) {
370375
}.bind(this));
371376
};
372377

373-
function findAndPerformDfu(firmwareRev, callback) {
378+
function findAndPerformDfu(firmwareRev, flavor, callback) {
374379
this.readModelNumber(function (error, modelNumber) {
375380
if (error) {
376381
console.error(error);
@@ -386,12 +391,12 @@ function findAndPerformDfu(firmwareRev, callback) {
386391
}
387392
debug('hardwareRev: ' + hardwareRev);
388393
// Use the zip firmware if it exists
389-
var url = firmwareUrl(hardwareRev, modelNumber, firmwareRev, 'firmware.zip');
394+
var url = firmwareUrl(hardwareRev, modelNumber, flavor, firmwareRev, 'firmware.zip');
390395
urlExists(url, function (err, exists) {
391396
if (exists) {
392397
this.updateFirmwareWithUrl(url, callback);
393398
} else {
394-
url = firmwareUrl(hardwareRev, modelNumber, firmwareRev, 'firmware.bin');
399+
url = firmwareUrl(hardwareRev, modelNumber, flavor, firmwareRev, 'firmware.bin');
395400
urlExists(url, function (err, exists) {
396401
if (exists) {
397402
this.updateFirmwareWithUrl(url, callback);
@@ -405,8 +410,8 @@ function findAndPerformDfu(firmwareRev, callback) {
405410
}.bind(this));
406411
}
407412

408-
function firmwareUrl(hardwareRev, modelNumber, firmwareRev, filename) {
409-
return "https://mbientlab.com/releases/metawear/" + hardwareRev + "/" + modelNumber + "/vanilla/" + firmwareRev + "/" + filename;
413+
function firmwareUrl(hardwareRev, modelNumber, flavor, firmwareRev, filename) {
414+
return "https://mbientlab.com/releases/metawear/" + hardwareRev + "/" + modelNumber + "/" + flavor + "/" + firmwareRev + "/" + filename;
410415
}
411416

412417
function download(url, dest, cb) {

0 commit comments

Comments
 (0)