GithubHelp home page GithubHelp logo

entrylabs / ble-serialport Goto Github PK

View Code? Open in Web Editor NEW

This project forked from elin-moco/ble-serialport

1.0 3.0 0.0 866 KB

A virtual node-serialport implementation that uses BLE as the transport.

JavaScript 99.75% CSS 0.17% HTML 0.08%

ble-serialport's Introduction

BleSerialPort

A virtual node-serialport implementation that uses BLE as the transport.

Prerequisites

First you need git and node.js to clone this repo and install dependencies:

git clone https://github.com/elin-moco/ble-serialport
cd ble-serialport
npm install

Secondly, you'll need an Arduino board with BleShield added on top of it, put an LED on pin 7, connect Arduino to you computer, and upload this BleFirmataSketch firmware to it.

To use BLE to send/receive data to the device with firmata or Johnny Five, run below gulp tasks to browserify them like:

gulp build

You'll find the browserified scripts in build folder

Use with Johnny Five

Include Johnny Five bundle script in your html file:

  <script type="text/javascript" src="j5-bundle.js"></script>

To use with node.js, you'll need these two require statements:

var BleSerialPort = require('ble-serialport').SerialPort;
var five = require('johnny-five');

Then use it directly in your script:

var bsp = new BleSerialPort({address: 'd0:6a:cf:58:ee:bd'}); //put your device name or address here
bsp.connect().then(function() {
  var board = new five.Board({port: bsp, repl: false});
  board.on('ready', function() {
    var led = new five.Led(7);
    led.blink();
  });
});

And you should see the LED blinks once you have the webapp(page) opened.

Use with Firmata

Include the firmata bundle script in your html file:

  <script type="text/javascript" src="firmata-bundle.js"></script>

To use with node.js, you'll need these two require statements:

var BleSerialPort = require('ble-serialport').SerialPort;
var firmata = require('firmata');

Then use it directly in your script:

var bsp = new BleSerialPort({address: 'd0:6a:cf:58:ee:bd'}); //put your device name or address here
bsp.connect().then(function() {
  var board = new firmata.Board(sp);
  board.on('ready', function() {
    board.digitalWrite(7, board.HIGH);
  });
});

And you should see the LED on once you have the webapp(page) opened.

Runing Examples

For the fxos-j5 and cordova-j5 example, run following commands to copy bundle script to example/fxos-j5 directory:

gulp dist

For the fxos-j5 example, modify example/fxos-j5/fxos-j5.js for your device address.
Then install app via WebIDE.

For the node-j5 and node-firmata examples, just update the address and run with:

node node-firmata.js

or

node node-j.js

For the cordova-j5 example, See cordova-j5 readme file for instructions for initialization and deployment.

Support

Currently this implementation uses WebBluetooth V2 API on FxOS, which is still experimental and requires certified permissions for now.

For the hardware part, now only tested with Arduino+BleShield, might need some tweaks for different BLE modules.

See blue-yeast if you are interested in enabling this for other platforms.

ble-serialport's People

Contributors

elin-moco avatar evanxd avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.