{"id":18330355,"url":"https://github.com/mbientlab/metawear-usb-javascript","last_synced_at":"2025-04-09T17:44:12.517Z","repository":{"id":81787912,"uuid":"390193955","full_name":"mbientlab/MetaWear-USB-JavaScript","owner":"mbientlab","description":"MetaWear Javascript SDK - USB","archived":false,"fork":false,"pushed_at":"2021-12-13T00:18:53.000Z","size":243,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-15T10:32:52.666Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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":"2021-07-28T03:01:17.000Z","updated_at":"2022-05-29T19:04:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"111b0d10-eed2-4bb9-9dec-ab27cb9dba4a","html_url":"https://github.com/mbientlab/MetaWear-USB-JavaScript","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbientlab%2FMetaWear-USB-JavaScript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbientlab%2FMetaWear-USB-JavaScript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbientlab%2FMetaWear-USB-JavaScript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbientlab%2FMetaWear-USB-JavaScript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mbientlab","download_url":"https://codeload.github.com/mbientlab/MetaWear-USB-JavaScript/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248080335,"owners_count":21044485,"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":[],"created_at":"2024-11-05T19:22:05.498Z","updated_at":"2025-04-09T17:44:12.492Z","avatar_url":"https://github.com/mbientlab.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MetaWear USB Driver for Javascript by MBIENTLAB\n\n[![Platforms](https://img.shields.io/badge/platform-linux%20%7C%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-%3D%2010.23.0-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\nUSB Driver to interact with the MetaWear board using Javascrip and a USB cable (NO BLUETOOTH).\n\n### Overview\n\n[MetaWear](https://mbientlab.com) is a complete development and production platform for wearable and connected device applications.\n\nMetaWear 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!\n\nThe MetaWear hardware comes pre-loaded with a wirelessly upgradeable firmware, so it keeps getting more powerful over time.\n\n### Requirements\n- [MetaWear board](https://mbientlab.com/store/)\n- A linux machine with Bluetooth 4.0/5.0\n\n### License\nSee the [License](https://github.com/mbientlab/MetaWear-SDK-JavaScript/blob/master/LICENSE.md).\n\n### Support\nReach out to the [community](https://mbientlab.com/community/) if you encounter any problems, or just want to chat :)\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 10.23.0. Here 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_10.x -o nodesource_setup.sh\nsudo bash nodesource_setup.sh\nsudo apt install nodejs\nnodejs -v\n```\nThis 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.\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 10.23.0\nnvm use 10.23.0\nnode -v\n```\nCheck 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.\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\nv0.10.23\n$ sudo node -v\nv0.11.8-pre\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\nAt the time of this release, Node 10 is supported. Node 12 is not currently supported as `node-ffi` and some other libraries have not been updated.\nWe have to use a custom fork of node-ffi until then (see package.json). Hopefully node-ffi will be updated to support Node 10 and Node 12 officially.\n\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 or later (Bluetooth low energy).\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.\n\nThis may or may not work on arm64. Works on armhf and raspberryPi 3 and RaspberryPi 4.\n\n### Installation\n\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 with the package.json file ready to be installed with npm.\n\nMake sure that when you clone this repository, that you clone the submodule with it.\n```\ngit clone --recurse-submodules https://github.com/mbientlab/MetaWear-SDK-JavaScript.git\n```\n\nThen you can simply install all the dependencies you need by building the npm project with command line: \n```javascript\nnpm install\n```\nThis step takes a long time as all the packages are installed and the MetaWear CPP library will be compiled as well.\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 bluetoothLE compliant. Follow the errors and correct them as indicated by the npm output log.\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.\nIf you cloned the repo:\n```\ncd MetaWear-SDK-Cpp/\nmake\n```\nIf you ran an npm command:\n```\ncd node_modules/\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:\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 using the local metawear code.\n\nSimply change it to this:\n```javascript\nvar MetaWear = require('metawear');\n```\nThis would be using the metawear code in your local npm `node_modules` directory as installed with npn.\n\n#### Notes\nYou 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. \n\n### Usage\nRequire the metawear package\n\n```javascript\nvar MetaWear = require('metawear');\n```\nDiscover the first MetaWear device seen\n```javascript\nMetaWear.discover(function (device) { ... }\n```\n\nOr 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\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-usb-javascript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmbientlab%2Fmetawear-usb-javascript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbientlab%2Fmetawear-usb-javascript/lists"}