用SimFAS物联网中控发布MQTT信息只需要下面4行代码就可以完成。
mqtt=import("system.mqtt");
mqtt.connect("iot.eclipse.org",1883);
erro=mqtt.publish("iot.channel.demo","hello MQTT");
mqtt.disconnect();
其中,这里涉及到的参数如下:
MQTT 域名 : "iot.eclipse.org"
MQTT 端口 : 1883
发布频道: "iot.channel.demo"
发布内容: "hello MQTT"
可以根据项目实际需求,修改.
完整代码,请看:
-------MQTT 发布信息-----
----SimFAS中控编程代码----
--------Core V6.51-------
-----引入库文件---
mqtt=import("system.mqtt");
---连接MQTT服务器----
mqtt.connect("iot.eclipse.org",1883);
------发布信息到频道----
erro=mqtt.publish("iot.channel.demo","hello MQTT");
--断开链接
mqtt.disconnect();
----显示发送结果---
if (not erro) then
print("信息发布成功!") ;
else
print("发布失败:",erro);
end
中控上的编程界面截图如下:
SimFAS中控编程资料参考:http://www.simfas.cn/download_all.html以下是几个可用的MQTT国外站点
Server Broker Port Websocket
iot.eclipse.org Mosquitto 1883 / 8883 n/a
broker.hivemq.com HiveMQ 1883 8000
test.mosquitto.org Mosquitto 1883 / 8883 / 8884 8080 / 8081
test.mosca.io mosca 1883 80
broker.mqttdashboard.com HiveMQ 1883