1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| // Manage connexion with a TCP Velbus server
letvelbus = import('./velbuslib');
letevents = require('events');
letvelbusEvt = newevents.EventEmitter();
lethost = "teo-tea.hd.free.fr";
letport = 8445;
letconnexion = () => {
console.log("connected to velbus ", host+":"+port);
}
letclient = newnet.Socket();
rep = client.connect(port, host, connexion);
client.on('connect', (data) => {
console.log("connexion ok : ", data);
})
client.on('data', (data) => {
// RAW data could have multiple Velbus message
velbus.Cut(data).forEach(element=> {
letdesc = velbus.analysing(element);
letd = velbus.toHexa(element);
letcrc = velbus.CheckSum(element);
// console.log("DATA: "+d+" CRC:"+crc.toString(16));
io.emit('news',desc + "--"+d);
});
});
client.on('close', () => {
console.log("Closing velbus server connexion");
}); |
Partager