Initial commit
This commit is contained in:
commit
c53c7085bc
60 changed files with 23885 additions and 0 deletions
96
flow/tcpipisend.js
Normal file
96
flow/tcpipisend.js
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
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 = `<div class="padding">
|
||||
<div data---="dropdown__tcpclient__datasource:tcpipconfig;required:true" class="m">@(Clients)</div>
|
||||
</div>
|
||||
<script>
|
||||
var tcpipconfig = [];
|
||||
var clients = {};
|
||||
ON('open.tcpipsend', function(component, options) {
|
||||
|
||||
/*TRIGGER('tcpip.clients', function(data) {
|
||||
clients = data;
|
||||
tcpipconfig = [];
|
||||
data.forEach(function(client){
|
||||
tcpipconfig.push(client.id);
|
||||
});
|
||||
console.log(tcpipconfig);
|
||||
});*/
|
||||
|
||||
TRIGGER('tcpip.clients', 'tcpipconfig');
|
||||
|
||||
});
|
||||
</script>`;
|
||||
|
||||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue