0.0.17 • Published 9 years ago
tls-xml v0.0.17
TLS-XML Library
This library is used to work with tls connection that sends and receives payload of format:
0-4 Bytes: Payload Length \ 4-8 Bytes: CommandID \ 8- remaining: Payload
API
new SecurifiSocket(options)
options
Objecthost
Stringport
NumberrejectUnauthorized
Boolean
Construct a new socket object.
socket.send(commandName, data)
commandName
Stringdata
Object
Sends command with commandName
and data
through tls connection.
data
is JSON object.
Available commands:
- login
- almond_list
- device_value
- device_data
- mobile_command
JSON commands:
- update_index
- device_list
Command: "update_index":
{
"MobileInternalIndex":689,
"CommandType":"UpdateDeviceIndex",
"ID":<device_id>,
"Index":<value_index>,
"Value":<value>,
"AlmondMAC": <almond_mac>
}
Command "device_list"
{
"MobileInternalIndex":355,
"CommandType":"DeviceList" ,
"AlmondMAC":<almond_mac>,
"Action": "get"
}
Event: 'data'
function(data) { }
When this event emitted JSON object is passed to data variable.
Event: 'error'
function (error) { }
If the internal tls socket emits an error, this event is emitted.
Event: 'open'
function () { }
Emitted when the tls connection is established.
Example
var SecurifiSocket = require('tls-xml');
Options is used to connect to server thhrough tls connection.
var options = {
host: '102.13.54.134',
port: 5000,
rejectUnauthorized:false
}
var socket = new SecurifiSocket(options):
socket.on('open', function() {
console.log('Connection opened');
})
Lock example:
securifi.lock('full', {
macAddress:"25117621634324",
devices: ["1","2","3"],
lockout: {
coolingSetpoint:{
min: 40,
max: 50
},
heatingSetpoint: {
min: 60,
max:70
},
duration: 360,
pin: 1111,
allowedModes:{}
}
})
Unlock example:
securifi.unlock({
macAddress:"25117621634324",
devices: ["1","2","3"]
})
"device_list" response:
{
"CommandType":"DeviceList",
"Success":true,
"Reason":null,
"AlmondMAC":251176216341111,
"Devices":{
"1":{
"Data":{
"ID":1,
"Type":62,
"Name":"Zen Thermostat #1",
"AssociationTimeStamp":null,
"FriendlyDeviceType":null,
"Location":"Default"
},
"DeviceValues":{
"1":{
"Name":"SENSOR MULTILEVEL",
"Value":"83.3"
},
"2":{
"Name":"THERMOSTAT MODE",
"Value":"Heat"
},
"3":{
"Name":"THERMOSTAT OPERATING STATE",
"Value":""
},
"4":{
"Name":"THERMOSTAT SETPOINT HEATING",
"Value":"49"
},
"5":{
"Name":"THERMOSTAT SETPOINT COOLING",
"Value":"40"
},
"6":{
"Name":"THERMOSTAT FAN MODE",
"Value":"Auto Low"
},
"7":{
"Name":"THERMOSTAT FAN STATE",
"Value":""
},
"8":{
"Name":"BATTERY",
"Value":""
},
"9":{
"Name":"UNITS",
"Value":""
},
"10":{
"Name":"CUSTOM_MESSAGE",
"Value":""
}
}
}
}
}