exports.id = 'tcpipsend'; exports.title = 'TCP/IP Send'; exports.group = 'TCP/IP'; exports.color = '#888600'; exports.version = '1.0.2'; exports.icon = 'sign-out'; exports.input = true; exports.output = 1; exports.author = 'Lukas Muransky'; exports.options = {}; exports.html = `
@(Clients)
`; exports.readme = `# TCPIP Connect`; exports.install = function(instance) { var net = require('net'); instance.on('data', function(flowdata) { connect(flowdata); }); instance.reconfigure = function() { if (!instance.options.tcpclient) return instance.status('Not configured', 'red'); else return instance.status('Configured'); }; instance.on('options', instance.reconfigure); instance.reconfigure(); function connect(response) { //instance.debug('Input data: ' + data); //let Summary = []; var client = new net.Socket(); var tcpip = TCPIP_CLIENTS.find(obj => obj.id == instance.options.tcpclient); var opt = {}; opt.ip = tcpip.options.ip; opt.port = tcpip.options.port; opt.helvar = tcpip.options.helvar; client.connect(opt.port, opt.ip, function() { instance.status('Connected'); }); //instance.debug('Response: ' + response.data); client.on('close', function() { //instance.debug('Connection closed (inside)'); instance.status('Closed'); }); client.on('data', function(answer) { response.data = answer.toString(); instance.send2(response); }); if(opt.helvar && response.data.slice(-1) == '*'){ response.data = response.data.slice(0, -1); //odstrani * client.write(response.data); response.data = response.data.slice(0, -1); //odstrani # lebo je prida ma koniec response.data = '?'+response.data.slice(1) + "=Command sent#"; instance.send2(response); //client.destroy(); } else { client.write(response.data); } client.end(); } }; ///FLOW.find() najde komponentu instance.connect(data)