sbrick-protocol

3.0.0 • Public • Published

david-dm

SBrick Protocol

Control your Lego SBrick creations from node.js!

I've written an article about this thing, read it here!

Requirements

An SBrick with Protocol 17, a device with node.js and a Bluetooth 4.x adapter, which is supported by noble.

Installation

npm install sbrick-protocol

Usage

const SBrick = require('sbrick-protocol');
var sbrick = null;

//scan for SBricks
SBrick.scanSBricks()
    .then((sbricks) => {
        if (sbricks.length > 0) {
            //connect to first SBrick
            sbrick = new SBrick(sbricks[0].uuid);
            return sbrick.connect();
        } else {
            throw new Error('no SBricks found');
        }
    })
    .then(() => {
        //start sbrick main loop
        return sbrick.start();
    })
    .then(() => {
        //subscribe to events
        sbrick.on('SBrick.voltage', (voltage) => {
            console.log('voltage', voltage);
        });
        
        sbrick.on('SBrick.temperature', (temperature) => {
            console.log('temperature', temperature);
        });

        
        //set channel 0 to full speed
        sbrick.channels[0].pwm = 255;
    })
    .catch(console.log);

See the complete interface in SBrick.js.

A fully functional, browser-based interface also available at node-sbrick-controller.

Commands not implemented yet

  • connection parameters
  • PWM counter
  • quick drive
  • SBrick Plus measurements

Readme

Keywords

Package Sidebar

Install

npm i sbrick-protocol

Weekly Downloads

0

Version

3.0.0

License

MIT

Unpacked Size

30.9 kB

Total Files

10

Last publish

Collaborators

  • zooli