hot fix for csq async problem

This commit is contained in:
Russel Yasol
2024-05-23 07:11:01 +08:00
parent 46696cdf28
commit b642d1e283

View File

@@ -649,7 +649,9 @@
atcmd: this.atcmd, atcmd: this.atcmd,
}) })
).then((response) => { ).then((response) => {
response.text().then((data) => { response
.text()
.then((data) => {
const rawdata = data; const rawdata = data;
const lines = rawdata.split("\n"); const lines = rawdata.split("\n");
// delete first element of the array // delete first element of the array
@@ -657,8 +659,14 @@
console.log(lines); console.log(lines);
// Parse the temperature // Parse the temperature
const temp1 = lines[15].split(",")[1].replace(/"/g, "").trim(); const temp1 = lines[15]
const temp2 = lines[16].split(",")[1].replace(/"/g, "").trim(); .split(",")[1]
.replace(/"/g, "")
.trim();
const temp2 = lines[16]
.split(",")[1]
.replace(/"/g, "")
.trim();
// Average the 2 temperatures then add degree symbol // Average the 2 temperatures then add degree symbol
this.temperature = (parseInt(temp1) + parseInt(temp2)) / 2; this.temperature = (parseInt(temp1) + parseInt(temp2)) / 2;
// Round the temperature to only show whole numbers // Round the temperature to only show whole numbers
@@ -696,7 +704,10 @@
this.ipv6 = lines[25].split(",")[4].replace(/"/g, ""); this.ipv6 = lines[25].split(",")[4].replace(/"/g, "");
// If no network IP detected, consider as disconnected. Return all values as unknown (except temperature, sim, network provider, mccmnc, and apn) // If no network IP detected, consider as disconnected. Return all values as unknown (except temperature, sim, network provider, mccmnc, and apn)
if (this.ipv4 == "0.0.0.0" && this.ipv6 == "0:0:0:0:0:0:0:0") { if (
this.ipv4 == "0.0.0.0" &&
this.ipv6 == "0:0:0:0:0:0:0:0"
) {
this.temperature = this.temperature; this.temperature = this.temperature;
this.active_sim = this.active_sim; this.active_sim = this.active_sim;
this.network_provider = this.network_provider; this.network_provider = this.network_provider;
@@ -752,12 +763,16 @@
lines[27].match(/FDD/) != null || lines[27].match(/FDD/) != null ||
lines[27].match(/TDD/) != null lines[27].match(/TDD/) != null
) { ) {
networkMode2 = lines[27].split(",")[2].replace(/"/g, ""); networkMode2 = lines[27]
.split(",")[2]
.replace(/"/g, "");
networkMode2 = networkMode2.split(",")[0].trim(); networkMode2 = networkMode2.split(",")[0].trim();
} }
if (networkMode2 !== "LTE") { if (networkMode2 !== "LTE") {
networkMode2 = lines[28].split(":")[1].replace(/"/g, ""); networkMode2 = lines[28]
.split(":")[1]
.replace(/"/g, "");
networkMode2 = networkMode2.split(",")[0]; networkMode2 = networkMode2.split(",")[0];
if ( if (
@@ -899,8 +914,12 @@
this.network_mode.match(/LTE/) != null && this.network_mode.match(/LTE/) != null &&
this.network_mode.match(/NR5G-NSA/) == null this.network_mode.match(/NR5G-NSA/) == null
) { ) {
let lte_bw_ul = lines[27].split(",")[10].replace(/"/g, ""); let lte_bw_ul = lines[27]
let lte_bw_dl = lines[27].split(",")[11].replace(/"/g, ""); .split(",")[10]
.replace(/"/g, "");
let lte_bw_dl = lines[27]
.split(",")[11]
.replace(/"/g, "");
lte_bw_dl = parseInt(lte_bw_dl); lte_bw_dl = parseInt(lte_bw_dl);
lte_bw_ul = parseInt(lte_bw_ul); lte_bw_ul = parseInt(lte_bw_ul);
@@ -948,7 +967,8 @@
let rsrq = parseInt(this.rsrqLTE); let rsrq = parseInt(this.rsrqLTE);
// Calculate the RSRQ percentage // Calculate the RSRQ percentage
this.rsrqLTEPercentage = this.calculateRSRQPercentage(rsrq); this.rsrqLTEPercentage =
this.calculateRSRQPercentage(rsrq);
// Get the RSRP // Get the RSRP
this.rsrpLTE = lines[27].split(",")[13].replace(/"/g, ""); this.rsrpLTE = lines[27].split(",")[13].replace(/"/g, "");
@@ -1034,7 +1054,8 @@
let rsrq = parseInt(this.rsrqLTE); let rsrq = parseInt(this.rsrqLTE);
// Calculate the RSRQ percentage // Calculate the RSRQ percentage
this.rsrqLTEPercentage = this.calculateRSRQPercentage(rsrq); this.rsrqLTEPercentage =
this.calculateRSRQPercentage(rsrq);
// Get the RSRP // Get the RSRP
this.rsrpLTE = lines[28].split(",")[11].replace(/"/g, ""); this.rsrpLTE = lines[28].split(",")[11].replace(/"/g, "");
@@ -1085,7 +1106,8 @@
rsrq = parseInt(this.rsrqNR); rsrq = parseInt(this.rsrqNR);
// Calculate the RSRQ percentage // Calculate the RSRQ percentage
this.rsrqNRPercentage = this.calculateRSRQPercentage(rsrq); this.rsrqNRPercentage =
this.calculateRSRQPercentage(rsrq);
// Get the RSRP NR // Get the RSRP NR
this.rsrpNR = lines[29].split(",")[4].replace(/"/g, ""); this.rsrpNR = lines[29].split(",")[4].replace(/"/g, "");
@@ -1122,6 +1144,26 @@
); );
} }
} }
})
.then(() => {
if (this.network_mode !== "NR5G-SA") {
this.atcmd = "AT+CSQ";
fetch(
"/cgi-bin/get_atcommand?" +
new URLSearchParams({
atcmd: this.atcmd,
})
).then((response) => {
response.text().then((data) => {
const rawdata = data;
const lines = rawdata.split("\n");
console.log("CSQ: ", lines);
this.csq = lines[1].split(":")[1].split(",")[0].trim();
});
});
}
}); });
}); });
}, },
@@ -1230,27 +1272,6 @@
} }
}, },
fetchCSQ() {
if (this.network_mode !== "NR5G-SA") {
this.atcmd = "AT+CSQ";
fetch(
"/cgi-bin/get_atcommand?" +
new URLSearchParams({
atcmd: this.atcmd,
})
).then((response) => {
response.text().then((data) => {
const rawdata = data;
const lines = rawdata.split("\n");
console.log("CSQ: ", lines);
this.csq = lines[1].split(":")[1].split(",")[0].trim();
});
});
}
},
fetchSIMInfo() { fetchSIMInfo() {
this.atcmd = "AT+QSIMSTAT?"; this.atcmd = "AT+QSIMSTAT?";
@@ -1281,9 +1302,6 @@
}) })
.then(() => { .then(() => {
this.fetchNetworkInfo(); this.fetchNetworkInfo();
})
.then(() => {
this.fetchCSQ();
}); });
}); });
}, },
@@ -1486,11 +1504,6 @@
// Ensure fetchSIMInfo returns a promise // Ensure fetchSIMInfo returns a promise
this.fetchSIMInfo(); this.fetchSIMInfo();
// // sleep for 2 seconds
// setTimeout(() => {
// this.fetchCSQ();
// }, 2000);
this.requestPing() this.requestPing()
.then((data) => { .then((data) => {
const response = data.trim(); const response = data.trim();