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

humix-sense

v1.1.1

Published

Foundation for Humix-Sense modules

Downloads

12

Readme

Introduction

This module is part of Humix Framework. For more information about Humix project, please refer Humix Overview

Essentially, a humix-sense module is installed on edge devices (e.g. robot). It communicates with other modules and the local controller via NATS-based pub/sub messaging infrastructure. Each module provide the information it collects by publishing 'event', while it also listen for 'command' to trigger actions the module supports.

This module provides an event-driven model to facilitate the creation of Humix-Sense modules. Basically, you need to proivde a config that specify 1) the name of the module 2) the commands the module accepts 3) the event the module generates 4) any child process the module depends upon ( optional )

With these information, humix-sense module could automatically generate the namespace for each event generated and monitor the local message bus for incoming commands targeted for this module. In addition, the humix-sense module also facilitates life-cycle management of the sensor module: it register the module during start up, monitoring the health check events(e.g. Ping/Pong) and commands (e.g. Stop) from local contorller.

The goal is to simplify the effort required for new sensor modules to communicate with the rest of Humix components, including other sensor modules and Humix Think

How to get the code

You can either clone the project of this repository

git clone https://github.com/project-humix/node-humix-sense.git

or get the module from npm repository

npm install humix-sense

How to use

You can use this module to build a new sensor module for Humix. Here are the steps you needs:

  1. config your module
  2. register your module
  3. send events, if any
  4. receive commands, if any

Provide module information

The following code shows how to config your module and register it with Humix.


 // provide default config. If not provided, the module will lookup module.js in current dir to load the config

 var config = {

    // define the namespace of this module
    "moduleName":"test",

    // specify the commands to monitor
    "commands" : [ "command1", "command2"],

    // specify the local events to listen. These are generated by other modules on the edge.
    "localEvents: ["localEvent1", "localEvent2"];


    // specify the events that will be gneerated by this module.
    // If not specified, all events generated with event() function will be emitted
    "events" : ["event1","event2"],

    /*  default logger will contain 2 logger streams:
    *   - console stream
    *   - file stream, which create a file under ~/.humix/ directory
    *
    *   configurable options including
    *        - filename: specify the log file name
    *        - fileLevel: specify the log level of logger file, default is INFO
    *        - consoleLevel: specify the log level of console, default is INFO
    */

    "log" : {
        filename : 'humix-sample-module.log',
        fileLevel : 'info',
        consoleLevel : 'debug'
    }

    // (optional)
    // if the module is implemented using other language, specify the process to lunch here
    "childProcess" : {
        "name" : "./test/test.sh",
        "params" : "7",
        "respawn" : true,
        "restart" : 3
    },


 }


var humix = require('humix-sense')(config);,

Basically you pass the config to the humix-sense module. The module will then register the current sensor with local humix-sense-controller.

The next step is to wait for the confirmation from humix-sense-controller


 humix.on('connection', function(humixSensorModule){
       hsm = humixSensorModule;
 }

Generate events

Once you get the HumixSensorModule object, you can then generate events with simple syntax like:

 hsm.event('event1', 'Hello World');

Listen for commands

and now you can receive command by monitoring the registered commands:


hsm.on('command1', function(data){
    console.log('receive data');
});

Example

To get a feeling of how to write a new humix module, you can reference a Sample Humix Module

License

This module is released under Apache 2.0 license