Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including unifi-events with all npm packages installed. Try it out:

var unifiEvents = require("unifi-events")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

unifi-events v0.4.3

UniFi Events is a Node.js module that allows you to listen for events generated by a UniFi Controller.

UniFi Events

UniFi Events is a Node.js module that allows you to listen for events generated by a UniFi Controller.

Requirements

Installation

unifi-events can be installed using the following npm command:

npm install unifi-events

or yarn:

yarn add unifi-events

Example

const UnifiEvents = require('unifi-events')

let unifi = new UnifiEvents({
  controller: 'https://demo.ubnt.com',  // Required. The url of the UniFi Controller
  username: 'superadmin',               // Required.
  password: 'password',                 // Required.
  site: 'default',                      // Optional. The UniFi site to connect to, if not set will use the default site.
  rejectUnauthorized: true,             // Optional. Set to false if you don't have a valid SSL
  listen: true                          // Optional. Set to false if you don't want to listen for events
})

// Listen for users and guests connecting to the network
unifi.on('connected', (data) => {
  console.log(data)
})

// Listen for users and guests disconnecting from the network
unifi.on('disconnected', (data) => {
  console.log(data)
})

// Listen for any event
unifi.on('event', (data) => {
  console.log(data)
})

Events

In addition to the connect, disconnect and event event types, other UniFi event types are emitted using the UniFi Event Key ID.

This JSON file shows all possible events: https://demo.ubnt.com/manage/locales/en/eventStrings.json?v=5.4.11.2

Some events such as EVT_AD_LOGIN (Admin Login) are not emitted by the UniFi Controller.

Wireless User Events:

  • EVT_WU_Connected - Wireless User connected
  • EVT_WU_Disconnected - Wireless User disconnected
  • EVT_WU_ROAM - Wireless User roamed from one AP to another
  • EVT_WU_ROAM_RADIO - Wireless User changed channel on the same AP

Wireless Guest Events:

  • EVT_WG_Connected - Wireless Guest connected
  • EVT_WG_Disconnected - Wireless Guest disconnected
  • EVT_WG_ROAM - Wireless Guest roamed from one AP to another
  • EVT_WG_ROAM_RADIO - Wireless Guest changed channel on the same AP
  • EVT_WG_AUTHORIZATION_ENDED - Wireless Guest became unauthorised

LAN User Events:

  • EVT_LU_CONNECTED - LAN User connected to the network
  • EVT_LU_DISCONNECTED - LAN User disconnected from the network

LAN Guest Events:

  • EVT_LG_CONNECTED - LAN Guest connected to the network
  • EVT_LG_DISCONNECTED - LAN Guest disconnected from the network

Example listing for connections made to Guest Wireless networks only:

unifi.on('EVT_WG_Connected', (data) => {
  console.log(data)
})
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free