/node-unifi

NodeJS class for querying/controlling a UniFi-Controller (www.ubnt.com)

Primary LanguageJavaScriptMIT LicenseMIT

Logo

node-unifi

Build Status Code Climate bitHound Score NPM version Downloads Github Issues Donate

NPM

Node-UniFi is a NodeJS module that allows to query/control UniFi devices via the official UniFi-Controller API. It is developed to be compatible to the latest UniFi-Controller API version starting with v4.x.x/v5.x.x.

Features

  • Supports all UniFi-Controller API features introduced with v4.x.x and v5.x.x.
  • Returns all data in JSON parsable strings/objects.

Requirements

Installation

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

npm install node-unifi

Example

node-unifi has been designed to be used quite straight forward and without introducing ackward language constructs. The following example should give a brief introduction on how to use node-unifi in your own applications:

var unifi = require('node-unifi');

var controller = new unifi.Controller("127.0.0.1", 8443);

// LOGIN
controller.login("admin", "PASSWORD", function(err) {

  if(err) {
    console.log('ERROR: ' + err);
    return;
  }

  // GET SITE STATS
  controller.getSitesStats(function(err, sites) {
    console.log('getSitesStats: ' + sites[0].name + ' : ' + sites.length);
    console.log(JSON.stringify(sites));

    // GET SITE SYSINFO
    controller.getSiteSysinfo(sites[0].name, function(err, sysinfo) {
      console.log('getSiteSysinfo: ' + sysinfo.length);
      console.log(JSON.stringify(sysinfo));

      // GET CLIENT DEVICES
      controller.getClientDevices(sites[0].name, function(err, client_data) {
        console.log('getClientDevices: ' + client_data[0].length);
        console.log(JSON.stringify(client_data));

        // GET ALL USERS EVER CONNECTED
        controller.getAllUsers(sites[0].name, function(err, users_data) {
          console.log('getAllUsers: ' + users_data[0].length);
          console.log(JSON.stringify(users_data));

          // FINALIZE, LOGOUT AND FINISH
          controller.logout();
        });
      });
    });
  });
});

Please note that with every controller.XXXXX() function a callback function have to be specified which will be called with a potential error message and the result data (second argument) as soon as the request succeeded.

References

This nodejs package/class uses functionality/Know-How gathered from different third-party projects:

Use-Cases

The following projects are known to use this nodejs class for query/control UniFi devices:

License

The MIT License (MIT)

Copyright (c) 2017 Jens Maus <mail@jens-maus.de>

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.