-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMQTTPhysical.lf
34 lines (31 loc) · 1.2 KB
/
MQTTPhysical.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
/**
* This program periodically publishes on a topic and, in a different part of the program,
* subscribes to the same topic. The timestamp at the receiving end will be nondeterministically
* determined from the local physical clock. The difference between the publisher's logical time and
* the subscriber's logical time is a reasonable measure of the latency through the MQTT broker.
* This gives behavior similar to an LF [physical
* connection](https://www.lf-lang.org/docs/handbook/composing-reactors?target=c#physical-connections).
*
* See README.md for prerequisites and further information.
*
* @author Ravi Akella
* @author Edward A. Lee
*/
target C {
timeout: 10 secs
}
import MQTTPublisher from "lib/MQTTPublisher.lf"
import MQTTSubscriber from "lib/MQTTSubscriber.lf"
import MessageGenerator, PrintMessage from "lib/private/MQTTTestReactors.lf"
main reactor {
pub = new MQTTPublisher(topic="my/test", address="tcp://localhost:1883")
msg = new MessageGenerator(root = "Hello World")
msg.message -> pub.in
sub = new MQTTSubscriber(
address="tcp://localhost:1883",
topic="my/test",
use_physical_time=true,
offset=0)
dsp = new PrintMessage()
sub.message -> dsp.message
}