天天看點

SimFAS 物聯網中控 物聯網MQTT釋出資訊,中控MQTT物聯網程式設計代碼

用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 物聯網中控 物聯網MQTT釋出資訊,中控MQTT物聯網程式設計代碼

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

繼續閱讀