- Platform information:
- Hardware: _x64 Intel
- OS: Ubuntu 18.04.4 LTS
- Java Runtime Environment: Zulu 8 amd64
- openHAB version: 2.5.4
Hi,
I know very little about web sockets, but I have managed to show connectivity between my OH machine and a third-party service that provides a web socket showing data from my alarm system.
If I run wscat from the command line on my OH machine, I see the following live events:
$ wscat -c ws://alarmgw:8088/ws/spc
Connected (press CTRL+C to quit)
< {"status":"success","data":{"sia":{"device_id":"xxxxx","timestamp":"1587394004","sia_code":"ZO","sia_address":"2","description":"Beam Hall¦ZONE¦1¦Home","flags":"","verification_id":"0"}}}
< {"status":"success","data":{"sia":{"device_id":"xxxxx","timestamp":"1587394010","sia_code":"ZC","sia_address":"2","description":"Beam Hall¦ZONE¦1¦Home","flags":"","verification_id":"0"}}}
< {"status":"success","data":{"sia":{"device_id":"xxxxx","timestamp":"1587394013","sia_code":"ZO","sia_address":"4","description":"Back Area¦ZONE¦1¦Home","flags":"","verification_id":"0"}}}
< {"status":"success","data":{"sia":{"device_id":"xxxxx","timestamp":"1587394016","sia_code":"ZC","sia_address":"4","description":"Back Area¦ZONE¦1¦Home","flags":"","verification_id":"0"}}}
> $
As per the documentation for the alarm gateway, I have the following basic config in a transform file:
var websocket_client = require('websocket').client;
// Connect to SPC Web Gateway websocket interface on alarmgw:8088
var ws_client = new websocket_client();
ws_client.connect('ws://alarmgw:8088/ws/spc');
ws_client.on('connectFailed', function(error) {
console.log('Connect Error: ' + error.toString());
});
ws_client.on('connect', function(connection) {
console.log('WebSocket client connected');
connection.on('error', function(error) {
console.log("Connection Error: " + error.toString());
});
connection.on('close', function()
{ console.log('echo-protocol Connection Closed');
});
connection.on('message', function(message)
{ if (message.type === 'utf8') {
manageSiaEvent(message.utf8Data);
}
});
});
// manageSiaEvent
function manageSiaEvent(message){
var msg = JSON.parse(message);
if (msg.status === 'success') {
var sia_code = msg.data.sia.sia_code;
// Take care of SIA event action
switch (sia_code){
case 'BA': /* Burglar Alarm */
break;
case 'BR': /* Burglar Alarm Restore */
break;
case 'BB': /* Inhibited or Isolated */
break;
case 'ZO': /* Zone Opened */
break;
case 'ZC': /* Zone Closed */
break;
}
}
}
I’m stuck as to how to proceed - does anyone know how I can get this data into an item?