An open API service indexing awesome lists of open source software.

https://github.com/hobbyquaker/node-movehub

Node.js interface for the Lego Boost Move Hub :robot: :cat: :guitar: :truck:
https://github.com/hobbyquaker/node-movehub

ble boost hub lego move node-module robotics

Last synced: 3 months ago
JSON representation

Node.js interface for the Lego Boost Move Hub :robot: :cat: :guitar: :truck:

Awesome Lists containing this project

README

        

# movehub

[![NPM version](https://badge.fury.io/js/movehub.svg)](http://badge.fury.io/js/movehub)
[![dependencies Status](https://david-dm.org/hobbyquaker/node-movehub/status.svg)](https://david-dm.org/hobbyquaker/node-movehub)
[![Build Status](https://travis-ci.org/hobbyquaker/node-movehub.svg?branch=master)](https://travis-ci.org/hobbyquaker/node-movehub)
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)
[![License][mit-badge]][mit-url]

> 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](test.js).

## API

## Classes


Boost


Hub


## Boost
**Kind**: global class

* [Boost](#Boost)
* [.connect(address, callback)](#Boost+connect)
* ["ble-ready" (bleReady)](#Boost+event_ble-ready)
* ["hub-found" (hub)](#Boost+event_hub-found)
* [.connectCallback](#Boost+connectCallback) : function

### boost.connect(address, callback)
**Kind**: instance method of [Boost](#Boost)

| Param | Type | Description |
| --- | --- | --- |
| address | string | MAC Address of the Hub |
| callback | [connectCallback](#Boost+connectCallback) | |

### "ble-ready" (bleReady)
**Kind**: event emitted by [Boost](#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](#Boost)

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

### boost.connectCallback : function
**Kind**: instance typedef of [Boost](#Boost)

| Param | Type | Description |
| --- | --- | --- |
| error | null \| error | |
| hub | [Hub](#Hub) | instance of the Hub Class |

## Hub
**Kind**: global class

* [Hub](#Hub)
* [.disconnect()](#Hub+disconnect)
* [.motorTime(port, seconds, [dutyCycle], [callback])](#Hub+motorTime)
* [.motorTimeMulti(seconds, dutyCycleA, dutyCycleB, callback)](#Hub+motorTimeMulti)
* [.motorAngle(port, angle, [dutyCycle], [callback])](#Hub+motorAngle)
* [.motorAngleMulti(angle, dutyCycleA, dutyCycleB, callback)](#Hub+motorAngleMulti)
* [.led(color, [callback])](#Hub+led)
* [.subscribe(port, [option], [callback])](#Hub+subscribe)
* [.unsubscribe(port, [option], [callback])](#Hub+unsubscribe)
* [.write(data, callback)](#Hub+write)
* ["rssi" (rssi)](#Hub+event_rssi)
* ["disconnect"](#Hub+event_disconnect)
* ["connect"](#Hub+event_connect)
* ["port" (port)](#Hub+event_port)
* ["color" (color)](#Hub+event_color)
* ["distance" (distance)](#Hub+event_distance)
* ["tilt" (tilt)](#Hub+event_tilt)
* ["rotation" (rotation)](#Hub+event_rotation)

### hub.disconnect()
Disconnect from Move Hub

**Kind**: instance method of [Hub](#Hub)

### hub.motorTime(port, seconds, [dutyCycle], [callback])
Run a motor for specific time

**Kind**: instance method of [Hub](#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](#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](#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](#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](#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](#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](#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](#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](#Hub)

| Param | Type |
| --- | --- |
| rssi | number |

### "disconnect"
**Kind**: event emitted by [Hub](#Hub)

### "connect"
Fires when a connection to the Move Hub is established

**Kind**: event emitted by [Hub](#Hub)

### "port" (port)
Fires on port changes

**Kind**: event emitted by [Hub](#Hub)

| Param | Type |
| --- | --- |
| port | object |
| port.port | string |
| port.action | string |

### "color" (color)
**Kind**: event emitted by [Hub](#Hub)

| Param | Type |
| --- | --- |
| color | string |

### "distance" (distance)
**Kind**: event emitted by [Hub](#Hub)

| Param | Type | Description |
| --- | --- | --- |
| distance | number | distance in millimeters |

### "tilt" (tilt)
**Kind**: event emitted by [Hub](#Hub)

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

### "rotation" (rotation)
**Kind**: event emitted by [Hub](#Hub)

| Param | Type |
| --- | --- |
| rotation | object |
| rotation.port | string |
| rotation.angle | |

## Contributing

Pull Requests welcome! :-)

## Credits

Thanks to [Jorge Pereira](https://github.com/JorgePe) 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

[mit-badge]: https://img.shields.io/badge/License-MIT-blue.svg?style=flat
[mit-url]: LICENSE