提交 2ba6eaa6 authored 作者: 詹银鑫's avatar 詹银鑫

链接mqtt

上级 09ddfebf
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
"delaunator": "^5.0.0", "delaunator": "^5.0.0",
"echarts": "^5.5.0", "echarts": "^5.5.0",
"gsap": "^3.12.2", "gsap": "^3.12.2",
"mqtt": "^5.11.0", "mqtt": "^5.0.0",
"normalize.css": "^8.0.1", "normalize.css": "^8.0.1",
"point-in-polygon": "^1.1.0", "point-in-polygon": "^1.1.0",
"three": "0.161.0", "three": "0.161.0",
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
"delaunator": "^5.0.0", "delaunator": "^5.0.0",
"echarts": "^5.5.0", "echarts": "^5.5.0",
"gsap": "^3.12.2", "gsap": "^3.12.2",
"mqtt": "^5.11.0", "mqtt": "^5.0.0",
"normalize.css": "^8.0.1", "normalize.css": "^8.0.1",
"point-in-polygon": "^1.1.0", "point-in-polygon": "^1.1.0",
"three": "0.161.0", "three": "0.161.0",
......
...@@ -3,16 +3,17 @@ import mqtt from 'mqtt' ...@@ -3,16 +3,17 @@ import mqtt from 'mqtt'
// MQTT 配置 // MQTT 配置
const options = { const options = {
// clean: true, // clean: true,
keepalive: 30, // 心跳间隔(秒) // keepalive: 30, // 心跳间隔(秒)
connectTimeout: 15000, // 连接超时(毫秒) // connectTimeout: 15000, // 连接超时(毫秒)
clientId: 'web-client-' + Math.random().toString(16).substring(2, 8), clientId: 'web-client-' + Math.random().toString(16).substring(2, 8),
// username: '', // 如果需要认证 // username: '', // 如果需要认证
// password: '', // password: '',
protocolVersion: 4, // protocolVersion: 4,
} }
// MQTT 代理地址(示例使用公共测试服务器) // MQTT 代理地址(示例使用公共测试服务器)
const brokerUrl = 'ws://192.168.1.177:1883/mqtt' // const brokerUrl = 'mqtt://192.168.1.177:1883'
const brokerUrl = 'ws://192.168.1.177:8883/mqtt'
class MQTTClient { class MQTTClient {
constructor() { constructor() {
...@@ -22,7 +23,8 @@ class MQTTClient { ...@@ -22,7 +23,8 @@ class MQTTClient {
connect() { connect() {
console.log('Connecting to MQTT...') console.log('Connecting to MQTT...')
console.log("brokerUrl", brokerUrl) console.log("brokerUrl", brokerUrl)
this.client = mqtt.connect(brokerUrl, options) console.log("options", options)
this.client = mqtt.connect(brokerUrl,options)
// 连接成功 // 连接成功
this.client.on('connect', () => { this.client.on('connect', () => {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论