Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

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

install

npm i sbrick-protocol

Downloadsweekly downloads

2

version

3.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability