-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMQTTLogical.lf
35 lines (32 loc) · 1.36 KB
/
MQTTLogical.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
/**
* This program periodically publishes on a topic and, in a different part of the program,
* subscribes to the same topic. The publisher has `include_timestamp` set to `true`, and the
* subscriber has `use_physical_time` set to `false`. The program has no other activity, so as long
* as the time between publishing of events is larger than the total latency through the MQTT
* broker, the subscriber will see messages one microstep later than the publisher. By setting a
* positive `offset` at the subscriber, you can increase the logical time of the received message
* and get a zero microstep. This gives behavior similar to an LF connection with an `after` delay.
*
* 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", include_timestamp=true)
msg = new MessageGenerator(root = "Hello World")
msg.message -> pub.in
sub = new MQTTSubscriber(
address="tcp://localhost:1883",
topic="my/test",
use_physical_time=false,
offset=0)
dsp = new PrintMessage()
sub.message -> dsp.message
}