homebridge-globalcache-gc100
Version:
A homebridge plugin for Global Cache GC-100 IR/RS232 bridge
26 lines (19 loc) • 690 B
JavaScript
var net = require('net');
var Entities = require('html-entities').AllHtmlEntities;
entities = new Entities();
// var PON_MSG = new Buffer('\x02PO1\x03', 'binary');
// var POF_MSG = new Buffer('\x02POF\x03', 'binary');
var STX = entities.decode('');
var ETX = entities.decode('');
var PON_MSG = new Buffer(STX+'POF'+ETX).toString('base64');
console.log(PON_MSG);
var client = new net.Socket();
client.connect('4999','10.0.1.155', function() {
console.log('CONNECTED');
// Replace `PON_MSG` with `POF_MSG` to do POF instead
client.write(PON_MSG);
}).on('data', function(data) {
console.log('RS232 response: '+ data);
// Close the connection
client.destroy();
});