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

unifi-controller-utils

v1.0.0

Published

Management of Ubiquity UniFi Controller

Downloads

17

Readme

unifi-controller-utils

Management of Ubiquity UniFi Controller for WiFi Access points.

Installation

npm install unifi-controller-utils

Usage

'use strict'
const Unifi = require('unifi-controller-utils')
async function run(){
	const unifi = new Unifi(UNIFY_URL, UNIFY_USER, UNIFY_PASS, DEBUG)
	try{
    // list devices (Access Points)
		let devices = await unifi.devices()
		console.log(devices.length,'ACCESS POINTS:')
		for(let dev of devices) console.log(`IP: ${dev.ip}   MAC: ${dev.mac}   NAME: ${dev.name}`)

    // list stations (WiFi Clients)
		let stations = await unifi.stations()
		console.log('\n'+stations.length+' WIFI CLIENTS:')
		for(let sta of stations) console.log(`IP: ${sta.ip}   MAC: ${sta.mac}   USER ID: ${sta.user_id}   NAME: ${sta.name}`)

    // change station name
		await unifi.renameStation(stations[0].mac, 'Some new name...')

    // disconnect station
		await unifi.disconnectStation(stations[0].mac, 'Some new name...')
  }catch(e){
		console.error('Error getting stations: ', String(e))
	}
}

run()

API

require('unifi-controller-utils')

constructor(<string>url, <string>username, <string>password, <boolean>debug)

Creates new instance of Unifi controller class.

  • url - string - URL to access the Unifi server.

  • username - string - Username for authentication.

  • password - string - Password for authentication.

  • debug - boolean - If set to true, will console.log() network requests.

devices() - (Promise)

Returns list of Unifi devices (i.e. Access Points). Each devices is an object with many useful properties, see excerption on the sample below:

{
  "_id":       "69218764a29238721439bcde",
  "device_id": "69218764a29238721439bcde",
  "ip": "10.0.0.2",
  "mac": "ab:cd:12:34:56:78",
  "model": "U7NHD",
  "type": "uap",
  "version": "5.60.12.34567",
  "site_id": "28c64932876b9298c6749864",
  "gateway_mac": "a2:12:34:56:78:b3",
  "internet": true,
  "connected_at": 1641945697,
  "name": "Nano AP 3rd floor",
  "last_seen": 1642045697,
  "uptime": 3891,
  "system-stats": {
    "cpu": "1.9",
    "mem": "42.2",
    "uptime": "3891"
  },
  "startup_timestamp": 1641845697,
  "satisfaction": 99,
  "bytes-d": 16022,
  "tx_bytes-d": 10310,
  "rx_bytes-d": 5712,
  "bytes-r": 1232,
  "tx_bytes": 55323801004,
  "rx_bytes": 4037952922,
  "bytes": 59361753926,
  "num_sta": 3,
  "user-num_sta": 3,
  "user-wlan-num_sta": 3,
  "guest-num_sta": 0,
  "guest-wlan-num_sta": 0
}

stations() - (Promise)

Returns list of Unifi stations (i.e. WiFi clients). Each station is an object with many useful properties, see excerption on the sample below:

{
  "_id": "61c398c7021b374027a96210",
  "user_id": "61c398c7021b374027a96210",
  "site_id": "28c64932876b9298c6749864",
  "oui": "Manufacturer, ltd.",
  "mac": "18:55:e3:5b:6d:85",
  "ip": "10.0.0.33",
  "hostname": "My-Computer",
  "hostname_source": "uap",
  "is_guest": false,
  "is_wired": false,
  "assoc_time": 1640761576,
  "latest_assoc_time": 1640775604,
  "first_seen": 1640635552,
  "last_seen": 1640779989,
  "usergroup_id": "",
  "disconnect_timestamp": 1640725472,
  "_uptime_by_uap": 4386,
  "_last_seen_by_uap": 1640779989,
  "_is_guest_by_uap": false,
  "ap_mac": "ab:cd:12:34:56:78",
  "channel": 44,
  "radio": "na",
  "radio_name": "rai0",
  "essid": "myunifi",
  "bssid": "1e:b0:cd:34:56:11",
  "powersave_enabled": true,
  "is_11r": false,
  "ccq": 0,
  "rssi": 20,
  "noise": -96,
  "signal": -76,
  "tx_rate": 121000,
  "rx_rate": 240000,
  "tx_power": 0,
  "idletime": 15,
  "dhcpend_time": 120,
  "satisfaction": 98,
  "anomalies": 0,
  "tx_mcs": 6,
  "vlan": 0,
  "radio_proto": "ac",
  "uptime": 18413,
  "tx_bytes": 289784002,
  "rx_bytes": 17553222,
  "tx_packets": 271541,
  "rx_packets": 91249,
  "bytes-r": 0,
  "tx_bytes-r": 0,
  "rx_bytes-r": 0,
  "tx_retries": 29233,
  "wifi_tx_attempts": 212219,
  "authorized": true,
  "qos_policy_applied": true,
  "roam_count": 4
}

restartDevice(mac, site) - (Promise)

Restarts Access Point with given MAC address.

  • mac - string - MAC address of Unifi device (Access Point)

  • site - string - Optional name of Unifi site. Defaults to "default"

disconnectStation(mac, site) - (Promise)

Disconnects wifi client from Unifi network.

  • mac - string - MAC address of WiFi client

  • site - string - Optional name of Unifi site. Defaults to "default"

blockStation(mac, site) - (Promise)

Blocks wifi client from accessing Unifi network.

  • mac - string - MAC address of WiFi client

  • site - string - Optional name of Unifi site. Defaults to "default"

unblockStation(mac, site) - (Promise)

Un-blocks wifi client from accessing Unifi network.

  • mac - string - MAC address of WiFi client

  • site - string - Optional name of Unifi site. Defaults to "default"

forgetStation(mac, site) - (Promise)

Forgets wifi client from Unifi network.

  • mac - string - MAC address of WiFi client

  • site - string - Optional name of Unifi site. Defaults to "default"

renameStation(mac, name, site) - (Promise)

Sets name for wifi client within Unifi network.

  • mac - string - MAC address of WiFi client

  • name - string - Name for the WiFi client

  • site - string - Optional name of Unifi site. Defaults to "default"