mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-07-30 16:59:15 +02:00
Serial port autoreconnect on close
This commit is contained in:
@@ -80,6 +80,9 @@ if (serverConfig.xdrd.wirelessConnection === false) {
|
|||||||
serialport.open((err) => {
|
serialport.open((err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
logError('Error opening port: ' + err.message);
|
logError('Error opening port: ' + err.message);
|
||||||
|
setTimeout(() => {
|
||||||
|
connectToSerial();
|
||||||
|
}, 5000);
|
||||||
return;
|
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;
|
return serialport;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user