Class: WeDo2SmartHub

WeDo2SmartHub()

new WeDo2SmartHub()

The WeDo2SmartHub is emitted if the discovered device is a WeDo 2.0 Smart Hub.
Source:

Extends

Members

(readonly) batteryLevel

Properties:
Name Type Description
batteryLevel number Battery level of the hub (Percentage between 0-100)
Inherited From:
Source:

(readonly) firmwareVersion

Properties:
Name Type Description
firmwareVersion string Firmware version of the hub
Inherited From:
Source:

(readonly) name

Properties:
Name Type Description
name string Name of the hub
Inherited From:
Source:

(readonly) rssi

Properties:
Name Type Description
rssi number Signal strength of the hub
Inherited From:
Source:

(readonly) uuid

Properties:
Name Type Description
uuid string UUID of the hub
Inherited From:
Source:

Methods

connect() → {Promise}

Connect to the Hub.
Overrides:
Source:
Returns:
Resolved upon successful connect.
Type
Promise

disconnect() → {Promise}

Disconnect the Hub.
Inherited From:
Source:
Returns:
Resolved upon successful disconnect.
Type
Promise

getHubType() → {HubType}

Get the hub type.
Inherited From:
Source:
Returns:
Type
HubType

getPortDeviceType(port) → {DeviceType}

Get the device type for a given port.
Parameters:
Name Type Description
port string
Inherited From:
Source:
Returns:
Type
DeviceType

hardStopMotor(port) → {Promise}

Fully (hard) stop the motor on a given port.
Parameters:
Name Type Description
port string
Source:
Returns:
Resolved upon successful completion of command.
Type
Promise

playTone(frequency, time) → {Promise}

Play a tone on the Hub's in-built buzzer
Parameters:
Name Type Description
frequency number
time number How long the tone should play for (in milliseconds).
Source:
Returns:
Resolved upon successful completion of command (ie. once the tone has finished playing).
Type
Promise

rampMotorSpeed(port, fromSpeed, toSpeed, time) → {Promise}

Ramp the motor speed on a given port.
Parameters:
Name Type Description
port string
fromSpeed number For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.
toSpeed number For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.
time number How long the ramp should last (in milliseconds).
Source:
Returns:
Resolved upon successful completion of command.
Type
Promise

setLEDColor(color) → {Promise}

Set the color of the LED on the Hub via a color value.
Parameters:
Name Type Description
color Color
Source:
Returns:
Resolved upon successful issuance of command.
Type
Promise

setLEDRGB(red, green, blue) → {Promise}

Set the color of the LED on the Hub via RGB values.
Parameters:
Name Type Description
red number
green number
blue number
Source:
Returns:
Resolved upon successful issuance of command.
Type
Promise

setLightBrightness(port, brightness, timeopt) → {Promise}

Set the light brightness on a given port.
Parameters:
Name Type Attributes Description
port string
brightness number Brightness value between 0-100 (0 is off)
time number <optional>
How long to turn the light on (in milliseconds). Leave empty to turn the light on indefinitely.
Source:
Returns:
Resolved upon successful completion of command. If time is specified, this is once the light is turned off.
Type
Promise

setMotorSpeed(port, speed, timeopt) → {Promise}

Set the motor speed on a given port.
Parameters:
Name Type Attributes Description
port string
speed number For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.
time number <optional>
How long to activate the motor for (in milliseconds). Leave empty to turn the motor on indefinitely.
Source:
Returns:
Resolved upon successful completion of command. If time is specified, this is once the motor is finished.
Type
Promise

setName(name) → {Promise}

Set the name of the Hub.
Parameters:
Name Type Description
name string New name of the hub (14 characters or less, ASCII only).
Source:
Returns:
Resolved upon successful issuance of command.
Type
Promise

sleep(delay) → {Promise}

Sleep a given amount of time. This is a helper method to make it easier to add delays into a chain of commands.
Parameters:
Name Type Description
delay number How long to sleep (in milliseconds).
Inherited From:
Source:
Returns:
Resolved after the delay is finished.
Type
Promise

subscribe(port, modeopt) → {Promise}

Subscribe to sensor notifications on a given port.
Parameters:
Name Type Attributes Description
port string
mode number <optional>
The sensor mode to activate. If no mode is provided, the default for that sensor will be chosen.
Inherited From:
Source:
Returns:
Resolved upon successful issuance of command.
Type
Promise

unsubscribe(port) → {Promise}

Unsubscribe to sensor notifications on a given port.
Parameters:
Name Type Description
port string
Inherited From:
Source:
Returns:
Resolved upon successful issuance of command.
Type
Promise

wait(commands) → {Promise}

Wait until a given list of concurrently running commands are complete. This is a helper method to make it easier to wait for concurrent commands to complete.
Parameters:
Name Type Description
commands Array.<Promise.<any>> Array of executing commands.
Inherited From:
Source:
Returns:
Resolved after the commands are finished.
Type
Promise

Events

attach

Emits when a motor or sensor is attached to the Hub.
Parameters:
Name Type Description
port string
type DeviceType
Inherited From:
Source:

button

Emits when a button is pressed.
Parameters:
Name Type Description
button string
state ButtonState
Source:

color

Emits when a color sensor is activated.
Parameters:
Name Type Description
port string
color Color
Source:

detach

Emits when an attached motor or sensor is detached from the Hub.
Parameters:
Name Type Description
port string
Inherited From:
Source:

distance

Emits when a distance sensor is activated.
Parameters:
Name Type Description
port string
distance number Distance, in millimeters.
Source:

rotate

Emits when a rotation sensor is activated.
Parameters:
Name Type Description
port string
rotation number
Source:

tilt

Emits when a tilt sensor is activated.
Parameters:
Name Type Description
port string
x number
y number
Source: