{"id":18330361,"url":"https://github.com/mbientlab/metawear-sdk-javascript","last_synced_at":"2025-04-06T01:33:05.717Z","repository":{"id":40005460,"uuid":"96940683","full_name":"mbientlab/MetaWear-SDK-JavaScript","owner":"mbientlab","description":"MetaWear JavaScript SDK - Linux - Node.JS","archived":false,"fork":false,"pushed_at":"2023-07-11T14:16:46.000Z","size":366,"stargazers_count":32,"open_issues_count":4,"forks_count":20,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-21T15:42:19.559Z","etag":null,"topics":["bluetooth-le","browser","javascript","metamotion","metawear","metawear-sdk","noble","nodejs"],"latest_commit_sha":null,"homepage":"https://mbientlab.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mbientlab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-11T21:58:10.000Z","updated_at":"2024-08-20T07:55:19.000Z","dependencies_parsed_at":"2023-01-31T15:31:06.872Z","dependency_job_id":null,"html_url":"https://github.com/mbientlab/MetaWear-SDK-JavaScript","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbientlab%2FMetaWear-SDK-JavaScript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbientlab%2FMetaWear-SDK-JavaScript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbientlab%2FMetaWear-SDK-JavaScript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbientlab%2FMetaWear-SDK-JavaScript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mbientlab","download_url":"https://codeload.github.com/mbientlab/MetaWear-SDK-JavaScript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247423497,"owners_count":20936622,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bluetooth-le","browser","javascript","metamotion","metawear","metawear-sdk","noble","nodejs"],"created_at":"2024-11-05T19:22:08.410Z","updated_at":"2025-04-06T01:33:03.762Z","avatar_url":"https://github.com/mbientlab.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MetaWear SDK for Javascript by MBIENTLAB\n\n[![Platforms](https://img.shields.io/badge/platform-linux%20-lightgrey?style=flat)](https://github.com/mbientlab/MetaWear-SDK-JavaScript)\n[![License](https://img.shields.io/cocoapods/l/MetaWear.svg?style=flat)](https://github.com/mbientlab/MetaWear-SDK-JavaScript/blob/master/LICENSE.md)\n[![Version](https://img.shields.io/badge/node-%2012-brightgreen?style=flat)](https://github.com/mbientlab/MetaWear-SDK-JavaScript)\n\n![alt tag](https://raw.githubusercontent.com/mbientlab/MetaWear-SDK-iOS-macOS-tvOS/master/Images/Metawear.png)\n\nSDK for creating MetaWear apps that run on node.js. Supported on Linux only.  \n\nThis 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.  \n\nAlso, check out the JavaScript [examples](https://github.com/mbientlab/MetaWear-SDK-JavaScript/tree/master/examples). \n\nUnder 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 using the @abandonware release.\n\n\u003e Only Node 12 on Linux is supported for release 1.2.0\n\n## Getting Started\n\n### Pre-Installation\n\n#### Node and NPM\nYou 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.\n\nWe are currently supporting Node 12 only (`node-ffi` does not work on higher node versions -- this will be addressed in future releases). \n\nHere are steps to install Node on Linux (Ubuntu). You have 3 options:\n\n##### 1. You can install Node from the repositories:\n```\nsudo apt install nodejs\nsudo apt install npm\nnodejs -v\n```\nThis will install the latest Node. You may need to alias nodejs to node.\n\n##### 2. You can install Node from a PPA:\n```\ncd ~\ncurl -sL https://deb.nodesource.com/setup_12.x -o nodesource_setup.sh\nsudo bash nodesource_setup.sh\nsudo apt install nodejs\nnodejs -v\n```\nThis will install node v12. You may need to alias nodejs to node.\n\n##### 3. Using NVM (preferred method):\n```\ncurl -sL https://raw.githubusercontent.com/creationix/nvm/v0.35.3/install.sh -o install_nvm.sh\nbash install_nvm.sh\nsource ~/.profile\nnvm install 12\nnvm use 12\nnode -v\n```\nCheck the latest version of NVM before you install (it might be higher than v0.35.3).\n\n##### Using sudo - a Warning\nIt 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)\n\nYou also need to check that the version of node you are using is as expected for sudo:\n```\n$ node -v\nv12.22.10\n$ sudo node -v\nv12.22.10\n```\nAs 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```\nn=$(which node); \\\nn=${n%/bin/node}; \\\nchmod -R 755 $n/bin/*; \\\nsudo cp -r $n/{bin,lib,share} /usr/local\n```\n\n##### Using bluez, BLE Dongles, and Node\nBluez 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)\n\nIf you are not using a BLE dongle, you need to make sure your system is working and supports Bluetooth 4.0+.\n\nIf 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. There is an example of how to specify a dongle in the example folder.\n\n### Installation\nYou have three options for installation:\n\n#### 1. Use NPM\nThe 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. \n\nYou 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.\n\nThen you can simply install the MetaWear package lib with NPM using the command line: \n```\nnpm install metawear\n```\nThis 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.\n```\nnpm update metawear\n```\n\n#### 2. Use our Repository \nYou can install the metawear package straight from our repository by using:\n```\nnpm install https://github.com/mbientlab/MetaWear-SDK-JavaScript.git\n```\nThis step takes a long time as all the packages are installed and the MetaWear CPP library will be compiled on your machine.\n\n#### 3. Clone our Repository \nWe packaged everything for you already in this repository -- see `package.json`.\n\nMake sure that when you clone this repository, that you clone the `MetaWear-SDK-Cpp` submodule with it.\n```\ngit clone --recurse-submodules https://github.com/mbientlab/MetaWear-SDK-JavaScript.git\ncd MetaWear-SDK-JavaScript\nnpm install\n```\n\nThe installation step takes some time to install the packages and compile the C++ code in the submodule.\n\n#### Errors and Issues\nIf 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 Bluetooth Low Energy compliant. \n\nIf 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.\n\nIf you cloned the repo:\n```\ncd MetaWear-SDK-Cpp/\nmake\n```\nIf you ran an npm command:\n```\ncd node_modules/metawear\ncd MetaWear-SDK-Cpp/\nmake\n```\n\n#### Running your first Script\nOnce the install is successful, you can run our example scripts in the example folder (see the example folder in our repository):\n```javascript\nnode led.js\n```\n\nPlease note that depending on your node and npm installation, you may need to run sudo (or use `su -`):\n```javascript\nsudo node led.js\n```\n\nPlease note that the examples in our examples folder will use the local metawear libraries (as this repository is meant for development):\n```javascript\nvar MetaWear = require('../index')\n```\nThis is pointing to the local metawear Node.JS code.\n\nSimply change it to this if using `metawear` as a package (dependency) in your own app:\n```javascript\nvar MetaWear = require('metawear');\n```\nThis means metawear would be installed as a dependency in the `node_modules` directory of your app.\n\n#### Notes\nYou should familiarize yourself with our tutorials since there a few limitiations and other gotchas spelled out, such as the maximum number of simultaneous Bluetooth connections. \n\n### Usage\nRequire the metawear package:\n```javascript\nvar MetaWear = require('metawear');\n```\n\nDiscover the first MetaWear device seen:\n```javascript\nMetaWear.discover(function (device) { ... }\n```\n\nOr connect to a device with a specific MAC address:\n```javascript\nMetaWear.discoverByAddress('cb:7d:c5:b0:20:8f', function(device) { ... }\n```\nThere are other options too, documented in [Noble Device](https://github.com/mbientlab/noble-device#discovery-api)\n\nAfter that, you must connect to the device and init:\n```javascript\ndevice.connectAndSetUp(function (error) { ... }\n```\n\nAt this point you can call any of the MetaWear API's, for example, you can blink the LED green\n```javascript\nvar pattern = new MetaWear.LedPattern();\nMetaWear.mbl_mw_led_load_p_pattern(pattern.ref(), MetaWear.LedPreset.BLINK);\nMetaWear.mbl_mw_led_write_pattern(device.board, pattern.ref(), MetaWear.LedColor.GREEN);\nMetaWear.mbl_mw_led_play(device.board);\n```\n\n### Example\n```javascript\nvar MetaWear = require('metawear');\n\nMetaWear.discover(function (device) {\n  device.connectAndSetUp(function (error) {\n    var pattern = new MetaWear.LedPattern();\n    MetaWear.mbl_mw_led_load_preset_pattern(pattern.ref(), MetaWear.LedPreset.BLINK);\n    MetaWear.mbl_mw_led_write_pattern(device.board, pattern.ref(), MetaWear.LedColor.GREEN);\n    MetaWear.mbl_mw_led_play(device.board);\n    // After 5 seconds we reset the board to clear the LED, when we receive\n    // a disconnect notice we know the reset is complete, so exit the program\n    setTimeout(function () {\n      device.on('disconnect', function () {\n        process.exit(0);\n      });\n      MetaWear.mbl_mw_debug_reset(device.board);\n    }, 5000);\n  });\n});\n```\n\n### Tutorials\nTutorials can be found [here](https://mbientlab.com/tutorials/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbientlab%2Fmetawear-sdk-javascript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmbientlab%2Fmetawear-sdk-javascript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbientlab%2Fmetawear-sdk-javascript/lists"}