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

mongoose-os-rpc

v0.2.0

Published

Node.js implementation of Mongoose OS' RPC protocol

Downloads

15

Readme

mongoose-os-rpc: a Node.js implementation of Mongoose OS' RPC protocol

mongoose-os-rpc is a client library that allows you to call remote functions (RPC) on devices which are running Mongoose OS (generally ESP8266). The library laverages Node's callbacks. Unconfirmed RPC calls will timeout and the caller will be notified about the failure.

Note: For instructions how to install and setup Mongoose OS, please visit the official site - https://mongoose-os.com/docs/quickstart/setup.html

Protocol support

This library implements the RPC protocol (JSON based) as described here: https://github.com/mongoose-os-libs/rpc-common

Transports

RPC packets are sent via a particular transport. Currently http, ws and mqtt are supported.

HTTP

The url format is: http://devideIpOrName/rpc

WS (WebSocket)

The url format is: ws://devideIpOrName/rpc

MQTT

The url format is: mqtt://devideIpOrName/deviceName

This transport requires a client id. If the clientId option was not specified a unique value will be generated. The RPC client will then subscribe to client-id/rpc topic, listening for replies.

Installing

npm install --save mongoose-os-rpc

Usage examples

Using Rpc class (automatic transport creation)


const Rpc = require("mongoose-os-rpc").Rpc;

// Instantiate Rpc object using the short format (specifying address property)
// The Rpc object will internally create an instance of an appropriate transport
let rpc = new Rpc({
  address: 'http://deviceIpOrName/rpc'
  // OR: address: 'ws://deviceIpOrName/rpc'
  // OR: address: 'mqtt://deviceIpOrName/esp8266_C6D764'  <-- In this case esp8266_C6D764 is device's name as configured in Mongoose OS
})

Manually creating a transport


const Rpc = require("mongoose-os-rpc").Rpc;
const HttpTransport = require("mongoose-os-rpc").HttpTransport;

let transport = new HttpTransport({
  address: 'http://deviceIpOrName/rpc'
});

let rpc = new Rpc({
  transport: transport
})

Calling FS.List function via http

const Rpc = require("mongoose-os-rpc").Rpc;

// Instantiate Rpc object using the short format (specifying address property)
// The Rpc object will internally create an instance of an appropriate transport
let rpc = new Rpc({
  address: 'http://deviceIpOrName/rpc'
  // OR: address: 'ws://deviceIpOrName/rpc'
  // OR: address: 'mqtt://deviceIpOrName/esp8266_C6D764'  <-- In this case esp8266_C6D764 is device's name as configured in Mongoose OS
});

// Subscribe for error events
rpc.on('error', function(){
  console.log("RPC ERROR");
  console.log(arguments);
})

// Subscribe for disconnect events
rpc.on('close', function() {
  console.log("RPC channel was closed!");
});

// Subscribe for connect events
// To distinguish between connect and reconnect use isReconnect() function
rpc.on('open', function() {
  console.log("RPC channel was opened!");

    if (!rpc.isReconnect()) {
      
      rpc.call("FS.List", {}, "", function(err, result, tag){
        
        console.log("CALLBACK (FS.List)");
        console.log(err);
        console.log(result);
        
        if (err) {
          // Oops, something went wrong
        } else {
          console.log(result)
        }
                
      });

    } else {
      console.log("The underlying transport had reconnected");
    }
    
});


TODO

  • Implement and test transport authentication
  • Implement tests