From 80b34719a5fad4d0d9c7ae27a7040c87bc7429dd Mon Sep 17 00:00:00 2001 From: dr-dolomite Date: Sun, 17 Mar 2024 17:07:18 +0800 Subject: [PATCH] incorporated atcmd dynamic wait time to get_atcommand --- simpleadmin/www/atcommander.html | 39 ++++++++++++++++++++++++--- simpleadmin/www/cgi-bin/get_atcommand | 34 +++++++++++++---------- 2 files changed, 56 insertions(+), 17 deletions(-) diff --git a/simpleadmin/www/atcommander.html b/simpleadmin/www/atcommander.html index 1fe10be..81f64cb 100644 --- a/simpleadmin/www/atcommander.html +++ b/simpleadmin/www/atcommander.html @@ -97,9 +97,9 @@
@@ -120,6 +120,18 @@
+

Here are some useful commands:

    @@ -240,7 +252,7 @@ return { isLoading: false, atcmd: null, - atCommandResponse: '', + atCommandResponse: "", sendAtCommand() { this.isLoading = true; fetch( @@ -265,6 +277,27 @@ }, }; } + + function sendRebootCommand() { + var isRebootClicked = true; + console.log("Reboot command triggered"); + var atcmd = "AT+CFUN=1,1"; + fetch( + "/cgi-bin/get_atcommand?" + + new URLSearchParams({ + atcmd: atcmd, + }) + ) + .then((res) => { + return res.text(); + }) + .then((data) => { + console.log(data); // Logging the response for debugging purposes + }) + .catch((error) => { + console.error("Error:", error); + }); + } diff --git a/simpleadmin/www/cgi-bin/get_atcommand b/simpleadmin/www/cgi-bin/get_atcommand index 150f0e6..a4b13ad 100644 --- a/simpleadmin/www/cgi-bin/get_atcommand +++ b/simpleadmin/www/cgi-bin/get_atcommand @@ -3,24 +3,30 @@ QUERY_STRING=$(echo "${QUERY_STRING}" | sed 's/;//g') function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; } if [ "${QUERY_STRING}" ]; then - - export IFS="&" - for cmd in ${QUERY_STRING}; do - - if [ "$(echo $cmd | grep '=')" ]; then - key=$(echo $cmd | awk -F '=' '{print $1}') - value=$(echo $cmd | awk -F '=' '{print $2}') - eval $key=$value - fi - - done - + export IFS="&" + for cmd in ${QUERY_STRING}; do + if [ "$(echo $cmd | grep '=')" ]; then + key=$(echo $cmd | awk -F '=' '{print $1}') + value=$(echo $cmd | awk -F '=' '{print $2}') + eval $key=$value + fi + done fi MYATCMD=$(printf '%b\n' "${atcmd//%/\\x}") if [ -n "${MYATCMD}" ]; then - x=$(urldecode "$atcmd") - runcmd=$(echo -en "$x\r\n" | microcom -t 2000 /dev/ttyOUT2) + x=$(urldecode "$atcmd") + # Initialize wait time to 2 seconds + wait_time=2 + 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 + if [[ $runcmd =~ "OK" ]] || [[ $runcmd =~ "ERROR" ]]; then + break # Exit the loop if "OK" or "ERROR" is found + fi + # If neither "OK" nor "ERROR" is found, increment wait time by 1 second + ((wait_time++)) + done fi echo "Content-type: text/plain"