Created
February 1, 2016 12:35
-
-
Save kenci/5c13547cfff1e2f44d36 to your computer and use it in GitHub Desktop.
Pimatic socket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var io = require('/usr/local/lib/node_modules/socket.io/node_modules/socket.io-client'); | |
var mqtt = require('/usr/local/lib/node_modules/mqtt'); | |
var mqttClient = mqtt.connect('mqtt://mqtt.server.ip', { | |
username: 'user', | |
password: 'password', | |
rejectUnauthorized: false | |
}); | |
var host = 'pimatichost'; | |
var port = 1607; //pimatic port | |
var u = encodeURIComponent('user'); //pimatic username | |
var p = encodeURIComponent('password'); //pimatic password | |
var socket = io('http://' + host + ':' + port + '/?username=' + u + '&password=' + p, { | |
reconnection: true, | |
reconnectionDelay: 1000, | |
reconnectionDelayMax: 3000, | |
timeout: 20000, | |
forceNew: true | |
}); | |
var _name, _id, _value; | |
socket.on('connect', function() { | |
console.log('connected'); | |
}); | |
mqttClient.on('connect', function () { | |
console.log('client mqtt connected:'); | |
}); | |
mqttClient.on('error', function (error) { | |
console.log('Error:'+error); | |
}); | |
socket.on('event', function(data) { | |
console.log(data); | |
}); | |
socket.on('disconnect', function(data) { | |
console.log('disconnected'); | |
}); | |
socket.on('deviceAttributeChanged', function(attrEvent) { | |
//console.log(attrEvent); | |
_name = attrEvent.attributeName.toLowerCase().replace(" ", "_"); | |
_id = attrEvent.deviceId.toLowerCase(); | |
_value = attrEvent.value.toString(); | |
//console.log('homematic/'+_id+'/'+_name+'->'+_value); | |
mqttClient.publish('homematic/'+_id+'/'+_name, _value); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment