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

lv-cap

v1.1.2

Published

Package for interfacing with LV-CAP

Downloads

18

Readme

lv-cap

NPM package for interfacing with the Common Application Platform for Low Voltage Networks (LV-CAP). This README covers:

Overview

LV-CAP runs Docker containers which are controlled by a Container Manager (CM) via the MQTT protocol. This package is meant for developers creating node.js containers and handles LV-CAP requirements for:

  • Basic startup/shutdown procedures
  • MQTT management
  • Responding to commands/requests from the CM

Installation

npm install lv-cap

Example Usage

var lvcap = require('lv-cap');

var options = {
  containerId: 'vendor_appName_instance',
  keyPath: './private_key.pem',
  certPath: './certificate.pem'
  debug: true,
  rejectUnauthorized: true
};

var configurationCB = function (newConfig) {
  //run your application init code here

};

var shutdownCB = function () {
  //run your application shutdown code here
}

lvcap.init(options, configurationCB, shutdownCB);

API

lvcap.start(options, configurationCallback, [shutdownCallback])

Containers running on LV-CAP are required to connect to the CM and receive configuration before initializing any custom code. Thus, start must be the first code your container runs, with your specific init code inside of configurationCallback. The CM can send configuration multiple times, and the configurationCallback will be called each time; so make sure your init code is ready for this.

The arguments are:

  • options for connecting to the MQTT broker
    • containerId is the ID assigned to your container by the LV-CAP admin
    • keyPath: relative path to private key file
    • certPath: relative path to certificate file
    • debug: false, set to true if you want to console.log() events (optional)
    • rejectUnauthorized: false, set to true for production (optional)
  • configurationCallback is called when valid configuration is received from
    the CM. You can access this configuration at lvcap.config
  • shutdownCallback is called when a shutdown command is received and before
    the MQTT connection is closed. This is where you should perform any data cleanup necessary, subscriptions are automatically cleaned up.

lvcap.stop()

Manually shutdown the MQTT client and unsubscribe from all active subscriptions. This is what is called when a shutdown command is received from the CM.

lvcap.setStatus(status, [errorMessage], [callback])

Set a status, and publish it to the CM. Choose the appropriate status text from the enumerated list. For MSG_FAIL and MSG_ERR be sure to set errorMessage.

If you want to use a callback without an errorMessage, be sure to pass undefined as the second argument.

lvcap.publish(topic, message, [settings], [callback])

Publish a message to an MQTT topic, with optional settings passed directly to the MQTT package's publish function.

If you want to use a callback without changing default settings, be sure to pass {} as the third argument.

lvcap.pubError(error, [message], [callback])

Publish an error with an optional error message Choose the appropriate error text from the enumerated list.

If you want to use a callback without a message, be sure to pass undefined as the second argument.

lvcap.subscribe(topic, [onMessage], [callback])

Subscribe to an MQTT topic. onMessage is called with a message as its only argument when received on topic, the third argument is called on verification of a successful subscription.

You will not be able to subscribe to certain topics, as they are used by the CM:

'#', 'status/#', 'config/#', 'command/#'

If you resubscribe to the same topic, only the most recent onMessage callback will be triggered.

If you want to use a callback without an onMessage callback, be sure to pass undefined as the second argument.

lvcap.unsubscribe(topic, [callback])

Unsubscribe from an MQTT topic.

You will not be able to unsubscribe from certain topics, as they are used by the CM:

'#', 'status/#', 'config/#', 'command/#'

lvcap.cleanupSubs()

Manually unsubscribe and remove callbacks from all MQTT subscriptions made via lvcap.subscribe().

lvcap.config

A JS object containing the most recently received configuration from the CM.

lvcap.messages

An array containing all messages received from the MQTT broker that are from topics subscribed to via lvcap.subscribe() without any onMessage callbacks.

License

Apache 2.0