1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
                mqttClient.on('connect', function () {
                    console.log('MQTT 連接成功');
                    updateMQTTStatus(true);
                });

                mqttClient.on('error', function (error) {
                    console.error('MQTT 連接錯誤:', error);
                    updateMQTTStatus(false);
                    alert('MQTT 連接失敗: ' + error.message);
                });

                mqttClient.on('close', function () {
                    console.log('MQTT 連接關閉');
                    updateMQTTStatus(false);
                });