Connection to hobu

This commit is contained in:
2017-05-12 22:32:18 +02:00
parent bfae25bd33
commit 143782ce4f
40 changed files with 4342 additions and 1392 deletions
+54 -6
View File
@@ -2,17 +2,21 @@ var Tinkerforge = require('../Tinkerforge')
, Conf = require('./config.json')
, Helper = require('../Adawim/helper')
, Log = require('../Adawim/logging')
, http = require('http');
, http = require('http')
, WebSocket = require('ws');
var ws = null;
var lastTagID = '';
var timeOutForHoldingLastTagID = null;
const timeOutForHoldingLastTagIDInMillis = Conf.rfid.timeout;
var currentActionState = 0;
Helper.each(Conf.items, function(item) {
connect(item);
});
var lastTagID = '';
var timeOutForHoldingLastTagID = null;
const timeOutForHoldingLastTagIDInMillis = Conf.rfid.timeout;
var currentActionState = 0;
/* private */
function reconnect(item) {
@@ -198,12 +202,56 @@ function doActionOnRFIDCallback(key) {
case 0:
// deactivate alarm system
Log.log( 'deactivate alarm system' );
deactivateAlarmSystem();
break;
case 1:
// activate alarm system
Log.log( 'activate alarm system' );
activateAlarmSystem();
break;
default:
// nothing to do
}
}
}
/* private */
function activateAlarmSystem() {
msg = '{type:"set_alarm_system_state", data:{state:"F111"}}';
send(msg);
}
/* private */
function deactivateAlarmSystem() {
msg = '{type:"set_alarm_system_state", data:{state:"F222"}}';
send(msg);
}
/* private */
function send(msg) {
if(Helper.isDefinedAndNotNull(ws) && Helper.isDefinedAndNotNull(msg)) {
ws.send(msg);
} else {
Log.error('ws is null');
}
}
var openWebSocket = function() {
ws = new WebSocket(Conf.hobu.url);
ws.on('open', function() {
Log.log('ws open');
ws.send(Date.now().toString(), {mask: true});
});
ws.on('close', function() {
Log.log('ws disconnect');
openWebSocket();
});
ws.on('message', function incoming(data, flags) {
// flags.binary will be set if a binary data is received.
// flags.masked will be set if the data was masked.
Log.inspect('data', data);
});
}
openWebSocket();
+4 -1
View File
@@ -1,10 +1,13 @@
{
"hobu": {
"url": "ws://hobu.local:8000/"
},
"rfid": {
"timeout": 10000
},
"items": [
{
"host": "localhost",
"host": "192.168.2.123",
"port": 4223,
"mtouch": {
"uid": "ADk"