diff --git a/docs/es/img/picture.png b/docs/es/img/picture.png deleted file mode 100644 index a16caf4..0000000 Binary files a/docs/es/img/picture.png and /dev/null differ diff --git a/docs/es/template.md b/docs/es/template.md deleted file mode 100644 index c930e13..0000000 --- a/docs/es/template.md +++ /dev/null @@ -1,3 +0,0 @@ -# This is Documentation - -(Picture)[img/picture.png) \ No newline at end of file diff --git a/docs/fr/img/picture.png b/docs/fr/img/picture.png deleted file mode 100644 index a16caf4..0000000 Binary files a/docs/fr/img/picture.png and /dev/null differ diff --git a/docs/fr/template.md b/docs/fr/template.md deleted file mode 100644 index c930e13..0000000 --- a/docs/fr/template.md +++ /dev/null @@ -1,3 +0,0 @@ -# This is Documentation - -(Picture)[img/picture.png) \ No newline at end of file diff --git a/docs/it/img/picture.png b/docs/it/img/picture.png deleted file mode 100644 index a16caf4..0000000 Binary files a/docs/it/img/picture.png and /dev/null differ diff --git a/docs/it/template.md b/docs/it/template.md deleted file mode 100644 index c930e13..0000000 --- a/docs/it/template.md +++ /dev/null @@ -1,3 +0,0 @@ -# This is Documentation - -(Picture)[img/picture.png) \ No newline at end of file diff --git a/docs/nl/img/picture.png b/docs/nl/img/picture.png deleted file mode 100644 index a16caf4..0000000 Binary files a/docs/nl/img/picture.png and /dev/null differ diff --git a/docs/nl/template.md b/docs/nl/template.md deleted file mode 100644 index c930e13..0000000 --- a/docs/nl/template.md +++ /dev/null @@ -1,3 +0,0 @@ -# This is Documentation - -(Picture)[img/picture.png) \ No newline at end of file diff --git a/docs/pt/img/picture.png b/docs/pt/img/picture.png deleted file mode 100644 index a16caf4..0000000 Binary files a/docs/pt/img/picture.png and /dev/null differ diff --git a/docs/pt/template.md b/docs/pt/template.md deleted file mode 100644 index c930e13..0000000 --- a/docs/pt/template.md +++ /dev/null @@ -1,3 +0,0 @@ -# This is Documentation - -(Picture)[img/picture.png) \ No newline at end of file diff --git a/docs/ru/img/picture.png b/docs/ru/img/picture.png deleted file mode 100644 index a16caf4..0000000 Binary files a/docs/ru/img/picture.png and /dev/null differ diff --git a/docs/ru/template.md b/docs/ru/template.md deleted file mode 100644 index 2202601..0000000 --- a/docs/ru/template.md +++ /dev/null @@ -1,3 +0,0 @@ -# Это документация - -(Picture)[img/picture.png) \ No newline at end of file diff --git a/main.js b/main.js index bde8162..ef1a5ef 100644 --- a/main.js +++ b/main.js @@ -2,121 +2,94 @@ /*jslint node: true */ 'use strict'; -// you have to require the utils module and call adapter function -var utils = require(__dirname + '/lib/utils'); // Get common adapter utils +var utils = require(__dirname + '/lib/utils'); // Get common adapter utils +var request = require('request'); -// you have to call the adapter function and pass a options object -// name has to be set and has to be equal to adapters folder name and main file name excluding extension -// adapter will be restarted automatically every time as the configuration changed, e.g system.adapter.luftdaten.0 var adapter = new utils.Adapter('luftdaten'); -// is called when adapter shuts down - callback has to be called under any circumstances! -adapter.on('unload', function (callback) { - try { - adapter.log.info('cleaned everything up...'); - callback(); - } catch (e) { - callback(); - } -}); - -// is called if a subscribed object changes -adapter.on('objectChange', function (id, obj) { - // Warning, obj can be null if it was deleted - adapter.log.info('objectChange ' + id + ' ' + JSON.stringify(obj)); -}); - -// is called if a subscribed state changes -adapter.on('stateChange', function (id, state) { - // Warning, state can be null if it was deleted - adapter.log.info('stateChange ' + id + ' ' + JSON.stringify(state)); - - // you can use the ack flag to detect if it is status (true) or command (false) - if (state && !state.ack) { - adapter.log.info('ack is not set!'); - } -}); - -// Some message was sent to adapter instance over message box. Used by email, pushover, text2speech, ... -adapter.on('message', function (obj) { - if (typeof obj === 'object' && obj.message) { - if (obj.command === 'send') { - // e.g. send email or pushover or whatever - console.log('send command'); - - // Send response in callback if required - if (obj.callback) adapter.sendTo(obj.from, obj.command, 'Message received', obj.callback); - } - } -}); - -// is called when databases are connected and adapter received configuration. -// start here! adapter.on('ready', function () { main(); }); function main() { - // The adapters config (in the instance object everything under the attribute "native") is accessible via - // adapter.config: - adapter.log.info('config test1: ' + adapter.config.test1); - adapter.log.info('config test1: ' + adapter.config.test2); - adapter.log.info('config mySelect: ' + adapter.config.mySelect); - - - /** - * - * For every state in the system there has to be also an object of type state - * - * Here a simple luftdaten for a boolean variable named "testVariable" - * - * Because every adapter instance uses its own unique namespace variable names can't collide with other adapters variables - * - */ - - adapter.setObject('testVariable', { - type: 'state', - common: { - name: 'testVariable', - type: 'boolean', - role: 'indicator' - }, - native: {} - }); - - // in this luftdaten all states changes inside the adapters namespace are subscribed - adapter.subscribeStates('*'); - - - /** - * setState examples - * - * you will notice that each setState will cause the stateChange event to fire (because of above subscribeStates cmd) - * - */ - - // the variable testVariable is set to true as command (ack=false) - adapter.setState('testVariable', true); - - // same thing, but the value is flagged "ack" - // ack should be always set to true if the value is received from or acknowledged from the target system - adapter.setState('testVariable', {val: true, ack: true}); - - // same thing, but the state is deleted after 30s (getState will return null afterwards) - adapter.setState('testVariable', {val: true, ack: true, expire: 30}); - - - - // examples for the checkPassword/checkGroup functions - adapter.checkPassword('admin', 'iobroker', function (res) { - console.log('check user admin pw ioboker: ' + res); - }); - - adapter.checkGroup('admin', 'admin', function (res) { - console.log('check group user admin group admin: ' + res); - }); - - + var sensorType = adapter.config.sensorType; + var sensorIdentifier = adapter.config.sensorIdentifier; + + adapter.log.info('sensor type: ' + sensorType); + adapter.log.info('sensor identifier: ' + sensorIdentifier); + + if (sensorType == "local") { + adapter.log.info('local request'); + + request( + { + url: "http://" + sensorIdentifier + "/data.json", + json: true + }, + function(error, response, content) { + adapter.log.debug('Request done'); + + if (!error && response.statusCode == 200) { + + for (var key in content.sensordatavalues) { + var obj = content.sensordatavalues[key]; + + adapter.setObjectNotExists(obj.value_type, { + type: 'state', + common: { + name: obj.value_type, + type: 'number', + role: 'value' + }, + native: {} + }); + + adapter.setState(obj.value_type, {val: obj.value, ack: true}); + } + + } else { + adapter.log.error(error); + } + } + ); + } else if (sensorType == "remote") { + adapter.log.info('remote request'); + + request( + { + url: "http://api.luftdaten.info/v1/sensor/" + sensorIdentifier + "/", + json: true + }, + function(error, response, content) { + adapter.log.debug('Request done'); + + if (!error && response.statusCode == 200) { + + for (var key in content[0].sensordatavalues) { + var obj = content[0].sensordatavalues[key]; + + adapter.setObjectNotExists('SDS_' + obj.value_type, { + type: 'state', + common: { + name: 'SDS_' + obj.value_type, + type: 'number', + role: 'value' + }, + native: {} + }); + + adapter.setState('SDS_' + obj.value_type, {val: obj.value, ack: true}); + } + + } else { + adapter.log.error(error); + } + } + ); + } -} + setTimeout(function () { + adapter.stop(); + }, 10000); +} \ No newline at end of file diff --git a/package.json b/package.json index 7dab05e..8797baa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "iobroker.luftdaten", - "version": "0.6.0", + "version": "0.0.1", "description": "ioBroker luftdaten Adapter", "author": { "name": "Matthias Kleine", @@ -12,7 +12,7 @@ "email": "info@haus-automatisierung.com" } ], - "homepage": "https://github.com/ioBroker/ioBroker.luftdaten", + "homepage": "https://github.com/klein0r/ioBroker.luftdaten", "license": "MIT", "keywords": [ "ioBroker", @@ -22,9 +22,11 @@ ], "repository": { "type": "git", - "url": "https://github.com/ioBroker/ioBroker.luftdaten" + "url": "https://github.com/klein0r/ioBroker.luftdaten" + }, + "dependencies": { + "request": "^2.72.0" }, - "dependencies": {}, "devDependencies": { "gulp": "^3.9.1", "mocha": "^4.1.0", @@ -35,7 +37,7 @@ "test": "node node_modules/mocha/bin/mocha --exit" }, "bugs": { - "url": "https://github.com/ioBroker/ioBroker.luftdaten/issues" + "url": "https://github.com/klein0r/ioBroker.luftdaten/issues" }, "readmeFilename": "README.md" } \ No newline at end of file