-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMQTTLegacy.lf
49 lines (45 loc) · 1.59 KB
/
MQTTLegacy.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 program illustrates how to interface to a legacy MQTT service that has no connection with
* Lingua Franca. The "Publisher" reactor publishes messages every 5s on topic "legacy" that any
* other MQTT application can subscribe to. For example, you can subscribe to these messages using
* the command-line utility (in another window):
*
* mosquitto_sub -t 'legacy'
*
* You can publish your own messages on this topic using any MQTT publisher, such as the command
* line utility:
*
* mosquitto_pub -t 'legacy' -m '******* My own message!'
*
* This is a federated program, the publisher and subscriber run in separate programs. This would
* work pretty much the same way, however, as an unfederated program. To run as an unfederated
* program, just change the `federated` keyword to `main`.
*
* See README.md for prerequisites and further information.
*
* @author Edward A. Lee
*/
target C {
timeout: 1 min
}
import MQTTPublisher from "lib/MQTTPublisher.lf"
import MQTTSubscriber from "lib/MQTTSubscriber.lf"
import MessageGenerator, PrintMessage from "lib/private/MQTTTestReactors.lf"
reactor Publisher {
msg = new MessageGenerator(root = "Legacy Message", period = 5 sec)
pub = new MQTTPublisher(topic="legacy", address="tcp://localhost:1883", include_timestamp=false)
msg.message -> pub.in
}
reactor Subscriber {
sub = new MQTTSubscriber(
address="tcp://localhost:1883",
topic="legacy",
use_physical_time=true,
offset = 0 sec)
dsp = new PrintMessage()
sub.message -> dsp.message
}
main reactor {
source = new Publisher()
destination = new Subscriber()
}