收藏
回答

为什么连接开发者工具上可以连接mqtt,真机测试却连接不上?

  //连接mqtt服务器
  connectMqtt: function(id{
    var clinet_id = parseInt(Math.random() * 100 + 88888888810);
    console.log('wx_' + clinet_id);
    const options = {
        connectTimeout: 4000// 超时时间
        clientId: 'wx_' + clinet_id,
    }
    client = mqtt.connect('wxs://www.bmums.cn:8084/mqtt', options)
    client.on('reconnect'(error) => {
        console.log('正在重连:', error)
    })


    client.on('error'(error) => {
        console.log('连接失败:', error)
    })


    let that = this;
    var arr='$USR/DevJsonTx/';
    var sub=arr.concat(id)
    client.on('connect'(e) => {
        console.log('成功连接服务器')
       //订阅一个主题
        client.subscribe(sub, {
            qos: 0
        }, function(err{
            if (!err) {
                console.log("订阅成功")
            }
        })
    })
    client.on('message'function (topic, message{{

})


回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容
问题标签