Newer
Older
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
int SendCapabilities::start(String args) {
//This is where you do your stuff for a simple behaviour
_node->announce_capabilities();
return "SendCapabilities behaviour " + _name;
};
void PingServer::update() {
if (millis() > (_t+_interval)) {
_t = millis();
_node->announce(str);
}
};
int PingServer::start(String args) {
_background = true;
_running = true;
_t = millis();
str = "{\"id\":\"" + String(_node->getId()) + "\",\"PingServer\":{}}";
_node->announce(str);
return "Pinging server";
};
void Link::update() {
if (millis() > (_t+_timeoutInterval)) {
String str = "{\"id\":\"" + String(_node->getId()) + "\",\"Unlink\":{\"peerId\":\"" + _peerId + "\"}}";
_node->announce(str);
_peerId = "";
_running = false;
}
};
int Link::start(String args) {
_running = true;
if (args == name() || args.indexOf(" ")>0) {
return "Invalid args (" + args + ") in behaviour " + name();
}
_t = millis();
if (args == _peerId) {
return "Link ping from (" + _peerId + ")";
}
_peerId = args;
String str = "{\"id\":\"" + String(_node->getId()) + "\",\"Link\":{\"peerId\":\"" + _peerId + "\"}}";
_node->announce(str);
return "New link with (" + _peerId + ")";
};
char * Link::args() {return "<String peerId>"; };