6. SDKs

Our free and open source SDKs allow developers to send commands to the board. These commands include accessing sensor data, setting up recordings, turning on LEDs and so on.

Language Best for: Details Documentation
Java Android Full SDK Developers
Swift Apple ObjC Wraper Developers
Objective-C Apple Full SDK Developers
C# Windows Full SDK Developers
C++ Linux Library Developers
Python Linux C++ Wrapper Developers
Node.JS / Javascript Web C++ Wrapper Developers

You can learn more about our SDKs on our developer page and get started with documentation, Github links, code examples and more.

The follow sub-sections are for developers who want to write their first App. You are expected to have an understanding of the language you will be coding in and to have a system setup to develop code.

Select the language you prefer and follow the appropriate tutorials.

6.1. Java

This tutorial will take you through your first Java App.

6.1.1. Prerequisites

If you are new to Android development, download Android Studio and enable debugging over USB on your Android device. You should be familiar with the Java language and know how to deploy apps before starting the Android Java tutorials.

6.1.2. Template App

For those who want to build a simple MetaWear app or are new to Android development, we have provided a template for creating MetaWear apps which we will be using in this guide. Download the Android template and import the project into Android Studio. All the code on this page will be added to the starter module.

Advanced developers building more complex apps can refer to the Android Documentation for explicit installation instructions of the MetaWear library.

6.1.2.1. Modules

MetaWear modules are sensors or peripherals that are on the board. Modules are represented by the Module interface and you retrieve references to them with the getModule function. The function may return null if the module is unsupported however all MetaWear boards have an accelerometer so we can safely assume the return value is non-null in this example.

In the onServiceConnected function, retrieve a reference to the Accelerometer module and configure the sensor.

private Accelerometer accelerometer;

@Override
public void onServiceConnected(ComponentName name, IBinder service) {
    metawear = ((BtleService.LocalBinder) service).getMetaWearBoard(settings.getBtDevice());

    accelerometer= metawear.getModule(Accelerometer.class);
    accelerometer.configure()
           .odr(25f)       // Set sampling frequency to 25Hz, or closest valid ODR
           .commit();
}

6.1.2.2. UI Elements

Next, add a start and stop button to the fragment layout defined in the fragment_device_setup.xml file.

<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:text="Start" android:id="@+id/acc_start"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentEnd="true" />

<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:text="Stop" android:id="@+id/acc_stop"
    android:layout_below="@+id/acc_start"
    android:layout_alignParentStart="true"
    android:layout_alignParentEnd="true" />

6.1.2.3. Data Stream

Switching back to the DeviceSetupActivityFragment class, override the onViewCreated function to add listeners for the start and stop buttons. The start button will setup a data route, subscribe to the data stream, and start the sensor. The stop button will stop the sensor and remove the data route.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    view.findViewById(R.id.acc_start).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            accelerometer.acceleration().addRouteAsync(new RouteBuilder() {
                @Override
                public void configure(RouteElement source) {
                    source.stream(new Subscriber() {
                        @Override
                        public void apply(Data data, Object... env) {
                            Log.i("MainActivity", data.value(Acceleration.class).toString());
                        }
                    });
                }
            }).continueWith(new Continuation<Route, Void>() {
                @Override
                    public Void then(Task<Route> task) throws Exception {
                        accelerometer.acceleration().start();
                        accelerometer.start();
                        return null;
                    }
            });
        }
    });
    view.findViewById(R.id.acc_stop).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            accelerometer.stop();
            accelerometer.acceleration().stop();
            metawear.tearDown();
        }
    });
}

6.1.2.4. Test the App

Load the app onto your Android device and connect to your board. Press the start button to see the acceleration data in Logcat.

6.1.3. Freefall App

The free fall tutorial showcases advanced features of the MetaWear by using the on-board data processing to convert raw accelerometer data into a free fall metric. We will be building the app from scratch following the instructions outlined in the Android SDK documentation.

Source code for this tutorial is available on GitHub.

6.1.3.1. Project Setup

We kick off the free fall tutorial by showing you how to setup your project to use the MetaWear Android SDK.

6.1.3.2. Bluetooth LE Connection

Part B shows you how to connect to your MetaWear using the Android SDK.

6.1.3.3. Accelerometer Data Stream

Part C sets up a data stream of accelerometer sending live data from the sensor to your mobile device.

6.1.3.4. Data Processor

Part D utilizes the firmware data processor to manipulate the raw acceleration data on-board. By using the on-board data procesor, you can perform simple computations on the data without having to transmit the raw data.

6.1.3.5. On-Board Logging

In the last segment of this tutorial, we use the logger to record when the free fall events happened, and download the data at a later time.

For a deeper dive into the Android SDK, checkout the documentation page for links to additional information about the MetaWear SDKs.

6.1.4. Event Handling

Say you want your MetaWear to react to different events, for example, turn on the LED when the switch is pressed and turn off the LED by tapping the board. This is easily accomplished in a data route using the stream component however, it requires that the board remains connected to your Android device at all times. Using the react component, we can instead program the board to respond to these events offline thus removing the need for an external app to handle the events for us.

6.1.4.1. Route Setup

Before we go around adding react components in our data route, first, lets create the route that uses the Android device to manage events.

metawear.getModule(Switch.class).state().addRouteAsync(new RouteBuilder() {
    @Override
    public void configure(RouteComponent source) {
        source.stream(new Subscriber() {
            @Override
            public void apply(Data data, Object... env) {
                if (data.value(Boolean.class)) {
                    led.editPattern(Led.Color.BLUE, Led.PatternPreset.SOLID).commit();
                    led.play();
                }
            }
        });
    }
}).onSuccessTask(new Continuation<Route, Task<Route>>() {
    @Override
    public Task<Route> then(Task<Route> task) throws Exception {
        return accBosch.tap().addRouteAsync(new RouteBuilder() {
            @Override
            public void configure(RouteComponent source) {
                source.stream(new Subscriber() {
                    @Override
                    public void apply(Data data, Object... env) {
                        led.stop(true);
                    }
                });
            }
        });
    }
});

From here, replace the stream components with react components. For brevity, only the route functions are in the code snippets with the first route corresponding to the switch data.

// Switch reaction route
source.react(new RouteComponent.Action() {
    @Override
    public void execute(DataToken token) {
        led.editPattern(Led.Color.BLUE, Led.PatternPreset.SOLID).commit();
        led.play();
    }
});

// Tap reaction route
source.react(new RouteComponent.Action() {
    @Override
    public void execute(DataToken token) {
        led.stop(true);
    }
});

As you may have noticed, the if statement from the streaming route is not present in the reaction route. This is because only MetaWear commands can be used inside a reaction, that is, no Java language constructs like loops and no functions that reside outside of the MetaWear SDK. The commands wrapped by the execute method are run whenever there is new data or activity from its input source, meaning our reaction based route actually turns on the LED whenever the button state changes i.e. when both a press and release are detected.

To remedy this small bug, we will insert a data processing component in between the switch source and reaction so that only button presses are reacted upon. In this case, we use the comparator filter to check for switch values not equal to 0 (1 = pressed, 0 = released).

Our data route now looks as follows:

metawear.getModule(Switch.class).state().addRouteAsync(new RouteBuilder() {
    @Override
    public void configure(RouteComponent source) {
        source.filter(Comparison.NEQ, 0).react(new RouteComponent.Action() {
            @Override
            public void execute(DataToken token) {
                led.editPattern(Led.Color.BLUE, Led.PatternPreset.SOLID).commit();
                led.play();
            }
        });
    }
}).onSuccessTask(new Continuation<Route, Task<Route>>() {
    @Override
    public Task<Route> then(Task<Route> task) throws Exception {
        return accBosch.tap().addRouteAsync(new RouteBuilder() {
            @Override
            public void configure(RouteComponent source) {
                source.react(new RouteComponent.Action() {
                    @Override
                    public void execute(DataToken token) {
                        led.stop(true);
                    }
                });
            }
        });
    }
});

6.1.4.2. Cleanup

The MetaWear firmware only has limited resources available for reaction commands and data processing. Before you disconnect from the board or reload the app, remember to remove the routes that were created by calling Route interface’s remove function on the Route objects returned by addRouteAsync.

6.2. Swift

This tutorial will take you through your first Swift App.

6.2.1. Prerequisites

