How to use the node-unifi.Controller function in node-unifi

To help you get started, we’ve selected a few node-unifi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jacobalberty / find-lf-unifi-source / index.js View on Github external
if (err.code = 'ENOENT') {
        console.log(err);
        console.log('config.json missing or invalid, please see README.md');
        return;
    } else {
        throw err;
    }
}

var iVar;

// Objects containing lists of all previously registered access points and clients and the times they registered
var nodes = { };
var clients = { };

var controller = new unifi.Controller(config.unifi.addr, config.unifi.port);

function getStats() {
    controller.getClientDevices(config.unifi.site, function(error, data) {
        if (error) {
            console.log(`error: ${error}`);
            clearInterval(iVar);
            return;
        }
        var payloads = { };
        var timestamp = Date.now();
        data[0].forEach(function(client) {
            if (!client.is_wired) {
                if (payloads[client.ap_mac] == undefined) {
                    if (nodes[client.ap_mac] == undefined) {
                        console.log(`new node '${client.ap_mac}' online at ${timestamp}`);
                        nodes[client.ap_mac] = timestamp;
github jens-maus / ioBroker.unifi / main.js View on Github external
adapter.log.info('Starting UniFi-Controller query');

  var update_interval = parseInt(adapter.config.update_interval, 10) || 60;
  var controller_ip = adapter.config.controller_ip || "127.0.0.1";
  var controller_port = adapter.config.controller_port || 8443;
  var controller_username = adapter.config.controller_username || "admin";
  var controller_password = adapter.config.controller_password || "";

  adapter.log.info('update_interval = ' + update_interval);
  adapter.log.info('controller = ' + controller_ip + ':' + controller_port);

  // get unifi class
  var unifi = require('node-unifi');

  var controller = new unifi.Controller(controller_ip, controller_port);

  //////////////////////////////
  // LOGIN
  controller.login(controller_username, controller_password, function(err) {

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

    //////////////////////////////
    // GET SITE STATS
    controller.getSitesStats(function(err, site_data) {
      var sites = site_data.map(function(s) { return s.name; });
github tdack / unifi-parental / index.js View on Github external
port = nconf.get('server:port') || 4000
host = nconf.get('server:host') || '0.0.0.0'

const serverOptions = {
    key: fs.readFileSync(path.resolve(__dirname, './' + nconf.get('server:key'))),
    cert: fs.readFileSync(path.resolve(__dirname, './' + nconf.get('server:cert')))
}

nodeCleanup( (exitCode, signal) => {
    controller.logout()
    nconf.set('data', data)
    nconf.save()
    debug('Config saved')
})

controller = new unifi.Controller(nconf.get('controller:host'), nconf.get('controller:port'))

function controllerLogin(callback) {
    return controller.getSelf(nconf.get('controller:site'), (err, result) => {
        if (err == 'api.err.LoginRequired') {
            return controller.login(nconf.get('controller:user'), nconf.get('controller:password'), (err) => {
                if (err) {
                    debug('Login error: ', err)
                    return
                }
                callback()
            })
        } else {
            callback()
        }
    })
}

node-unifi

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

MIT
Latest version published 12 months ago

Package Health Score

62 / 100
Full package analysis

Popular node-unifi functions