1
0
mirror of https://github.com/KubaPro010/fm-dx-webserver.git synced 2026-02-26 22:13:53 +01:00

Serial port autoreconnect on close

This commit is contained in:
AmateurAudioDude
2024-08-13 03:37:17 +10:00
committed by GitHub
parent 6f4b23265a
commit d24d513466

View File

@@ -80,6 +80,9 @@ if (serverConfig.xdrd.wirelessConnection === false) {
serialport.open((err) => {
if (err) {
logError('Error opening port: ' + err.message);
setTimeout(() => {
connectToSerial();
}, 5000);
return;
}
@@ -120,6 +123,13 @@ if (serverConfig.xdrd.wirelessConnection === false) {
});
});
// Handle port closure
serialport.on('close', () => {
logWarn('Disconnected from ' + serverConfig.xdrd.comPort + '. Attempting to reconnect.');
setTimeout(() => {
connectToSerial();
}, 5000);
});
return serialport;
}
}