Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

metawear

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metawear

Official JavaScript SDK for MetaWear

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
82
decreased by-51.48%
Maintainers
1
Weekly downloads
 
Created
Source

MetaWear JavaScript SDK

JavaScript SDK for creating MetaWear apps that run on node.js or in the browser (web-bluetooth support not widespread yet, but growing). This is a thin wrapper around the MetaWear C++ API so you will find the C++ documentation and API reference useful. Also, check out the JavaScript examples.

Under the hood it uses Noble for Bluetooth Low Energy communications.

Install

Before getting started, you need to setup the prerequisites for Noble. While you are there, familiarize yourself with the reset of the README since there a few limitiations and other gotchas spelled out.

Then you can simply install the NPM module:

npm install metawear

Usage

Require the metawear package

var MetaWear = require('metawear');

Discover the first MetaWear device seen

MetaWear.discover(function (device) { ... }

Or a specific MAC address

MetaWear.discoverByAddress('cb:7d:c5:b0:20:8f', function(device) { ... }

There are other options too, documented in Noble Device

After that, you must connect to the device

device.connectAndSetUp(function (error) { ... }

At this point you can call any of the MetaWear API's, for example, you can blink the LED green

var pattern = new MetaWear.LedPattern();
MetaWear.mbl_mw_led_load_preset_pattern(pattern.ref(), MetaWear.LedPreset.BLINK);
MetaWear.mbl_mw_led_write_pattern(device.board, pattern.ref(), MetaWear.LedColor.GREEN);
MetaWear.mbl_mw_led_play(device.board);

Complete Example

var MetaWear = require('metawear');

MetaWear.discover(function (device) {
  device.connectAndSetUp(function (error) {
    var pattern = new MetaWear.LedPattern();
    MetaWear.mbl_mw_led_load_preset_pattern(pattern.ref(), MetaWear.LedPreset.BLINK);
    MetaWear.mbl_mw_led_write_pattern(device.board, pattern.ref(), MetaWear.LedColor.GREEN);
    MetaWear.mbl_mw_led_play(device.board);
    // After 5 seconds we reset the board to clear the LED, when we receive
    // a disconnect notice we know the reset is complete, so exit the program
    setTimeout(function () {
      device.on('disconnect', function () {
        process.exit(0);
      });
      MetaWear.mbl_mw_debug_reset(device.board);
    }, 5000);
  });
});

Keywords

FAQs

Package last updated on 11 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc