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

rainfall

v0.1.3

Published

API implementation of the Rainfall protocol, used in home automation

Downloads

19

Readme

#Rainfall

API implementation of the Rainfall protocol, used in home automation. This application protocol can use almost any netowrk infrastructure to communicate (see the drivers folder and check out which network protocol are already supported). The protocol is designed to provide a common language for all devices in your home communicate and it envolves three node classes:

Sensor

This node sends collected data to the controller.

Actuator

This node receives commands from the controller and eventually sends to the controller commands received from other sources.

Controller

This node controls all the sensors and actuators in the network, they only communicate with this node and do not between each other.

Actually, the protocol is flexible enough to let you define a node as both a sensor and an actuator.

##Documentation For documentation on how to use the API, refer to this

##Usage First of all you need to choose which driver you'll use, and then instantiate it:

const Driver = require('my-driver');
Driver.createDriver({/*driver params*/}, (err, driver) => {
  //Check for errors
  if (err) throw err;
  //At this point we have a valid driver
});

Then, we instantiate the Rainfall, passing the driver object to it:

const Rainfall = require('rainfall');

var rainfall = new Rainfall.Rainfall(driver);

The complete initialization would be something like this:

const Driver = require('my-driver');
const Rainfall = require('rainfall');
Driver.createDriver({/*driver params*/}, (err, driver) => {
  if (err) throw err;
  var rainfall = new Rainfall.Rainfall(driver);
  //We can start using rainfall here
});

With the rainfall object we can send messages:

rainfall.send({/*Destination Address, depends on driver */}, 
  { /*THE MESSAGE */ }, (err) => {
    //This function will be called when the message was sent or not sent due to an error 
    //(available in the err variable)
  }
);

With the rainfall object we can listen for messages:

rainfall.listen((msg, from) => {
    //Called when a message arrives, msg contains the message and from contains the address of the sender
  }, /* Here you can define which packageTypes you want to listen (or null for all)*/,
     /* Here you can define which addresses you want to listen (or null for all)*/,
  (err) => {
    //This callback is called when the rainfall is actually listening (can take some time due to
    //driver implementation). If there is an error, the error is in the err variable
  }
);

With the rainfall object we can broadcast messages:

rainfall.sendBroadcast({ /*THE MESSAGE */ }, (err) => {
    //This function will be called when the message was sent or not sent due to an error 
    //(available in the err variable)
  }
);

We can also stop listeners:

rainfall.stopListen(/* Here you can define which packageTypes you want to stop listening (or null for all)*/);

And of course, we can shutdown the role thing:

rainfall.close();

##Examples In the examples below, we will use the TCP driver.

###Discovering Controller This example asks who is controller and waits for response

const Driver = require('rainfall-tcp');
const Rainfall = require('rainfall');
Driver.createDriver({ }, (err, driver) => {
  if (err) throw err;
  var rainfall = new Rainfall.Rainfall(driver);
  rainfall.listen((msg, from) => {
    console.log("I am controller received. The controller is in the address: " + from +
      " and my id is " + msg.yourId);
    //Returns false to stop listening
    return false;
  }, 'iamcontroller', null, (err) => {
    rainfall.sendBroadcast({ packageType: 'whoiscontroller' });
  });
});

###Answering who is the controller This example asks who is controller and waits for response

const Driver = require('rainfall-tcp');
const Rainfall = require('rainfall');
Driver.createDriver({ udplisten: true }, (err, driver) => {
  if (err) throw err;
  var rainfall = new Rainfall.Rainfall(driver);
  rainfall.listen((msg, from) => {
    console.log("Who is controller received from: " + from);
    //Answers question
    rainfall.send(from, { packageType: 'iamcontroller', yourId: 1 });
  }, 'whoiscontroller');
});