-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMQTTDistributedActivity.lf
49 lines (44 loc) · 1.49 KB
/
MQTTDistributedActivity.lf
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
/**
* This is a federated LF program consisting of two unconnected federates that communicate via MQTT,
* but where the destination reactor has activity that interferes with its ability to use the
* incoming timestamps from the publisher. This program will print a warning each time it receives a
* message. To get rid of the warnings, you can set the `use_physical_time` parameter of the
* `MQTTSubscriber` to true, and then it will not use the incoming timestamps (except to measure
* apparent latency).
*
* See README.md for prerequisites and further information.
*
* @author Edward A. Lee
*/
target C {
timeout: 10 secs,
coordination: centralized
}
import MQTTPublisher from "lib/MQTTPublisher.lf"
import MQTTSubscriber from "lib/MQTTSubscriber.lf"
import MessageGenerator, PrintMessage from "lib/private/MQTTTestReactors.lf"
reactor Source {
msg = new MessageGenerator(root = "Hello World")
pub = new MQTTPublisher(topic="my/test", address="tcp://localhost:1883", include_timestamp=true)
msg.message -> pub.in
}
reactor Destination {
timer t(1001 ms, 1 s)
sub = new MQTTSubscriber(
address="tcp://localhost:1883",
topic="my/test",
use_physical_time=false,
offset = 0 sec)
dsp = new PrintMessage()
sub.message -> dsp.message
reaction(t) {=
tag_t tag = lf_tag();
lf_print("Destination: Activity at " PRINTF_TAG,
tag.time - lf_time_start(), tag.microstep
);
=}
}
federated reactor {
source = new Source()
destination = new Destination()
}