Back in October 2014 I attended a talk by Erica Stanley called “Open Source and the Internet of Things” at the All Things Open conference in Raleigh. We were just starting to do wearable development beyond Android Wear and Google Glass and had been playing with some prototyping boards. At the time, working with boards that included any kind of wireless chipset posed a challenge: You needed to write code that could run on the board whilst developing a protocol to communicate between the two devices. In addition, most boards, albeit smaller than an Arduino, were still fairly sizable if you were trying to develop a wearable type of application.
In Erica’s talk she mentioned a board called the MetaWear that seemed perfect for wearable applications. It’s small and the base unit has built-in Bluetooth radio, an accelerometer, temperature sensor, LED, switch, LiPo charging circuit, haptic driver, 4 digital/analog pins, 4 digital pins, GPIO support and can even act as a beacon. Also, you can simply use their Android or iOS API to program and read data from the board without having to write C++ sketches. All of that for a mere $45! Before the end of the talk, I had ordered a MetaWear. Soon thereafter, I began using it for projects and started doing conference talks that featured the board. MetaWear has since expanded their offerings to include boards with additional sensors.
Going Beyond iOS and Android
Most wearable devices will likely interface with an iOS or Android-based device, but developers doing Node.js and Windows development didn’t always have an easy way to communicate with, and use, these devices. That recently changed with the release of the C++ API, a C# wrapper, and Node.js NPM package. We’ve also been working on a Cordova plugin. The cool thing about the Node and Cordova efforts are that they are driven by enthusiasts in the community.
Getting Started
We have personally tested the Node.js package on MacOS, Ubuntu (running under Crouton in Chrome OS), and on a Raspberry Pi. It works great on all three platforms with a few minor tweaks. Note, however, that MetaWear uses Bluetooth 4.0 to communicate with other devices, so make sure that your device supports Bluetooth 4.0.
Mac OS
I tested the MetaWear board on a Mac that has Bluetooth 4.0 support. In theory, it would be possible to use a third party adapter, but you may need to tweak some settings. On a standard Mac is it really easy, assuming that you have a recent version of Node.
git clone git@github.com:brainexe/node-metawear.git
cd node-metawear
npm install
DEBUG="noble-device" node examples/all.js
Running this code snippet will clone the repo, install the Node modules and create a test app called all.js. If you have a MetaWear that is running (but not currently connected to another device), and within range of your Mac, you can expect to see the light on it start to flash and some sensor output on your terminal. If it doesn’t immediately work correctly, you may need to close and restart Node.
Ubuntu in Crouton under Chrome OS
Again, I conducted the test with a Chromebook Pixel LS that has built-in Bluetooth 4.0 support. It should, however, work on other machines.
sudo setcap cap_net_raw+eip $(eval readlink -f `which node`)
git clone git@github.com:brainexe/node-metawear.git
cd node-metawear
npm install
export DEBUG="noble-device"
host-dbus node examples/all.js
The main difference here is that you’ll need to run Node through host-dbus, since it’s accessing the Bluetooth adapter attached through Chrome OS.
Raspberry Pi Running Raspbien
Finally, I tested the board using a Pi Zero with a WiFi and BLE dongle. I opted to clone the Node repo and build it on the platform (yes, it does take a while). Once that was done, the rest was easy.
sudo setcap cap_net_raw+eip $(eval readlink -f `which node`)
git clone git@github.com:brainexe/node-metawear.git
cd node-metawear
npm install
export DEBUG="noble-device"
node examples/all.js
Personally, I consider Pi Zero to be the most interesting use for a Node.js integration with Metawear. Unlike previous Pi releases, it has a lower power consumption profile and a small size, which, in theory, might be useful when creating wearable devices that interact with MetaWear.
In Summary
Support for Node.js is still somewhat limited and it would require adding lots of additional features in order to go beyond basic experimentation. As with any open source project, if you want to see a specific feature implemented, you can always do it yourself and submit it as a pull request. If you’re interested in using Cordova/Phone Gap to interact with your MetaWear, be sure to look out for an upcoming blog post and introduction to using our library.