-
Notifications
You must be signed in to change notification settings - Fork 35
/
MQTTfx_Script.js
45 lines (33 loc) · 911 Bytes
/
MQTTfx_Script.js
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
//MQTT.fx script fountain, modified by Stephen Borsay
var Thread = Java.type("java.lang.Thread");
var topic = "iot/mqttfx";
var waitTime = 2000;
var iterations = 10;
function execute(action) {
out("Test Script: " + action.getName());
for (var i = 0; i < iterations; i++) {
sendPayload();
Thread.sleep(waitTime);
}
action.setExitCode(0);
action.setResultText("done.");
out("Test Script: Done");
return action;
}
function sendPayload() {
var temp = Math.round(Math.random()*130);
var humid = Math.round(Math.random()*100);
var ts = Date.now();
var IoT_Payload = {
"temperature" : temp,
"humidity" : humid,
"timestamps" : ts
}
var payload = JSON.stringify(IoT_Payload)
mqttManager.publish(topic, payload);
out("Topic is: \n" + topic);
out("payload sent \n" + payload);
}
function out(message){
output.print(message);
}