Before we get started with code examples, you should be familiar with Swift, creating iOS apps, and using the MetaWear iOS app. If you are new to iOS development, download Xcode and use the new project template to build a Hello World app for your iOS device.

Note you can also build your apps in Objective-C, but it’s highly recommended to begin all new development in Swift.

6.2.2. Template App

For those who want to build a simple MetaWear app or are new to iOS development, we have provided a template for creating MetaWear apps that we will be using in this guide. Download the template open StarterProject/StarterProject.xcworkspace with Xcode.

Advanced developers building more complex apps can refer to the iOS Documentation for explicit installation instructions of the MetaWear SDK.

Download the StarterProject App Template.

6.2.2.1. Module

MetaWear modules are sensors or peripherals that are on the board. Modules are represented by the MBLModule interface and you retrieve references to them through properties on the MBLMetaWear object. Because each MetaWear model has different sensors, some properties may be nil.

First, open the DeviceViewController class and modify the viewWillAppear function to retrieve an Accelerometer module reference and configure the sensor.

override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated);

        device.addObserver(self, forKeyPath: "state", options: NSKeyValueObservingOptions.New, context: nil)
        device.connectWithHandler { error in
                NSLog("We are connected")

                if let accModule = self.device.accelerometer {
                        // Set the output data rate to 25Hz or closet valid value
                        accModule.sampleFrequency = 25.0
                } else {
                        NSLog("Sorry, no accelerometer");
                }
        }
}

6.2.2.2. UI Elements

Next, we will add a start and stop button using interface builder, so open up iOS/Main.storyboard. Then drag two buttons onto the Device View Controller and connect the buttons to DeviceViewController.swift. See Apple Docs for detailed instruction on this.

6.2.2.3. Data Stream

Switching back to the DeviceViewController class, lets fill in the startPressed and stopPressed functions. The start button will enable the accelerometer data stream. The stop button will disable the stream.

@IBAction func startPressed(sender: AnyObject) {
        device.accelerometer?.dataReadyEvent.startNotificationsWithHandlerAsync { (obj, error) in
                print(obj)
        }.success { result in
                print("Successfully subscribed")
        }.failure { error in
                print("Error on subscribe: \(error)")
        }
}

@IBAction func stopPressed(sender: AnyObject) {
        device.accelerometer?.dataReadyEvent.stopNotificationsAsync().success { result in
                print("Successfully unsubscribed")
        }.failure { error in
                print("Error on unsubscribe: \(error)")
        }
}

6.2.2.4. Test the App

Load the app onto your iOS device and connect to your board. Press the start button to see acceleration data being outputted to the log.

6.2.2.5. Next Steps

Once you have this sample code working, watch our iOS tutorial videos and try to create a MetaWear app from scratch.

For advanced developers wanting a deeper dive into the iOS SDK, checkout the documentation page for links to additional information about the SDK.

6.2.3. Persistent Events and Filters

6.2.3.1. Introduction

Today we are talking about MBLEvents and what happens when the MetaWear disconnects. Perhaps you have ran into the error “MetaWear[ERROR] attempted to communicate with disconnected device”, this post should help clear up what’s going on here.

6.2.3.2. Background Info

First a quick architecture review, the MBLMetaWear object is your digital representation of a physical MetaWear board. It contains all the logical methods for interacting with the device, such as connecting and disconnecting, in addition it contains pointers to MBLModule objects that encapsulate sensors and peripherals. These sensor objects then expose their actual data via pointers MBLEvent or MBLData objects.

When you call one of the convenience functions on MBLEvent or MBLData objects (startNotificationsAsync, readAsync, etc) it will internally trace back to its parent MBLMetaWear object and from there perform the physical BLE reads/writes. You can imagine holding a strong pointer to one of these MBLEvent or MBLData objects and then disconnecting the MetaWear. If you then use a convenience function, it will trace back and see the MBLMetaWear is disconnected and throw the “MetaWear[ERROR] attempted to communicate with disconnected device” error. What you need to do is instead is only access the MBLEvent or MBLData objects directly through a connected MBLMetaWear.

6.2.3.3. The Problem

What happens when you create your own MBLEvent’s using filters? The filters provide a powerful way to process raw sensor data directly on the MetaWear, but how do I access my custom events after a disconnect? After all, I had to create new MBLEvent objects using the filter functions and there are no builtin properties to access them…

6.2.3.4. The Solution

To solve this, we expose the same scheme used to save/restore the builtin event objects. This will conceptually be a user defined module. To get started you will create an object that implements the MBLRestorable interface, here is an example from our StarterProject:

6.2.3.5. The Implementation

First our configuration class:

class DeviceConfiguration: NSObject, MBLRestorable {
        // You must save any custom events/filters to @objc properties
        // for the auto save/restore feature to work properly
        @objc var temperatureFilter: MBLFilter<AnyObject>?

        public func run(onDeviceBoot device: MBLMetaWear) {
                // Create all custom filters in this function and assign to properties
                temperatureFilter = device.temperature?.onDieThermistor.periodicRead(withPeriod: 1000).changeOfEvent(byDelta: 1.0, output: .absolute)
                temperatureFilter?.startLoggingAsync()
        }
}

The run(onDeviceBoot:) function is where we put the relevant code to setup and populate our custom events.

The final part is associating this class with an MBLMetaWear instance. You just create an instance of your MBLRestorable object and pass it to the setConfigurationAsync function on MBLMetaWear:

device.setConfigurationAsync(DeviceConfiguration()).continueOnDispatch { t in
        if !t.isFaulted {
                // Programming successful!
        }
        return t
}

setConfigurationAsync is called once, and then you can use the configuration property on the MBLMetaWear to access your MBLRestorable object. It will be properly saved and restored through all future connects and disconnects.

if let configuration = device.configuration as? DeviceConfiguration {
        configuration.temperatureFilter?.downloadLogAndStopLoggingAsync(false).success { array in
        }
}

6.2.3.6. Conclusion

In order to access custom MBLEvents across connect/disconnect cycles that are not simple properties on built-in modules, you need to create a MBLRestorable class and assign it to the desired MBLMetaWear object. Then you can freely connect and disconnect but still access your custom events through the MBLMetaWear configuration property.

6.3. C#

This tutorial will take you through your first C# App.

6.3.1. Prerequisites

If you are new to Windows 10 development, first download Visual Studio 2017 and ensure your dev machine is updated to the Creator’s Update. You should be familiar with the C# language and know how to deploy apps before starting the Win10 C# tutorials.

Don’t forget to keep the C# documentation handy as it can provide additional code examples and context to help you better understand what the tutorials are saying.

6.3.2. Template App

For those who want to build a simple MetaWear app or are new to Android development, we have provided a template for creating MetaWear apps which we will be using in this guide. Download the C# Tutorial and import the solution into Visual Studio. All the code on this page will be added to the StarterApp project.

Advanced developers building more complex apps can refer to the C# Documentation for explicit installation instructions of the MetaWear library.

6.3.2.1. XAML Layout

The first thing we will do is add two buttons to the DeviceSetup.xaml file that start and stop the accelerometer.

<Button x:Name="accStart" Content="Start" HorizontalAlignment="Stretch" Margin="10,10,10,0"
        VerticalAlignment="Top" Click="accStart_Click"/>
<Button x:Name="accStop" Content="Stop" HorizontalAlignment="Stretch" Margin="10,47,10,0"
        VerticalAlignment="Top" Click="accStop_Click"/>

6.3.2.2. Data Stream

Open the DeviceSetup.xaml.cs file and implement the button click callback functions. The accStart_Click button will subscribe to the acceleration data signal and start the accelerometer whereas the accStop_Click will stop the data stream.

private async void accStart_Click(object sender, RoutedEventArgs e) {
    var accelerometer = metawear.GetModule<IAccelerometer>();

    accelerometer.Configure(odr: 25f);
    await accelerometer.Acceleration.AddRouteAsync(source => source.Stream(data =>
        System.Diagnostics.Debug.WriteLine(data.Value<Acceleration>())
    ));
    accelerometer.Acceleration.Start();
    accelerometer.Start();
}

private void accStop_Click(object sender, RoutedEventArgs e) {
    var accelerometer = metawear.GetModule<IAccelerometer>();

    accelerometer.Stop();
    accelerometer.Acceleration.Stop();
    metawear.TearDown();
}

6.3.2.3. Test the App

Load the app onto your Windows 10 device, select your board from the devices list, and press the start button to see acceleration data being outputted to the debug console.

6.3.3. FreeFall App

The FreeFall Detector app showcases how to use advanced firmware features such as data processing and logging. While we currently do not have videos availble that go through the app’s construction, the Java free fall videos should sufficiently explain how to use the aforementioned features as the C# SDK heavily mirrors the Java SDK.

6.4. C++

If compiled as a shared library, this can be used with any language that supports calling C functions from a shared library, such as Node and Python. The library only constructs the bytes for communicating with the MetaWear platform, it does not contain any Bluetooth LE code. Users will need to fill in the appropriate Bluetooth LE functions for their target platform.

6.4.1. Build

Building the project has been tested on *nix systems with Clang 4, and on Windows with Visual Studio Community 2017.

> clang++ --version
clang version 4.0.1 (tags/RELEASE_401/final 305264)
Target: x86_64-unknown-linux-gnu

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community>cl.exe
Microsoft (R) C/C++ Optimizing Compiler Version 19.10.25019 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]

6.4.2. GCC and Clang

Linux users can build the project by invoking GNU make; the default action is to build the shared library for your current platform. You can also change the C++ compiler by overriding the CXX make variable.

> make

# build using g++ as the compiler
> make CXX=g++

Upon a successful compile, the library will be placed in the newly created “dist” directory.

> make
> tree dist
dist/
└── release
    └── lib
        └── x64
            ├── libmetawear.so -> libmetawear.so.0
            ├── libmetawear.so.0 -> libmetawear.so.0.12.1
            └── libmetawear.so.0.12.1

6.4.3. Visual Studio 2017

MSBuild files have been provided to build the project as both a Win32 and WinRT dll. The Win32 dll is for classic Win32 applications whereas the WinRT dll is for Universal Windows apps. You will need to have Visual Studio 2017 installed in order to run the build.

When calling MSBuild, you can set the Configuration and Platform properties to control debug/release builds and x86/x64/ARM platforms respectively. If not specified on the command line, the default action is to build a debug dll targeting the x86 (Win32) platform. Note that the ARM platform is only available for the WinRT build.

# default properties are debug config with x86 (win32) platform
msbuild MetaWear.Win32.vcxproj

# release build for Win32 applications targeting the x64 architecture
msbuild MetaWear.Win32.vcxproj /p:Configuration=Release;Platform=x64

# debug build for WinRT applications targeting the ARM architecture
msbuild MetaWear.WinRT.vcxproj /p:Configuration=Debug;Platform=ARM

As with the Makefile, the .dll, .lib, .pdb, and .exp files are placed in the dist directory.

> tree dist
dist/
└── release
    └── lib
        └── x64
            ├── MetaWear.Win32.dll
            ├── MetaWear.Win32.exp
            ├── MetaWear.Win32.iobj
            ├── MetaWear.Win32.ipdb
            ├── MetaWear.Win32.lib
            └── MetaWear.Win32.pdb

6.4.4. Testing

Unit tests for the library are written in Python (min v3.4.1) and can be invoked by calling the test target (Test for MSBuild).

> make test
python3 -m unittest discover -s test
................................................................................
................................................................................
................................................................................
................................................................................
...........s....................................................................
.........................
----------------------------------------------------------------------
Ran 425 tests in 22.388s

OK (skipped=1)

6.4.5. MSBuild

When testing with MSBuild, it is important that the Platform property matches the installed Python’s target platform as well. For example, if 64-bit Python is installed, set the Platform property to x64 when running the Test target otherwise MSBuild will use the x86 dll which will cause all of the tests to fail.

metawear-cpp-api>msbuild MetaWear.Win32.vcxproj /p:Platform=x64 /t:Test

6.5. Python

Python SDK for creating MetaWear apps on the Linux platform. 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 scripts in the GitHub examples folder for full sample code.

6.5.1. Install

Use pip to install the metawear package. It depends on pygattlib so ensure your Linux environment first has the necessary dependencies installed.

pip install metawear --process-dependency-links

6.5.2. Usage

Import the MetaWear class and libmetawear variable from the metawear module and everything from the cbindings module.

from mbientlab.metawear import MetaWear, libmetawear
from mbientlab.metawear.cbindings import *

If you do not know the MAC address of your device, use pygattlib to scan for nearby devices.

from gattlib import DiscoveryService
service = DiscoveryService("hci0")
devices = service.discover(2)

# grab the first scanned device
address = devices.items()[0][0]

Once you have the device’s MAC address, create a MetaWear object with the MAC address and connect to the device.

device = MetaWear(address)
status = device.connect()

Upon a successful connection, you can begin calling any of the functions from the C++ SDK, for example, blinking the LED green.

pattern= LedPattern(repeat_count= Const.LED_REPEAT_INDEFINITELY)
libmetawear.mbl_mw_led_load_preset_pattern(byref(pattern), LedPreset.BLINK)
libmetawear.mbl_mw_led_write_pattern(device.board, byref(pattern), LedColor.GREEN)
libmetawear.mbl_mw_led_play(device.board)

6.6. JavaScript

This tutorial will set you up to run the examples in our Node SDK.

6.6.1. Prerequisites

To get started, get your Linux or similar environment up and running (commands may change based on your environment):

  1. Git
  2. Noble
  3. Node
  4. Dependencies

Full instructions are available on the MetaHub tutorial page to setup a Raspbian / RaspberryPi device.

6.6.2. Adding MetaWear to your Node Application

Simply install the NPM module:

>>> npm install metawear

To use, simply 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 SDK’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);
        });
});

6.6.3. First App

Please check out the example code and README of the Javascript Github page: https://github.com/mbientlab/MetaWear-SDK-JavaScript:

>>> git clone --recursive https://github.com/mbientlab/MetaWear-SDK-JavaScript

Then install the project (this will build the CPP libraries and Node metawear module)

>>> npm install

You can now navigate to the examples folder and run any example using the command:

>>> node led.js

The LED example will cause the led to blink green a few times. You can try to run the other examples in the examples directory and build on top of them.

6.6.4. Notes

A few notes:

  1. You may have to run the examples using sudo node led.js.
  2. You may have to change the first line in the code from var MetaWear = require('../index') to require('metawear'); or vice versa depending on how you are running your project.

3. The best way to use the metawear module is using the MAC address of your device: MetaWear.discoverByAddress('cb:7d:c5:b0:20:8f', function(device). You can find your MAC address by following the steps in the MAC section of the tutorial. 4. Make sure you have ssh access to Github.

If you run into issues with npm and your build, these websites can help:

  1. https://www.bitpi.co/2015/02/11/how-to-change-raspberry-pis-swapfile-size-on-rasbian/
  2. https://docs.npmjs.com/getting-started/installing-npm-packages-globally
  3. https://docs.npmjs.com/getting-started/fixing-npm-permissions
  4. http://www.competa.com/blog/how-to-run-npm-without-sudo/
  5. https://help.github.com/articles/connecting-to-github-with-ssh/

6.7. Build your own MetaHub

It is possible to build your own version of MetaHub by compiling the source files on the right device. We provide this tutorial as an example, but no official suppport will be given for homebrew products.

  1. Install the Raspbian OS on an SD card:

    Follow the instructions in the previous section link to boot and setup your MetaHub.

  2. Change settings (such as the keyboard layout):

    Use the GUI:

    >>> sudo raspi-config
    
  3. Add Wifi:

    Follow these RaspberryPi Instructions.

    Update packages:

    >>> sudo apt-get update
    

    Install GIT:

    >>> sudo apt-get install git
    

    Install pip:

    >>> sudo apt-get install python-pip
    

    Install Bluetooth dependencies:

    >>> sudo apt-get install pkg-config libboost-python-dev libboost-thread-dev libbluetooth-dev libglib2.0-dev python-dev build-essential python-dev
    

    Install Bluetooth libraries:

    >>> pip install pygatt
    >>> pip install pybluez[ble]
    

    Install Node:

    >>> sudo apt-get install -y build-essential
    >>> curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
    >>> sudo apt-get install -y nodejs
    

    Alternatively, for Node.js 8:

    >>> curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
    >>> sudo apt-get install -y nodejs
    
  4. Choose the most fitting Meta SDK repositories on Github:

  5. Clone the repositories of the Meta SDK you want to use:

    Make sure you are comfortable with GIT:

    >>> git clone REPO_NAME
    
  6. Go to the SDK part of the tutorial or get started by looking at the example code in the repository you just downloaded.