Created
September 4, 2020 11:09
-
-
Save jforge/8a21eef42d35b75db3fad76172c6fbf5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Thread = Java.type("java.lang.Thread"); | |
| var Instant = Java.type("java.time.Instant"); | |
| var topic = "cybus/machine/1CY816L0ⓥ3/lastMovement"; | |
| function execute(action) { | |
| out("Test Script: " + action.getName()); | |
| for (var i = 0; i < 1000; i++) { | |
| randomTimeSeriesPing(); | |
| Thread.sleep(2000); | |
| } | |
| action.setExitCode(0); | |
| action.setResultText("done."); | |
| out("Test Script: Done"); | |
| return action; | |
| } | |
| function randomTimeSeriesPing() { | |
| var time = Instant.now().toString(); | |
| out("time published: " + time); | |
| var randomTemp = Math.random()*100; | |
| var randomX = Math.random()*100; | |
| var randomY = Math.random()*100; | |
| var randomZ = Math.random()*100; | |
| var message = { | |
| machineId: "1CY816L0ⓥ3", | |
| eventTimestamp: time, | |
| temperature: randomTemp, | |
| position: { | |
| X: randomX, | |
| Y: randomY, | |
| Z: randomZ | |
| }, | |
| status: "operational" | |
| }; | |
| mqttManager.publish(topic, JSON.stringify(message)); | |
| } | |
| function out(message){ | |
| output.print(message); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment