MQTT.fx脚本Scripts使用
1. 概述
MQTT.fx官方网站:http://mqttfx.jensd.de/
本节讲述MQTT.fx的高级用法,通过js脚本发送和接收云端的消息。当你需要连续向云端发送多条消息时,脚本特别好用。
2. MQTT.fx的脚本
系统已经有一个模板,可以复制后添加自己的功能。

3. Script属性上报Publish
周期发送数据。
js程序:
var Thread = Java.type("java.lang.Thread");
function execute(action) {
var temp;
out("Test Script: " + action.getName());
for (var i = 0; i < 10; i++) {
temp = random(10, 27);
publishTemp(temp);
Thread.sleep(300000);
}
action.setExitCode(0);
action.setResultText("done.");
out("Test Script: Done");
return action;
}
function publishTemp(temp) {
out("temp value : " + temp);
var data = '{"id":"1","version":"1.0","params":{"Temperature":' + temp +'},"method":"thing.event.property.post"}';
mqttManager.publish("/sys/a1KDpQ8yhGW/BedroomTemperature/thing/event/property/post", data);
}
function out(message){
output.print(message);
}

浙公网安备 33010602011771号