
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
This is a node.js module for the Lego WeDo 2.0 and Lego Boost set.
Since this module supports now Wedo 2.0, Boost & Power Up, the development continues with a new name: https://www.npmjs.com/package/wedoboostpoweredup
npm install wedoboostpoweredup
Once the wedo2 module is loaded, the module starts searching for devices (Wedo2 and Boost)
var Wedo2 = require('wedoboostpoweredup');
var wedo2 = new Wedo2();
If you want to search for a specific range of devices, you can add parts of their names as argument. The following example will search for devices that all have "lego" as part of their name.
var Wedo2 = require('WeDo2');
var wedo2 = new Wedo2("lego");
Boost allows setting the interval time between each sensor reading. It defines how often the Boost hub sends out messages. The default is 5.
var interval = 5;
var Wedo2 = require('WeDo2');
var wedo2 = new Wedo2("lego", interval);
All events emit the uuid from the device they have been placed from. The uuid is always the last argument.
If a new device is connected, it emits the "connected" event.
wedo2.on('connected', function (uuid) {
console.log('I found a device with uuid: '+uuid);
// Place getters and setters in here, to make sure that they are called,
// when the object is connectged
});
If a new device is disconnected, it emits the "connected" event.
wedo2.on('disconnected', function (uuid) {
console.log('I removed a device with uuid: '+uuid);
});
Battery status in %. uuid tells on which device the status was emitted.
wedo2.on('battery', function (status, uuid) {
console.log('Battery: ' + status + '% @ '+uuid);
});
If a distance sensor is connected, it will send its distance in the range of 0 and 10 (matching cm-scale) as well the port.
wedo2.on('distanceSensor', function (distance, port, uuid) {
console.log('distanceSensor: '+distance+' at port '+port + ' @ '+uuid);
});
If a tilt sensor is connected, it will send its tilt x and y in the range of -45 and 45 as well the port.
wedo2.on('tiltSensor', function (x,y, port, uuid) {
console.log('tilt sensor: '+x+' '+y+' at port '+port +' @ '+uuid);
});
If the device button on the controller is clicked, the following event is fired.
wedo2.on('button', function (button, uuid) {
console.log('button state: '+button + ' @ '+ uuid );
});
Every time a sensor or motor is connected and disconnected, the port event is fired.
wedo2.on('port', function (port, connected, type, uuid) {
if(connected){
console.log('Found '+type+' on port '+port+ ' @ '+ uuid );
} else {
console.log('Disconnected '+type+' on port '+port+ ' @ '+ uuid );
}
});
If the color vision sensor is connected, it will send RGB values representing the color luminance as well as the port.
wedo2.on('visionSensor', function (colorLuminance, port, uuid) {
console.log('Red: '+ colorLuminance.r+', Green: '+ colorLuminance.g+', Blue: '+ colorLuminance.b+' at port '+port + ' @ '+uuid);
});
If a tacho Motor is connected, it will emit exact rotation angles and rotation counts. The Boost set has two internal ports with two internal tacho Motors.
wedo2.on('motor', function (motorRotation, port, uuid) {
console.log('rotation angle: '+ motorRotation.rotationAngle +', rotation count: '+ motorRotation.rotationCount + ' at port '+port + ' @ '+uuid);
});
Without a uuid argument, all setters will set values for the first device found. If you use more then one device, you can reach the specific device via the uuid argument with the following methods.
uuid: You can hand over the exact uuid of an object.
name: Add the exact name of your device instead of the uuid. If two objects have the same name, the first match will count.
number: Add a number (0,1,2,...) instead of the uuid to set different devices.
Set the name of your device within the device. This name will be saved in your device until you rename it again. In case you use more than one device, this a good place to define names to differentiate specific devices.
wedo2.setDeviceName(yourName, (optional) uuid);
Set the Led color of the device controller to an RGB value. Each value is on the scale from 0-255. For example Red, Green Blue all set to 255 is white:
wedo2.setLedColor(r,g,b, (optional) uuid);
Set the motor speed, if a motor is connected.
(Optional) If you want to operate a motor on a specific port,
you can add the port number (1 or 2) after the speed.
Set the port to null to leave it blank in case you want to set the device.
wedo2.setMotor(speed, (optionl) port, (optional) uuid);
Play a sound on the build-in piezo speaker. The frequency of the sound is in kHz, and the length is in ms. [wedo only]
wedo2.setSound(frequency, length, (optional) uuid)
If you work with more then one device, you have the same uuid choices (nothing, uuid, name, number) as with the setters.
To get the name of your device.
wedo2.getDeviceName(function(name, uuid){
console.log("the device name is "+name+" @ "+uuid);
}, uuid);
Get the Signal strength of the device Bluetooth LE.
wedo2.getSignalStrength(function (err, signal, uuid) {
console.log('Signal: ' + signal + 'dBm'+ " @ "+uuid);
}, uuid);
Get and list all ports that have devices connected.
wedo2.getPortList(function (portlist, uuid) {
console.log(JSON.stringify(portlist));
}, uuid);
WeDo2.prototype.listPorts
Each device is saved in an object reachable via:
wedo2.wedo
In this object, new devices are saved with their uuid as key for the time that they are connected. If you know the uuid of your device, you can test its connection like so:
if(wedo2.wedo[uuid])
If you only know the name of the device or just a number in which order it was discovered (the first device will always have the number 0), then you can obtain the uuid with the following function. If no device uuid has been found, the response will be ```null``
var uuid = wedo2.getUuidFromInput(input)
Once you know that it is connected, you can read all kinds of stuff:
Name
wedo2.wedo[uuid].name
Type of connected items on ports
wedo2.wedo[uuid].port[1].type
And so on.
FAQs
A library for controlling the Lego WeDo 2.0
The npm package wedo2 receives a total of 91 weekly downloads. As such, wedo2 popularity was classified as not popular.
We found that wedo2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.