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

apcaccess

v1.1.2

Published

apcaccess client library and cli written in node.js

Downloads

73

Readme

apcaccess client library and cli written in node.js

npm version

NPM

This is a node.js implementation of an apcupsd nis client. The module comes with a command line interface and a library you can use in your projects.

Prerequisites

An APC UPS Daemon has to run on a local or remote machine and has to be configured as network information server (NIS). For more information visit the apcupsd website.

Command Line Interface

These instructions will help you to install and use the command line interface on your local machine.

Installing

Simply install the package globally over npm. This will create a symlink in your bin folder and installs all the required dependencies.

npm install -g apcaccess

Usage

Usage:
  apcaccessjs [OPTIONS] <command> [ARGS]

Options:
  -H, --host [STRING]    Hostname or ip address of the apcupsd nis (Default is localhost)
  -p, --port [NUMBER]    Port of the apcupsd nis (Default is 3551)
  -h, --help             Display help and usage details

Commands:
  events, status, statusJson

Library

A short introduction and example how to use the apcaccess library. The library uses Promises.

Examples

Create a client and connect to server

var ApcAccess = require('apcaccess');
var client = new ApcAccess();

client.connect('localhost', 3551)
  .then(function() {
    console.log('Connected');
  })
  .catch(function(err) {
    console.log(err);
  })

Request the status and disconnect

var ApcAccess = require('apcaccess');
var client = new ApcAccess();

client.connect('localhost', 3551)
  .then(function() {
    return client.status();
  })
  .then(function(result) {
    console.log(result)
    return client.disconnect();
  })
  .then(function() {
    console.log('Disconnected');
  })
  .catch(function(err) {
    console.log(err);
  })  

Output:

APC      : 001,034,0839
DATE     : 2017-04-30 13:41:04 +0200  
HOSTNAME : alarmpi
VERSION  : 3.14.14 (31 May 2016) unknown
UPSNAME  : alarmpi
CABLE    : USB Cable
DRIVER   : USB UPS Driver
UPSMODE  : Stand Alone
STARTTIME: 2017-04-28 12:04:47 +0200  
MODEL    : Back-UPS ES 700G
STATUS   : ONLINE
LINEV    : 232.0 Volts
LOADPCT  : 5.0 Percent
BCHARGE  : 100.0 Percent
TIMELEFT : 36.4 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME  : 0 Seconds
SENSE    : Medium
LOTRANS  : 180.0 Volts
HITRANS  : 266.0 Volts
ALARMDEL : 30 Seconds
BATTV    : 13.5 Volts
LASTXFER : Unacceptable line voltage changes
NUMXFERS : 0
TONBATT  : 0 Seconds
CUMONBATT: 0 Seconds
XOFFBATT : N/A
STATFLAG : 0x05000008
SERIALNO : 5B1325T16968  
BATTDATE : 2013-06-23
NOMINV   : 230 Volts
NOMBATTV : 12.0 Volts
FIRMWARE : 871.O2 .I USB FW:O2
END APC  : 2017-04-30 13:41:26 +0200  

Request events and disconnect

var ApcAccess = require('apcaccess');
var client = new ApcAccess();

client.connect('localhost', 3551)
  .then(function() {
    return client.events();
  })
  .then(function(result) {
    console.log(result)
    return client.disconnect();
  })
  .then(function() {
    console.log('Disconnected');
  })
  .catch(function(err) {
    console.log(err);
  })  

Output:

2017-04-28 12:01:15 +0200  Cannot create /run/apcupsd/LCK.. serial port lock file: ERR=No such file or directory
2017-04-28 12:01:15 +0200  apcupsd FATAL ERROR in apcupsd.c at line 221
Unable to create UPS lock file.
  If apcupsd or apctest is already running,
  please stop it and run this program again.
2017-04-28 12:01:15 +0200  apcupsd error shutdown completed
2017-04-28 12:01:35 +0200  Cannot create /run/apcupsd/LCK.. serial port lock file: ERR=No such file or directory
2017-04-28 12:01:35 +0200  apcupsd FATAL ERROR in apcupsd.c at line 221
Unable to create UPS lock file.
  If apcupsd or apctest is already running,
  please stop it and run this program again.
2017-04-28 12:01:35 +0200  apcupsd error shutdown completed
2017-04-28 12:04:47 +0200  apcupsd 3.14.14 (31 May 2016) unknown startup succeeded

Request status as JSON and disconnect

var ApcAccess = require('apcaccess');
var client = new ApcAccess();

client.connect('localhost', 3551)
  .then(function() {
    return client.statusJson();
  })
  .then(function(result) {
    console.log(result)
    return client.disconnect();
  })
  .then(function() {
    console.log('Disconnected');
  })
  .catch(function(err) {
    console.log(err);
  })  

Output:

{ APC: '001,034,0839',
  DATE: '2017-04-30 13:47:07 +0200  ',
  HOSTNAME: 'alarmpi',
  VERSION: '3.14.14 (31 May 2016) unknown',
  UPSNAME: 'alarmpi',
  CABLE: 'USB Cable',
  DRIVER: 'USB UPS Driver',
  UPSMODE: 'Stand Alone',
  STARTTIME: '2017-04-28 12:04:47 +0200  ',
  MODEL: 'Back-UPS ES 700G ',
  STATUS: 'ONLINE ',
  LINEV: '232.0 Volts',
  LOADPCT: '5.0 Percent',
  BCHARGE: '100.0 Percent',
  TIMELEFT: '36.4 Minutes',
  MBATTCHG: '5 Percent',
  MINTIMEL: '3 Minutes',
  MAXTIME: '0 Seconds',
  SENSE: 'Medium',
  LOTRANS: '180.0 Volts',
  HITRANS: '266.0 Volts',
  ALARMDEL: '30 Seconds',
  BATTV: '13.5 Volts',
  LASTXFER: 'Unacceptable line voltage changes',
  NUMXFERS: '0',
  TONBATT: '0 Seconds',
  CUMONBATT: '0 Seconds',
  XOFFBATT: 'N/A',
  STATFLAG: '0x05000008',
  SERIALNO: '5B1325T16968  ',
  BATTDATE: '2013-06-23',
  NOMINV: '230 Volts',
  NOMBATTV: '12.0 Volts',
  FIRMWARE: '871.O2 .I USB FW:O2',
  'END APC': '2017-04-30 13:47:10 +0200  ' }

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details