How to use the @iobroker/adapter-core.controllerDir function in @iobroker/adapter-core

To help you get started, we’ve selected a few @iobroker/adapter-core 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 ioBroker / ioBroker.history / main.js View on Github external
/* jshint -W097 */// jshint strict:false
/*jslint node: true */
'use strict';
const cp          = require('child_process');
const utils       = require('@iobroker/adapter-core'); // Get common adapter utils
const path        = require('path');
const dataDir     = path.normalize(utils.controllerDir + '/' + require(utils.controllerDir + '/lib/tools').getDefaultDataDir());
const fs          = require('fs');
const GetHistory  = require('./lib/getHistory.js');
const Aggregate   = require('./lib/aggregate.js');
const adapterName = require('./package.json').name.split('.').pop();

const history    = {};
const aliasMap   = {};
let subscribeAll = false;
let bufferChecker = null;
const tasksStart = [];
let finished   = false;

let adapter;
function startAdapter(options) {
    options = options || {};
github iobroker-community-adapters / ioBroker.email / main.js View on Github external
/**
 *
 *      ioBroker email Adapter
 *
 *      (c) 2014-2019 bluefox 
 *
 *      MIT License
 *
 */
'use strict';

const utils = require('@iobroker/adapter-core'); // Get common adapter utils
const tools = require(utils.controllerDir + '/lib/tools.js');
const adapterName = require('./package.json').name.split('.').pop();
let adapter;

function startAdapter(options) {
    options = options || {};
    Object.assign(options, {
        name: adapterName, // adapter name
    });

    adapter = new utils.Adapter(options);

    adapter.on('unload', cb => {
        if (adapter.__stopTimer) {
            clearTimeout(adapter.__stopTimer);
            adapter.__stopTimer = null;
        }
github ioBroker / ioBroker.simple-api / main.js View on Github external
/* jshint -W097 */// jshint strict:false
/*jslint node: true */
'use strict';

const utils       = require('@iobroker/adapter-core'); // Get common adapter utils
const SimpleAPI   = require('./lib/simpleapi.js');
const LE          = require(utils.controllerDir + '/lib/letsencrypt.js');
const adapterName = require('./package.json').name.split('.').pop();

let webServer = null;
let fs        = null;
let adapter;

function startAdapter(options) {
    options = options || {};
    Object.assign(options, {
        name: adapterName,
        stateChange: (id, state) => webServer && webServer.api && webServer.api.stateChange(id, state),
        unload: callback => {
            try {
                if (webServer && webServer.server) {
                    adapter.log.info('terminating http' + (webServer.settings.secure ? 's' : '') + ' server on port ' + webServer.settings.port);
                    webServer.server.close();
github ioBroker / ioBroker.history / converter / history2db.js View on Github external
/* jshint -W097 */// jshint strict:false
/*jslint node: true */
"use strict";

//noinspection JSUnresolvedFunction

//usage: nodejs history2db.js [] [] [|0] [] [] [--logChangesOnly []] [--ignoreExistingDBValues]
//usage: nodejs history2db.js influxdb.0 info 20161001 /path/to/data
const utils   = require('@iobroker/adapter-core'); // Get common adapter utils

var fs        = require('fs');
var path      = require('path');
var dataDir   = path.normalize(utils.controllerDir + '/' + require(utils.controllerDir + '/lib/tools').getDefaultDataDir());
var historydir = dataDir + 'history-data';

var earliestDBValue = {};
var earliesValCachefile = __dirname + '/earliestDBValues.json';
var earliesValCachefileExists = false;

var existingDBValues = {};
var existingDataCachefile = __dirname + '/existingDBValues.json';
var processNonExistingValues = false;

var existingTypes = {};
var existingTypesCachefile = __dirname + '/existingDBTypes.json';
var existingTypesCachefileExists = false;

var processAllDPs = false;
var simulate = false;
github ioBroker / ioBroker.admin / lib / web.js View on Github external
/* jshint -W097 */
/* jshint strict: false */
/* jslint node: true */
/* jshint -W061 */
'use strict';
const Stream 	= require('stream');
const utils 	= require('@iobroker/adapter-core'); // Get common adapter utils
const LE 	    = require(utils.controllerDir + '/lib/letsencrypt.js');
const express 	= require('express');
const fs        = require('fs');
let path        = require('path');

let session;
let bodyParser;
let AdapterStore;
let password;
let passport;
let LocalStrategy;
let flash;
let cookieParser;
let fileUpload;
let socketIoFile;
const FORBIDDEN_CHARS = /[\]\[*,;'"`<>\\\s?]/g; // with space
const ONE_MONTH_SEC = 30 * 24 * 3600;
github ioBroker / ioBroker.admin / lib / web.js View on Github external
settings.ttl = parseInt(settings.ttl, 10) || 3600;

            server.app.disable('x-powered-by');

            // enable use of i-frames together with HTTPS
            server.app.get('/*', (req, res, next) => {
                res.header('X-Frame-Options', 'SAMEORIGIN');
                next(); // http://expressjs.com/guide.html#passing-route control
            });

            if (settings.auth) {
                session       = require('express-session');
                cookieParser  = require('cookie-parser');
                bodyParser    = require('body-parser');
                AdapterStore  = require(utils.controllerDir + '/lib/session.js')(session, settings.ttl);
                password      = require(utils.controllerDir + '/lib/password.js');
                passport      = require('passport');
                LocalStrategy = require('passport-local').Strategy;
                flash         = require('connect-flash'); // TODO report error to user

                store = new AdapterStore({adapter: adapter});

                passport.use(new LocalStrategy(
                    (username, password, done) => {
                        username = (username || '').toString().replace(FORBIDDEN_CHARS, '_').replace(/\s/g, '_').replace(/\./g, '_').toLowerCase();

                        if (bruteForce[username] && bruteForce[username].errors > 4) {
                            let minutes = (new Date().getTime() - bruteForce[username].time);
                            if (bruteForce[username].errors < 7) {
                                if ((new Date().getTime() - bruteForce[username].time) < 60000) {
                                    minutes = 1;
github ioBroker / ioBroker.influxdb / main.js View on Github external
/* jshint -W097 */// jshint strict:false
/*jslint node: true */
'use strict';

//noinspection JSUnresolvedFunction
var utils    = require('@iobroker/adapter-core'); // Get common adapter utils
var influx    = require('influx');
var fs        = require('fs');
var path      = require('path');
var Aggregate = require(__dirname + '/lib/aggregate.js');
var dataDir   = path.normalize(utils.controllerDir + '/' + require(utils.controllerDir + '/lib/tools').getDefaultDataDir());
var cacheFile = dataDir + 'influxdata.json';

var subscribeAll        = false;
var influxDPs           = {};
var client;
var seriesBufferChecker = null;
var seriesBufferCounter = 0;
var seriesBufferFlushPlanned = false;
var seriesBuffer        = {};
var conflictingPoints   = {};
var errorPoints         = {};
var tasksStart          = [];
var connected           = null;
var finished            = false;
var aliasMap   = {};
github ioBroker / ioBroker.mqtt / lib / client.js View on Github external
'use strict';

const mqtt            = require('mqtt');
const utils           = require('@iobroker/adapter-core');
const tools           = require(utils.controllerDir + '/lib/tools');
const state2string    = require(__dirname + '/common').state2string;
const convertTopic2id = require(__dirname + '/common').convertTopic2id;
const convertID2topic = require(__dirname + '/common').convertID2topic;

const messageboxRegex = new RegExp('\\.messagebox$');

function getAppName() {
    const parts = __dirname.replace(/\\/g, '/').split('/');
    return parts[parts.length - 2].split('.')[0];
}
utils.appName = getAppName();

function MQTTClient(adapter, states) {
    if (!(this instanceof MQTTClient)) return new MQTTClient(adapter, states);

    let client    = null;
github simatec / ioBroker.backitup / lib / restore / iobroker.js View on Github external
function restore(options, fileName, log, callback) {
    let ioPath = utils.controllerDir + '/iobroker.js';

    try {
        log.debug('Start ioBroker Restore ...');
        const cmd = child_process.fork(ioPath, ['restore', fileName], {silent: true});
        cmd.stdout.on('data', data => log.debug(data.toString()));

        cmd.stderr.on('data', data => log.error(data.toString()));

        cmd.on('close', code => {
            if (callback) {
                log.debug('ioBroker Restore completed successfully');
                callback(null, code);
                callback = null;
            }
        });
github ioBroker / ioBroker.vis / main.js View on Github external
function upload(callback) {
    adapter.log.info('Upload ' + adapter.name + ' anew, while changes detected...');
    const file = utils.controllerDir + '/iobroker.js';
    const child = require('child_process').spawn('node', [file, 'upload', adapter.name, 'widgets']);
    let count = 0;
    child.stdout.on('data', data => {
        count++;
        adapter.log.debug(data.toString().replace('\n', ''));
        !(count % 100) && adapter.log.info(count + ' files uploaded...');
    });
    child.stderr.on('data', data => {
        adapter.log.error(data.toString().replace('\n', ''));
    });
    child.on('exit', exitCode => {
        adapter.log.info('Uploaded. ' + (exitCode ? 'Exit - ' + exitCode : 0));
        callback(exitCode);
    });
}

@iobroker/adapter-core

Core module to be used in ioBroker adapters. Acts as the bridge to js-controller.

MIT
Latest version published 1 month ago

Package Health Score

78 / 100
Full package analysis