var options = {
'username': username,
'password': password,
'clientId': clientId,
'keepalive': 90,
'connectTimeout': 3000
}
var client = mqtt.connect('wxs://xxxxx',options)
var topic = ‘xxx’
client.on('connect', function() {
client.subscribe(topic, { 'qos': 0 })
console.log('链接上')
})
client.on('message', function(topic, message) {
console.log('topic:' + topic + ' msg:' + message.toString())
})
var i = 0
setInterval(function() {
client.publish(topic, 'Hello mqtt ' + (i++))
}, 1000)
报错
mqtt版本"^4.3.7", 哪位大神看下哪里错了呢?