incorporated atcmd dynamic wait time to get_atcommand
This commit is contained in:
@@ -97,9 +97,9 @@
|
|||||||
<div class="content">
|
<div class="content">
|
||||||
<textarea
|
<textarea
|
||||||
class="textarea"
|
class="textarea"
|
||||||
x-bind:placeholder="isLoading ? 'Fetching response, please wait...' : 'Please send only 1 AT command at a time'"
|
placeholder="Please send only 1 AT command at a time"
|
||||||
rows="10"
|
rows="10"
|
||||||
x-text="atCommandResponse"
|
x-text="isLoading ? 'Fetching response, please wait...' : atCommandResponse"
|
||||||
></textarea>
|
></textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -120,6 +120,18 @@
|
|||||||
</header>
|
</header>
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
<!-- <div class="field" style="margin-bottom: 1rem">
|
||||||
|
<p class="control">
|
||||||
|
<button
|
||||||
|
class="button is-danger"
|
||||||
|
click="sendRebootCommand()"
|
||||||
|
:disabled="isRebootClicked"
|
||||||
|
|
||||||
|
>
|
||||||
|
Reboot
|
||||||
|
</button>
|
||||||
|
</p>
|
||||||
|
</div> -->
|
||||||
<!-- Add your useful commands content here -->
|
<!-- Add your useful commands content here -->
|
||||||
<p>Here are some useful commands:</p>
|
<p>Here are some useful commands:</p>
|
||||||
<ul>
|
<ul>
|
||||||
@@ -240,7 +252,7 @@
|
|||||||
return {
|
return {
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
atcmd: null,
|
atcmd: null,
|
||||||
atCommandResponse: '',
|
atCommandResponse: "",
|
||||||
sendAtCommand() {
|
sendAtCommand() {
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
fetch(
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -3,24 +3,30 @@ QUERY_STRING=$(echo "${QUERY_STRING}" | sed 's/;//g')
|
|||||||
function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
|
function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
|
||||||
|
|
||||||
if [ "${QUERY_STRING}" ]; then
|
if [ "${QUERY_STRING}" ]; then
|
||||||
|
export IFS="&"
|
||||||
export IFS="&"
|
for cmd in ${QUERY_STRING}; do
|
||||||
for cmd in ${QUERY_STRING}; do
|
if [ "$(echo $cmd | grep '=')" ]; then
|
||||||
|
key=$(echo $cmd | awk -F '=' '{print $1}')
|
||||||
if [ "$(echo $cmd | grep '=')" ]; then
|
value=$(echo $cmd | awk -F '=' '{print $2}')
|
||||||
key=$(echo $cmd | awk -F '=' '{print $1}')
|
eval $key=$value
|
||||||
value=$(echo $cmd | awk -F '=' '{print $2}')
|
fi
|
||||||
eval $key=$value
|
done
|
||||||
fi
|
|
||||||
|
|
||||||
done
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
MYATCMD=$(printf '%b\n' "${atcmd//%/\\x}")
|
MYATCMD=$(printf '%b\n' "${atcmd//%/\\x}")
|
||||||
if [ -n "${MYATCMD}" ]; then
|
if [ -n "${MYATCMD}" ]; then
|
||||||
x=$(urldecode "$atcmd")
|
x=$(urldecode "$atcmd")
|
||||||
runcmd=$(echo -en "$x\r\n" | microcom -t 2000 /dev/ttyOUT2)
|
# 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
|
fi
|
||||||
|
|
||||||
echo "Content-type: text/plain"
|
echo "Content-type: text/plain"
|
||||||
|
|||||||
Reference in New Issue
Block a user