You've already forked fm-dx-webserver
mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-02-26 14:11:59 +01:00
serialport reconnect rework - v1.3.0.1
This commit is contained in:
committed by
GitHub
parent
a7931257d5
commit
b4047cbabb
@@ -425,6 +425,18 @@ function handleData(wss, receivedData, rdsWss) {
|
||||
}
|
||||
}
|
||||
|
||||
// Serialport retry code when port is open but communication is lost (additional code in index.js)
|
||||
isSerialportAlive = true;
|
||||
lastFrequencyAlive = '87.500';
|
||||
setInterval(() => {
|
||||
lastFrequencyAlive = initialData.freq;
|
||||
// Activate serialport retry if handleData has not been executed for over 10 seconds
|
||||
if (((Date.now() - lastUpdateTime) > 8000) && !isSerialportRetrying && serverConfig.xdrd.wirelessConnection === false) {
|
||||
isSerialportAlive = false;
|
||||
isSerialportRetrying = true;
|
||||
}
|
||||
}, 2000);
|
||||
|
||||
function showOnlineUsers(currentUsers) {
|
||||
dataToSend.users = currentUsers;
|
||||
initialData.users = currentUsers;
|
||||
|
||||
@@ -126,6 +126,28 @@ function checkIPv6Support(callback) {
|
||||
});
|
||||
}
|
||||
|
||||
// Serialport retry code when port is open but communication is lost (additional code in datahandler.js)
|
||||
isSerialportRetrying = false;
|
||||
|
||||
setInterval(() => {
|
||||
if (!isSerialportAlive && serverConfig.xdrd.wirelessConnection === false) {
|
||||
isSerialportAlive = true;
|
||||
isSerialportRetrying = true;
|
||||
if (serialport && serialport.isOpen) {
|
||||
logWarn('Communication lost from ' + serverConfig.xdrd.comPort + ', force closing serialport.');
|
||||
setTimeout(() => {
|
||||
serialport.close((err) => {
|
||||
if (err) {
|
||||
logError('Error closing serialport: ', err.message);
|
||||
}
|
||||
});
|
||||
}, 1000);
|
||||
} else {
|
||||
logWarn('Communication lost from ' + serverConfig.xdrd.comPort + '.');
|
||||
}
|
||||
}
|
||||
}, 2000);
|
||||
|
||||
// Serial Connection
|
||||
function connectToSerial() {
|
||||
if (serverConfig.xdrd.wirelessConnection === false) {
|
||||
@@ -150,6 +172,7 @@ if (serverConfig.xdrd.wirelessConnection === false) {
|
||||
}
|
||||
|
||||
logInfo('Using COM device: ' + serverConfig.xdrd.comPort);
|
||||
isSerialportAlive = true;
|
||||
setTimeout(() => {
|
||||
serialport.write('x\n');
|
||||
}, 3000);
|
||||
@@ -163,9 +186,12 @@ if (serverConfig.xdrd.wirelessConnection === false) {
|
||||
serialport.write('T' + Math.round(serverConfig.defaultFreq * 1000) + '\n');
|
||||
dataHandler.initialData.freq = Number(serverConfig.defaultFreq).toFixed(3);
|
||||
dataHandler.dataToSend.freq = Number(serverConfig.defaultFreq).toFixed(3);
|
||||
} else if (lastFrequencyAlive && isSerialportRetrying) { // Serialport retry code when port is open but communication is lost
|
||||
serialport.write('T' + (lastFrequencyAlive * 1000) + '\n');
|
||||
} else {
|
||||
serialport.write('T87500\n');
|
||||
}
|
||||
isSerialportRetrying = false;
|
||||
|
||||
serialport.write('A0\n');
|
||||
serialport.write('F-1\n');
|
||||
@@ -190,6 +216,7 @@ if (serverConfig.xdrd.wirelessConnection === false) {
|
||||
serialport.on('close', () => {
|
||||
logWarn('Disconnected from ' + serverConfig.xdrd.comPort + '. Attempting to reconnect.');
|
||||
setTimeout(() => {
|
||||
isSerialportRetrying = true;
|
||||
connectToSerial();
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user