24 lines
682 B
JavaScript
24 lines
682 B
JavaScript
var did=1037;
|
|
const clientId = 'mqttjs_' + Math.random().toString(16).substr(2, 8);
|
|
|
|
// 创建一个全局的 MQTT 客户端
|
|
var client = new Paho.MQTT.Client("mqtt.gpic.opmonitor.com", Number(8083), clientId);
|
|
|
|
// 设置接收消息的回调函数
|
|
client.onMessageArrived = function(message) {
|
|
console.error("~~~ ~~~");
|
|
console.info(message.payloadString);
|
|
};
|
|
|
|
// 连接到 MQTT 代理
|
|
client.connect({
|
|
onSuccess: function() {
|
|
console.log("已连接到 MQTT.GPIC 代理");
|
|
// 连接成功后,订阅主题
|
|
client.subscribe("mqtt/gpic_d/"+did+"/");
|
|
},
|
|
onFailure: function(errorMessage) {
|
|
console.log("连接失败: " + errorMessage.errorMessage);
|
|
}
|
|
});
|