Skip to content

Commit fb1a238

Browse files
committed
(bluefox) initial commit
1 parent e439ca3 commit fb1a238

File tree

13 files changed

+1227
-22
lines changed

13 files changed

+1227
-22
lines changed

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Gruntfile.js
2+
tasks

Gruntfile.js

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
// To use this file in WebStorm, right click on the file name in the Project Panel (normally left) and select "Open Grunt Console"
2+
3+
/** @namespace __dirname */
4+
/* jshint -W097 */// jshint strict:false
5+
/*jslint node: true */
6+
"use strict";
7+
8+
module.exports = function (grunt) {
9+
10+
var srcDir = __dirname + '/';
11+
var dstDir = srcDir + '.build/';
12+
var pkg = grunt.file.readJSON('package.json');
13+
var iopackage = grunt.file.readJSON('io-package.json');
14+
var version = (pkg && pkg.version) ? pkg.version : iopackage.common.version;
15+
16+
// Project configuration.
17+
grunt.initConfig({
18+
pkg: pkg,
19+
clean: {
20+
all: ['tmp/*.json', 'tmp/*.zip', 'tmp/*.jpg', 'tmp/*.jpeg', 'tmp/*.png',
21+
dstDir + '*.json', dstDir + '*.zip', dstDir + '*.jpg', dstDir + '*.jpeg', dstDir + '*.png']
22+
},
23+
replace: {
24+
core: {
25+
options: {
26+
patterns: [
27+
{
28+
match: /var version = *'[\.0-9]*';/g,
29+
replacement: "var version = '" + version + "';"
30+
},
31+
{
32+
match: /"version"\: *"[\.0-9]*",/g,
33+
replacement: '"version": "' + version + '",'
34+
}
35+
]
36+
},
37+
files: [
38+
{
39+
expand: true,
40+
flatten: true,
41+
src: [
42+
srcDir + 'controller.js',
43+
srcDir + 'package.json',
44+
srcDir + 'io-package.json'
45+
],
46+
dest: srcDir
47+
}
48+
]
49+
}
50+
},
51+
// Javascript code styler
52+
jscs: require(__dirname + '/tasks/jscs.js'),
53+
// Lint
54+
jshint: require(__dirname + '/tasks/jshint.js'),
55+
http: {
56+
get_hjscs: {
57+
options: {
58+
url: 'https://raw.githubusercontent.com/ioBroker/ioBroker.js-controller/master/tasks/jscs.js'
59+
},
60+
dest: 'tasks/jscs.js'
61+
},
62+
get_jshint: {
63+
options: {
64+
url: 'https://raw.githubusercontent.com/ioBroker/ioBroker.js-controller/master/tasks/jshint.js'
65+
},
66+
dest: 'tasks/jshint.js'
67+
},
68+
get_gruntfile: {
69+
options: {
70+
url: 'https://raw.githubusercontent.com/ioBroker/ioBroker.build/master/adapters/Gruntfile.js'
71+
},
72+
dest: 'Gruntfile.js'
73+
},
74+
get_utilsfile: {
75+
options: {
76+
url: 'https://raw.githubusercontent.com/ioBroker/ioBroker.build/master/adapters/utils.js'
77+
},
78+
dest: 'lib/utils.js'
79+
},
80+
get_jscsRules: {
81+
options: {
82+
url: 'https://raw.githubusercontent.com/ioBroker/ioBroker.js-controller/master/tasks/jscsRules.js'
83+
},
84+
dest: 'tasks/jscsRules.js'
85+
},
86+
get_iconOnline: {
87+
options: {
88+
encoding: null,
89+
url: iopackage.common.extIcon || 'https://raw.githubusercontent.com/ioBroker/ioBroker.js-controller/master/adapter/example/admin/example.png'
90+
},
91+
dest: dstDir + 'ioBroker.adapter.' + iopackage.common.name + '.png'
92+
93+
},
94+
get_iconOffline: {
95+
options: {
96+
encoding: null,
97+
url: iopackage.common.extIcon || 'https://raw.githubusercontent.com/ioBroker/ioBroker.js-controller/master/adapter/example/admin/example.png'
98+
},
99+
dest: dstDir + 'ioBroker.adapter.offline.' + iopackage.common.name + '.png'
100+
101+
}
102+
},
103+
compress: {
104+
adapter: {
105+
options: {
106+
archive: dstDir + 'ioBroker.adapter.' + iopackage.common.name + '.zip'
107+
},
108+
files: [
109+
{
110+
expand: true,
111+
src: ['**', '!tasks/*', '!Gruntfile.js', '!node_modules/**/*', '!build/**/*'],
112+
dest: '/',
113+
cwd: srcDir
114+
}
115+
]
116+
},
117+
adapterOffline: {
118+
options: {
119+
archive: dstDir + 'ioBroker.adapter.offline.' + iopackage.common.name + '.zip'
120+
},
121+
files: [
122+
{
123+
expand: true,
124+
src: ['**',
125+
'!tasks/*',
126+
'!Gruntfile.js',
127+
'!build/**/*',
128+
'!node_modules/grunt/**/*',
129+
'!node_modules/grunt*/**/*'
130+
],
131+
dest: '/',
132+
cwd: srcDir
133+
}
134+
]
135+
}
136+
},
137+
exec: {
138+
npm: {
139+
cmd: 'npm install'
140+
}
141+
},
142+
copy: {
143+
json: {
144+
files: [
145+
{
146+
expand: true,
147+
cwd: srcDir,
148+
src: ['io-package.json'],
149+
dest: dstDir,
150+
rename: function (dest, src) {
151+
return dstDir + 'ioBroker.adapter.offline.' + iopackage.common.name + '.json';
152+
}
153+
},
154+
{
155+
expand: true,
156+
cwd: srcDir,
157+
src: ['io-package.json'],
158+
dest: dstDir,
159+
rename: function (dest, src) {
160+
return dstDir + 'ioBroker.adapter.' + iopackage.common.name + '.json';
161+
}
162+
}
163+
]
164+
}
165+
}
166+
});
167+
168+
grunt.registerTask('updateReadme', function () {
169+
var readme = grunt.file.read('README.md');
170+
var pos = readme.indexOf('## Changelog\r\n');
171+
if (pos != -1) {
172+
var readmeStart = readme.substring(0, pos + '## Changelog\r\n'.length);
173+
var readmeEnd = readme.substring(pos + '## Changelog\r\n'.length);
174+
175+
if (iopackage.common && readme.indexOf(iopackage.common.version) == -1) {
176+
var timestamp = new Date();
177+
var date = timestamp.getFullYear() + '-' +
178+
("0" + (timestamp.getMonth() + 1).toString(10)).slice(-2) + '-' +
179+
("0" + (timestamp.getDate()).toString(10)).slice(-2);
180+
181+
var news = "";
182+
if (iopackage.common.whatsNew) {
183+
for (var i = 0; i < iopackage.common.whatsNew.length; i++) {
184+
if (typeof iopackage.common.whatsNew[i] == 'string') {
185+
news += '* ' + iopackage.common.whatsNew[i] + '\r\n';
186+
} else {
187+
news += '* ' + iopackage.common.whatsNew[i].en + '\r\n';
188+
}
189+
}
190+
}
191+
192+
grunt.file.write('README.md', readmeStart + '### ' + iopackage.common.version + ' (' + date + ')\r\n' + (news ? news + '\r\n\r\n' : '\r\n') + readmeEnd);
193+
}
194+
}
195+
});
196+
197+
grunt.loadNpmTasks('grunt-replace');
198+
grunt.loadNpmTasks('grunt-contrib-jshint');
199+
grunt.loadNpmTasks('grunt-jscs');
200+
grunt.loadNpmTasks('grunt-http');
201+
grunt.loadNpmTasks('grunt-contrib-clean');
202+
grunt.loadNpmTasks('grunt-contrib-compress');
203+
grunt.loadNpmTasks('grunt-exec');
204+
grunt.loadNpmTasks('grunt-contrib-copy');
205+
206+
grunt.registerTask('default', [
207+
'exec',
208+
'http',
209+
'clean',
210+
'replace',
211+
'updateReadme',
212+
'compress',
213+
'copy',
214+
'jshint',
215+
'jscs'
216+
]);
217+
};

LICENSE

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
The MIT License (MIT)
2-
3-
Copyright (c) 2015
4-
5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
11-
12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
14-
15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
22-
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
![Logo](admin/megad.png)
2+
ioBroker MegaD-328 adapter
3+
=================
4+
Lets control the [MegaD-328](http://www.ab-log.ru/smart-house/ethernet/MegaD-328) over ethernet.
5+
## English
6+
[по русски](#Русский)
7+
8+
## Install
9+
10+
```node iobroker.js add megad```
11+
12+
### Information
13+
The device has 14 ports, 0-7 inputs and 8-13 outputs.
14+
To read the state of the port call
15+
```http://mega_ip/sec/?pt=4&cmd=get``` , where sec is password (max 3 chars), 4 is port number
16+
The result will come as "ON", "OFF" or analog value for analog ports
17+
18+
To set the state call:
19+
```http://mega_ip/sec/?cmd=2:1``` , where sec is password (max 3 chars), 2 is port number, and 1 is the value
20+
For digital ports only 0, 1 and 2 (toggle) are allowed, for analog ports the values from 0 to 255 are allowed
21+
22+
The device can report the changes of ports to some web server in form
23+
```http://ioBroker:80/?pt=6``` , where 6 is the port number
24+
25+
MegaD-328 cannot report on other port than 80.
26+
27+
### Configuration
28+
29+
- IP: IP address of MegaD-328;
30+
- MegaD-328 Name: Name of the MegaD-328 to assign the port changes, e.g. "DevA". If no name set the adapter instance will be used for that;
31+
- Port: Listening port on ioBroker. MegaD-328 cannot send to ports other than 80. Default value: 80.
32+
- Poll interval: poll interval in seconds. All configured input ports will be polled in defined interval;
33+
- Password: password to access the device (max 3 characters). Default value "sec";
34+
35+
MegaD-328 can report about changes on some ports if configured.
36+
You can configure something like that "http://ioBrokerIP/instance" on MegaD-328 in "Net"-Field and MegaD-328 will send reports like this one "http://ioBrokerIP/instance/?pt=7" to ioBroker.
37+
That means the button on port 7 was pressed. ioBroker expectes instance number (e.g. "0") or defined name of MegaD-328 (e.g. "DevA"). The "Net" field will look like: "http://192.168.0.8/0/".
38+
39+
### Ports
40+
All ports, that are desired to be used must be configured in right order. Following settings must be set for every port:
41+
42+
- name: name of the port. Used by ioBroker;
43+
- input: Is the port INPUT(true) or output(false);
44+
- switch: Is the port can be ON or OFF (in this case value = TRUE) or just used to send the reports about button press (FALSE);
45+
- digital: Analog or digital port. ioBroker expects analog ports with range from 0 to 255.
46+
- offset: offset for the **analog** port.
47+
- factor: multiply factor for **anaolog** port.
48+
49+
ioBrokerValue = (MegaValue/256) * factor + offset;
50+
51+
To get the range of the analog value from 100 to 500 set the factor as 400 and offset = 100.
52+
53+
**The order of the ports is very important. The port in first row will be associated with P0 in MegaD-328. In row number 14 with P13.**
54+
55+
-------------------
56+
## Русский
57+
Подробную документацию можно найти здесь: [http://www.ab-log.ru/smart-house/ethernet/MegaD-328](http://www.ab-log.ru/smart-house/ethernet/MegaD-328)
58+
59+
### Настройки
60+
61+
- IP Адрес устройства: IP адрес MegaD-328;
62+
- MegaD Имя: Имя MegaD-328 устройства для идентификации сообщений о смене состояния порта от MegaD-328, например "DevA". Если имя не задано, то для этих целей будет использоватся номер инстанции драйвера.;
63+
- ioBroker веб-порт: Порт на котором ioBroker развертывает веб сервер для приёма сообщений от MegaD-328. MegaD-328 не поддерживает на данный момент порты отличные от 80. Значение по умолчанию: 80.
64+
- Интервал опроса (сек): инетрвал опроса портов в секундах;
65+
- MegaD-328 Пароль: пароль для доступа на MegaD-328 (максимально 3 символа). Значение по умолчанию: "sec";
66+
67+
В сетевых настройках MegaD-328 можно сконфигуририровать IP-адрес ioBroker. При каждом нажатии на кнопку MegaD-328 сообщает ioBroker (restAPI) номер сработавшего входа.
68+
69+
Выглядит запрос примерно следующим образом:
70+
´´´http://192.168.0.250/0/?pt=7´´´
71+
72+
Необходимо прописать в настройках MegaD-328 в поле "Net" ´´´http://192.168.0.250/0/´´´, если адрес ioBroker "192.168.0.250" и инстанция адаптера 0.
73+
74+
### Порты
75+
Необходимо сконфигурироваь все порты, которые должны быть видимы в ioBorker. Для каждого порта необходимо настроить следующее:
76+
77+
- Имя: имя порта. Исползуется в ioBroker для создание объектов;
78+
- Вход: является ли порт входом (true) или выходом(false);
79+
- Переключатель: Может ли порт быть в положениях ВКЛ и ВЫКЛ (в этом случае значение TRUE) или он просто используется для сигнализирования нажатия на кнопку (FALSE);
80+
- Цифровой: Цифровой или аналоговый порт. ioBroker ожидает значени с аналогового порта в промежутке от 0 до 255.
81+
- Множитель: множитель для значения **аналогового** порта.
82+
- Сдвиг: сдвиг для значения **аналогового** порта.
83+
84+
ioBrokerЗначение = (MegaЗначение/256) * Множитель + Сдвиг;
85+
86+
Например, что бы получить интервал значений от 100 до 500 нужно установить сдиг 100 и множитель 400.
87+
88+
Только аналоговые порты принимают во внимание Множитель и Сдвиг.
89+
90+
**Порядок портов очень важен. Порт в первой колонке таблицы ассоциируется с портом P0 на MegaD-328. Порт в колонке 14 с P13.**
91+
92+
## TODO
93+
- support of more than one device
94+
95+
96+
## Changelog
97+
### 0.0.1 (2015-03-05)
98+
* (bluefox) make socket usable as module

0 commit comments

Comments
 (0)