added dedicated NR-CA SA parser
This commit is contained in:
@@ -16,8 +16,8 @@ fi
|
||||
MYATCMD=$(printf '%b\n' "${atcmd//%/\\x}")
|
||||
if [ -n "${MYATCMD}" ]; then
|
||||
x=$(urldecode "$atcmd")
|
||||
# Initialize wait time to 2 seconds
|
||||
wait_time=2
|
||||
# Initialize wait time to 1 second
|
||||
wait_time=1000
|
||||
while true; do
|
||||
runcmd=$(echo -en "$x\r\n" | microcom -t $wait_time /dev/ttyOUT2)
|
||||
# Check if "OK" or "ERROR" is present in the response
|
||||
|
||||
24
simpleadmin/www/cgi-bin/get_sms
Normal file
24
simpleadmin/www/cgi-bin/get_sms
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This is a simple scrip that fetches the SMS messages from the device
|
||||
SMS_MESSAGE_INDICATION="AT+CNMI=2,1"
|
||||
SMS_FORMAT="AT+CMGF=1"
|
||||
SMS_LIST="AT+CMGL=\"ALL\""
|
||||
|
||||
# Send the all the AT commands 1 by 1 with 2 seconds waiting time for each command
|
||||
runcmd=$(echo -en "$SMS_MESSAGE_INDICATION\r\n" | microcom -t 1000 /dev/ttyOUT2)
|
||||
runcmd=$(echo -en "$SMS_FORMAT\r\n" | microcom -t 1000 /dev/ttyOUT2)
|
||||
|
||||
while true; do
|
||||
runcmd=$(echo -en "$SMS_LIST\r\n" | microcom -t 2000 /dev/ttyOUT2)
|
||||
if [[ $runcmd =~ "OK" ]] || [[ $runcmd =~ "ERROR" ]]; then
|
||||
break
|
||||
fi
|
||||
((wait_time++))
|
||||
done
|
||||
|
||||
|
||||
# Print the list of SMS messages as JSON plain text
|
||||
echo "Content-type: text/plain"
|
||||
echo ""
|
||||
echo $runcmd
|
||||
@@ -99,61 +99,20 @@
|
||||
function atCommands() {
|
||||
return {
|
||||
isLoading: false,
|
||||
atcmd: 'AT+CMGL="ALL"',
|
||||
atCommandResponse: null,
|
||||
atCommandResponse: "",
|
||||
// get the SMS list through cgi-bin/get_sms
|
||||
sendAtCommand() {
|
||||
this.isLoading = true; // Set loading state to true before fetching data
|
||||
fetch(
|
||||
"/cgi-bin/get_atcommand?" +
|
||||
new URLSearchParams({
|
||||
atcmd: this.atcmd,
|
||||
})
|
||||
)
|
||||
.then((res) => {
|
||||
return res.text();
|
||||
})
|
||||
this.isLoading = true;
|
||||
fetch("/cgi-bin/get_sms")
|
||||
.then((response) => response.text())
|
||||
.then((data) => {
|
||||
this.atCommandResponse = data;
|
||||
// Split the response into individual messages
|
||||
const messages = data.trim().split("\n\n");
|
||||
|
||||
// Parse each message and construct an array of objects
|
||||
const parsedMessages = messages.map((message) => {
|
||||
const lines = message.split("\n");
|
||||
const sender = decodeHexString(
|
||||
lines[1].split(",")[2].slice(1, -1)
|
||||
);
|
||||
const time = lines[2].split(',"')[1];
|
||||
const messageText = decodeHexString(lines[3]);
|
||||
return {
|
||||
"Người gửi": sender,
|
||||
"Thời gian": time,
|
||||
"Tin nhắn": messageText,
|
||||
};
|
||||
});
|
||||
|
||||
// Log the parsed messages array as JSON to the console
|
||||
console.log(JSON.stringify(parsedMessages, null, 2));
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Không thể tìm thấy dữ liệu:", error);
|
||||
})
|
||||
.finally(() => {
|
||||
this.isLoading = false; // Set loading state to false after fetching data
|
||||
console.log(data);
|
||||
this.isLoading = false;
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
// Hàm giải mã chuỗi hex sang văn bản
|
||||
function decodeHexString(hexString) {
|
||||
let decodedString = "";
|
||||
for (let i = 0; i < hexString.length; i += 4) {
|
||||
let hex = hexString.substr(i, 4);
|
||||
let intValue = parseInt(hex, 16);
|
||||
decodedString += String.fromCharCode(intValue);
|
||||
}
|
||||
return decodedString;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user