|
|
@@ -19,12 +19,19 @@ export default {
|
|
|
mqttResponse: () => {}
|
|
|
}
|
|
|
) {
|
|
|
+ const clientId = new Date().getTime()
|
|
|
const options = {
|
|
|
clean: true,
|
|
|
connectTimeout: 4000,
|
|
|
- clientId: new Date().getTime(),
|
|
|
+ clientId: clientId,
|
|
|
username: 'admin',
|
|
|
- password: 'houyaf1!'
|
|
|
+ password: 'houyaf1!',
|
|
|
+ will: {
|
|
|
+ topic: 'willTopic',
|
|
|
+ payload: clientId + '与服务器断开连接',
|
|
|
+ retain: false,
|
|
|
+ qos: 0
|
|
|
+ }
|
|
|
}
|
|
|
const client = mqtt.connect(mqttUrl, options)
|
|
|
client.on('connect', function() {
|
|
|
@@ -48,6 +55,9 @@ export default {
|
|
|
client.on('error', (error) => {
|
|
|
console.log('连接失败:', error)
|
|
|
})
|
|
|
+ client.on('close', function() {
|
|
|
+ console.log('Disconnected')
|
|
|
+ })
|
|
|
client.on('offline', function() {
|
|
|
console.log('offline')
|
|
|
})
|