-
Notifications
You must be signed in to change notification settings - Fork 0
/
IoTLab_stop_signal.js
55 lines (40 loc) · 1.37 KB
/
IoTLab_stop_signal.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//Some parameters:
var timeInterval = 2000;
var numberTimes = 5;
//Seting UDP communication:
var udp_datagram = require('dgram');
var client = udp_datagram.createSocket('udp6');
var udpPort = 4000;
//Getting the IPaddress of the nodes involved:
var fs = require('fs');
var data = fs.readFileSync("NODES.json");
var dataNodes = JSON.parse(data);
var address = dataNodes.ipv6Address;
//****************************************************************************//
//*** Send UDP datagram to Broadcast *****************************************//
//****************************************************************************//
//Send UDP datagram to the agents, each timeInterval [ms], for numberTimes times:
function send_UDPdatagram(){
//The message:
var message = new Buffer("stop");
//For each agent:
for (var index in address) {
//Send UDP message:
client.send(
message, 0, message.length, udpPort, address[index],
function(err,bytes){
if(err){
throw err;
}
}
);
//Console print for debugging:
console.log('UDP stop signal sended to: ' + address[index]);
}
}
timer = setInterval(send_UDPdatagram, timeInterval);
function stopTimer() {
clearInterval(timer);
process.exit();
}
setTimeout(stopTimer, (numberTimes*timeInterval));