npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

bare-lwp3

v0.1.0

Published

LEGO Wireless Protocol 3 codec

Readme

[!IMPORTANT] This module is experimental. The API is subject to change and may break at any time.

bare-lwp3

LEGO Wireless Protocol 3 (Powered Up) codec. Pure functions: commands in, bytes out; hub notification bytes in, plain objects out. No Bluetooth inside - bring your own transport, for example bare-bluetooth.

npm i bare-lwp3

Usage

const lwp3 = require('bare-lwp3')

peripheral.write(characteristic, lwp3.startSpeed(lwp3.PORT_A, 50), false)

peripheral.on('notify', (c, data) => {
  console.log(lwp3.decode(data))
})

Scan for lwp3.SERVICE_UUID and write every message to lwp3.CHARACTERISTIC_UUID without response.

API

Encoders return a Uint8Array ready to write to the LWP3 characteristic. Ports are PORT_A to PORT_D.

const message = startSpeed(port, speed)

Run a motor at a regulated speed, -100 to 100.

const message = startPower(port, power)

Drive a motor with raw PWM power, -100 to 100. 0 lets the motor float.

const message = brake(port)

Actively brake a motor.

const message = startSpeedForTime(port, ms, speed)

Run at a regulated speed for ms milliseconds, then brake. The hub handles the timing.

const message = startSpeedForDegrees(port, degrees, speed)

Turn degrees in the direction of speed, then brake.

const message = gotoAbsolutePosition(port, position, speed)

Turn a motor to an angle in degrees and hold.

const message = connectVirtualPort(portA, portB)

Pair two motors into one virtual port. The hub replies with attachedIo (event 2) carrying the new port id.

const message = disconnectVirtualPort(port)

Split a virtual port back into its two motors.

const message = startSpeeds(port, speedA, speedB)

Run the two motors of a virtual port, synchronized by the hub.

const message = subscribe(port, mode)

Ask the hub to report a sensor mode on every change. Motor modes are MODE_SPEED, MODE_POSITION and MODE_ABSOLUTE_POSITION.

const message = unsubscribe(port, mode)

Stop the reports for a mode.

const message = requestBattery()

Ask for the battery level once.

const message = subscribeBattery()

Ask the hub to report the battery level on every change.

const message = unsubscribeBattery()

Stop the battery reports.

const message = led(port, color)

Set a hub LED (LED_OFF, LED_PINK, LED_PURPLE, LED_BLUE, LED_LIGHT_BLUE, LED_CYAN, LED_GREEN, LED_YELLOW, LED_ORANGE, LED_RED, LED_WHITE). LED_PORT is the built-in LED of the Technic hub; other hubs report theirs via attachedIo.

const message = switchOff()

Power the hub down.

const notification = decode(bytes)

Turn a hub notification into one of:

  • { type: 'battery', level } - percentage
  • { type: 'attachedIo', port, event, ioType } - device plugged (event 1) or unplugged (0); virtual port formed (event 2) adds ports, the two members
  • { type: 'portValue', port, value } - subscribed sensor value, e.g. motor position
  • { type: 'feedback', port, status } - command progress report
  • { type: 'error', command, code, reason } - hub rejected command; code is the raw byte, reason names it ('notRecognized', 'invalidUse', 'overcurrent', ..., 'unknown')
  • { type: 'hubProperty', property } / { type: 'unknown', id } - anything not decoded yet

Tested on the LEGO(R) Technic hub (88012); the LEGO Group publishes the protocol under the MIT license at lego.github.io/lego-ble-wireless-protocol-docs. See bare-lwp3-demo for a complete example.

License

Apache-2.0

LEGO(R) is a trademark of the LEGO Group of companies which does not sponsor, authorize or endorse this project.