Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
WoCha-FR committed Nov 2, 2022
0 parents commit e5d676e
Show file tree
Hide file tree
Showing 18 changed files with 12,183 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"env": {
"es2021": true,
"node": true
},
"extends": "standard",
"overrides": [
],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
},
"plugins": [
"jest"
],
"ignorePatterns": ["jest.config.js"]
}
104 changes: 104 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: node_js

node_js:
- node
- lts/*

script:
- npm run lint
- npm run coveralls
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 WOCHA

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
103 changes: 103 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# mqtt4apcaccess

![npm](https://img.shields.io/npm/v/mqtt4apcaccess)
![License](https://img.shields.io/github/license/WoCha-FR/mqtt4apcaccess)
[![Build Status](https://app.travis-ci.com/WoCha-FR/mqtt4apcaccess.svg?branch=main)](https://app.travis-ci.com/WoCha-FR/mqtt4apcaccess)
[![Coverage Status](https://coveralls.io/repos/github/WoCha-FR/mqtt4apcaccess/badge.svg?branch=main)](https://coveralls.io/github/WoCha-FR/mqtt4apcaccess?branch=main)
![npm](https://img.shields.io/npm/dt/mqtt4apcaccess)

Publish values from apcaccess to MQTT

## Prerequisites

1. Apcacces binary installed *(eg: apt install apcupsd)*
2. An APC UPS Daemon has to run on a local or/and remote machine and has to be configured as network information server (NIS). For more information visit the apcupsd website.

* [APC UPS Daemon](http://www.apcupsd.org/) - The APC UPS Daemon
* [APC Access](http://www.apcupsd.org/manual/#apcaccess) - The apcaccess tool
* [APCUPSD NIS Example Configuration](http://www.apcupsd.org/manual/manual.html#nis-server-client-configuration-using-the-net-driver) - Howto configure the APCUPSD as NIS

## Installing

Simply install the package over npm. This will install all the required dependencies.

```
npm install -g mqtt4apcaccess
```

## Usage

```
Usage: mqtt4apcaccess [options]
Options:
-a, --ups-hosts upshost[:upsport] [array] [default: "127.0.0.1"]
-f, --poll-frequency frequency of polling in sec [number] [default: "5"]
-u, --mqtt-url mqtt broker url [default: "mqtt://127.0.0.1"]
-t, --mqtt-topic mqtt topic prefix [default: "apcaccess"]
-v, --log-verbosity possible values: "error", "warn", "info", "debug" [default: "info"]
-s, --ssl-verify allow ssl connections with invalid certs
--version Show version number [boolean]
-h, --help Show help [boolean]
```

### Example

#### Single UPS on localhost - mqtt broker on 192.168.5.1

```
mqtt4apcaccess -u mqtt://192.168.5.1
```

#### Two UPS in localnet - mqtt borker on localhost

```
mqtt4apcaccess -a 192.168.1.9 -a 192.168.1.10
```

## MQTT Frame Output

```
[apcaccess/UnRaid] {
apc: '001,034,0825',
date: '2022-09-28 14:18:39 +0200',
hostname: 'UnRaid',
upsname: 'UnRaid',
cable: 'USB Cable',
driver: 'USB UPS Driver',
upsmode: 'Stand Alone',
starttime: '2022-09-25 04:40:03 +0200',
model: 'Back-UPS ES 550G',
status: 'ONLINE',
linev: '234.0',
loadpct: '40.0',
bcharge: '100.0',
timeleft: '18.9',
mbattchg: '10',
mintimel: '10',
maxtime: '0',
sense: 'Medium',
lotrans: '180.0',
hitrans: '266.0',
alarmdel: '30',
battv: '13.6',
lastxfer: 'Low line voltage',
numxfers: '0',
tonbatt: '0',
cumonbatt: '0',
battdate: '2019-06-07',
nominv: '230',
nombattv: '12.0',
firmware: '870.O4 .I USB FW:O4'
}
```

## Versioning

mqtt4apcaccess is maintained under the [semantic versioning](https://semver.org/) guidelines.

See the [releases](https://github.com//releases) on this repository for changelog.

## License

This project is licensed under MIT License - see the [LICENSE](LICENSE.md) file for details
31 changes: 31 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env node
const config = require('./lib/config')
const logger = require('./lib/logs')
const MqttClient = require('./lib/mqtt')
const APCaccess = require('./lib/apcaccess')

/**
* Main function.
*/
async function main () {
const apcs = {}
logger.info('Starting mqtt4apcaccess')
logger.debug(JSON.stringify(config))
try {
// mqtt Client
const mqtt = new MqttClient(config.mqttUrl, config.mqttTopic, config.sslVerify)
await mqtt.connect()
// APCaccess hosts
for (let i = 0, len = config.upsHosts.length; i < len; i++) {
apcs[i] = new APCaccess(config.upsHosts[i], config.pollFrequency)
logger.info(`Get UPS data for ${config.upsHosts[i]}`)
await apcs[i].startPolling()
}
} catch (e) {
logger.error('Unable to run => See errors below')
logger.error(e)
process.exit(1)
}
}
// Call the main code
main()
12 changes: 12 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/configuration
*/
module.exports = {
// A list of reporter names that Jest uses when writing coverage reports
coverageReporters: ['lcov', 'text'],
// A list of paths to directories that Jest should use to search for files in
roots: ['./tests'],
// The paths to modules that run some code to configure or set up the testing environment before each test
setupFiles: ['./tests/setup.js']
}

0 comments on commit e5d676e

Please sign in to comment.