Giter Club home page Giter Club logo

node-movehub's Introduction

movehub

NPM version dependencies Status Build Status XO code style License

Node.js interface for the Lego Boost Move Hub ๐Ÿค– ๐Ÿฑ ๐ŸŽธ ๐Ÿšš

Install

$ npm install movehub

If you want to utilize the new async/await syntax see https://github.com/ttu/node-movehub-async which is based on this module.

Usage example

See test.js.

API

Classes

Boost
Hub

Boost

Kind: global class

boost.connect(address, callback)

Kind: instance method of Boost

Param Type Description
address string MAC Address of the Hub
callback connectCallback

"ble-ready" (bleReady)

Kind: event emitted by Boost

Param Type Description
bleReady boolean reports true/false when BLE is active

"hub-found" (hub)

Fires when a Move Hub is found

Kind: event emitted by Boost

Param Type
hub object
hub.uuid string
hub.address string
hub.localName string

boost.connectCallback : function

Kind: instance typedef of Boost

Param Type Description
error null | error
hub Hub instance of the Hub Class

Hub

Kind: global class

hub.disconnect()

Disconnect from Move Hub

Kind: instance method of Hub

hub.motorTime(port, seconds, [dutyCycle], [callback])

Run a motor for specific time

Kind: instance method of Hub

Param Type Default Description
port string | number possible string values: A, B, AB, C, D.
seconds number
[dutyCycle] number 100 motor power percentage from -100 to 100. If a negative value is given rotation is counterclockwise.
[callback] function

hub.motorTimeMulti(seconds, dutyCycleA, dutyCycleB, callback)

Run both motors (A and B) for specific time

Kind: instance method of Hub

Param Type Description
seconds number
dutyCycleA number motor power percentage from -100 to 100. If a negative value is given rotation is counterclockwise.
dutyCycleB number motor power percentage from -100 to 100. If a negative value is given rotation is counterclockwise.
callback function

hub.motorAngle(port, angle, [dutyCycle], [callback])

Turn a motor by specific angle

Kind: instance method of Hub

Param Type Default Description
port string | number possible string values: A, B, AB, C, D.
angle number degrees to turn from 0 to 2147483647
[dutyCycle] number 100 motor power percentage from -100 to 100. If a negative value is given rotation is counterclockwise.
[callback] function

hub.motorAngleMulti(angle, dutyCycleA, dutyCycleB, callback)

Turn both motors (A and B) by specific angle

Kind: instance method of Hub

Param Type Description
angle number degrees to turn from 0 to 2147483647
dutyCycleA number motor power percentage from -100 to 100. If a negative value is given rotation is counterclockwise.
dutyCycleB number motor power percentage from -100 to 100. If a negative value is given rotation is counterclockwise.
callback function

hub.led(color, [callback])

Control the LED on the Move Hub

Kind: instance method of Hub

Param Type Description
color boolean | number | string If set to boolean false the LED is switched off, if set to true the LED will be white. Possible string values: off, pink, purple, blue, lightblue, cyan, green, yellow, orange, red, white
[callback] function

hub.subscribe(port, [option], [callback])

Subscribe for sensor notifications

Kind: instance method of Hub

Param Type Default Description
port string | number e.g. call .subscribe('C') if you have your distance/color sensor on port C.
[option] number 0 Unknown meaning. Needs to be 0 for distance/color, 2 for motors, 8 for tilt
[callback] function

hub.unsubscribe(port, [option], [callback])

Unsubscribe from sensor notifications

Kind: instance method of Hub

Param Type Default Description
port string | number
[option] number 0 Unknown meaning. Needs to be 0 for distance/color, 2 for motors, 8 for tilt
[callback] function

hub.write(data, callback)

Send data over BLE

Kind: instance method of Hub

Param Type Description
data string | Buffer If a string is given it has to have hex bytes separated by spaces, e.g. 0a 01 c3 b2
callback function

"rssi" (rssi)

Kind: event emitted by Hub

Param Type
rssi number

"disconnect"

Kind: event emitted by Hub

"connect"

Fires when a connection to the Move Hub is established

Kind: event emitted by Hub

"port" (port)

Fires on port changes

Kind: event emitted by Hub

Param Type
port object
port.port string
port.action string

"color" (color)

Kind: event emitted by Hub

Param Type
color string

"distance" (distance)

Kind: event emitted by Hub

Param Type Description
distance number distance in millimeters

"tilt" (tilt)

Kind: event emitted by Hub

Param Type
tilt object
tilt.roll number
tilt.pitch number

"rotation" (rotation)

Kind: event emitted by Hub

Param Type
rotation object
rotation.port string
rotation.angle

Contributing

Pull Requests welcome! :-)

Credits

Thanks to Jorge Pereira who analyzed and documented the move hub ble protocol: https://github.com/JorgePe/BOOSTreveng

Disclaimer

LEGO and BOOST are Trademarks from The LEGO Company, which does not support (most probably doesn't even know about) this project. And of course I'm not responsible for any damage on your LEGO BOOST devices - use it at your own risk.

License

MIT (c) Sebastian Raff

node-movehub's People

Contributors

hobbyquaker avatar ttu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-movehub's Issues

Can't connect to the MOVE HUB

Hi,

I'm trying to run your test.js file with a move hub being advertised but my terminal is printing only ble-ready true.

Do i need to change any values on another file ? For instance the UUID in the devices you are looking for ?

Thank you so much in advance

fail

Hm, this looks amazing - doesnt seem to work here though...

yarn install
node test.js

ble-ready true

and then nothing happens. (yes, I clicked the connect btn on the boost)

node: v8.9.4
macos: 10.13

(Same happens with Wedo2, so it could be sth on my side...)

Thanks in advance!

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.