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 🙏

© 2024 – Pkg Stats / Ryan Hefner

multiwii-msp

v0.0.3-beta-47

Published

NodeJS MultiWii Serial Protocol to send or receive commands from MultiWii via TCP/IP

Downloads

66

Readme

MultiWii Serial Protocol via TCP/IP

This package is for MultiWii multicopters to communicate with MSP protocol over TCP/IP protocol. The package contains two public object the TcpClient and TcpServer.

Features

  • Communication over TCP protocol
  • Support async and sync command calls
  • Command queue on client side
  • Priority command

Installation

Simply use npm with the following command:

npm install multiwii-msp

Usage

Server

The server can listen for multiple client connection. After first successful connection new Device instance is created. During connection server polling client for actual data (status, rawImu, rc, rawGps, compGps, attitude, altitude and analog). The polling interval is continuous.

Note: Device can handle maximum 255 commands simultaneously.

Sample code

var TcpServer = require('multiwii-msp').TcpServer;

// Create new TCP server on 3002 port and enable logging
var server = new TcpServer(3002, true);

// Register device's first connection
server.on('register', function (key, device) {
    
    // Register device's open event
    device.on('open', function () {
        // Do something
    });
    
    // Register device's update event
    device.on('update', function (data) {
        // Do something
    });
    
    // Register device's close event
    device.on('close', function () {
        // Do something
    });
});

Device

Device instance describe each MultiWii board. It has multiple methods that represent commands. The command can grouped in three groups:

  • getter - The getter commands return data from flight controller. The syntax is {command name}(options, callback), where options and callback are only optional parameters.

    • The options parameter is object of available options.
    • If callback parameter is not set, then command will execute synchronously otherwise, will execute as async call and result will pass to the callback function. The callback format is standard nodeJs callback, function(error, response){}.
  • setter - The setter command send some data to the flight controller. The syntax is {command name}(dataObject, options, callback), where dataObject is object that contains data for each command. The dataObject structure depends on individual command. The options and callback arguments are same as above.

  • special - The special commands no need parameters or return data from flight controller. The syntax is same as getters {command name}(options, callback).

In the following examples the ident command are used.

Sync and async command calls

// Synchronous way
var ident = device.ident();
// Do something with ident

// or

// Asynchronous way
device.ident({}, function (error, ident) {
    // Do something with ident
});

Priority call

You can call command in priority order. Queue on clients side send commands to serial port in order which are commands are in queue. The priority call put command to the beginning of queue, so command is executed nearly immediately.

// Send command as priority
var ident = device.ident({
  prior: true
});

Note: Default command calls are put on end of the queue.

Use cache

Commands response can stored in cache. It useful for example at boxNames, pidNames or ident commands, where response only change if flight control was changed. If response not found in cache, then command get it from flight controller, save to cache and return as response or add to callback.

// Get response from cache
var ident = device.ident({
  cache: true
});

Client

The client try connect to server. After connection is established, then client is waiting for data over TCP and send response, what received from MultiWii via serial port. If connection is lost then client try to reconnect to server.

var TcpClient = require('multiwii-msp').TcpClient;

// Create new client to connect to server via 192.168.0.1:3002 port,
// connect to serial pot via /dev/ttyAMA0 with 115200 baud rate and
// enable logging
var client = new TcpClient('192.168.0.1', 3002, '/dev/ttyAMA0', 115200, true);

Public api

The library api documentation should be something like this.

TcpServer

Tcp server inherits from node's EventEmitter.

Methods

TcpServer

This is object's constructor.

Parameters

Type | Parameter | Description ----------|-----------|------------------------------ int | port | Port number to listen boolean | log | Console log is enabled or not

Example

var server = new TcpServer(3002, true);
getDevice

Get device by key

Parameters

Type | Parameter | Description ---------|-----------|------------------------------ string | key | Device key

Returns

Returns null if device not found otherwise Device.

Example

var device = server.getDevice('192.168.1.1:3005');
hasDevice

Check if device exists with key

Parameters

Type | Parameter | Description ---------|-----------|------------------------------ string | key | Device key

Returns

Returns true if device with key exists, otherwise false.

Example

var exists = server.hasDevice('192.168.1.1:3005');
listDevices

List all devices registered by server.

Returns

Returns object with key-Device pairs.

Example

var devices = server.listDevices();

devices[key].ident(); // if device exists with "key"

Events

register

The register event fires when new client first time connected. It means if client reconnecting then this event not fires.

Event parameters

Type | Parameter | Description -------- |-----------|------------------------------------------- string | key | Newly connected device identifier Device | device | Device instance for newly connected device

Example

server.on('register', function (key, device) {
    // Do something
}

TcpClient

Device

License

This package is licensed under the MIT License