added changes to home, integrated sms from snjzb, and fixed minor error

This commit is contained in:
Russel Yasol
2024-05-28 14:25:12 +08:00
parent 61cdfebc8a
commit 4a3a7775dd
6 changed files with 1289 additions and 497 deletions

View File

@@ -1,12 +0,0 @@
#!/bin/bash
SMS_FORMAT="AT+CMGF=1"
SMS_LIST="AT+CMGL=\"ALL\""
send_at_command() {
local command="$1"
echo -en "$command\r\n" | microcom -t 2000 /dev/ttyOUT2
}
send_at_command "$SMS_FORMAT"
runcmd=$(send_at_command "$SMS_LIST")
echo "Content-type: text/plain"
echo "$runcmd"

View File

@@ -20,35 +20,12 @@ fi
phone_number="$number"
message_encoded="$msg"
phone_number="+86$phone_number"
send_at_command() {
local cmd=$1
echo "Sending command: $cmd" >&2
echo -en "$cmd\r" | microcom -t 1000 /dev/ttyOUT2
sleep 2
local response=$(microcom -t 1000 /dev/ttyOUT2)
echo "Response: $response" >&2
echo "$response"
echo -en "$cmd\r" | microcom -t 100 /dev/ttyOUT2
}
send_at_command "AT+CMGF=1"
send_at_command "AT+CSCS=\"UCS2\""
encode_ucs2() {
local input="$1"
local output=""
local i
for ((i=0; i<${#input}; i++)); do
hex=$(printf "%04X" "'${input:$i:1}")
output="$output$hex"
done
echo "$output"
}
phone_number_ucs2=$(encode_ucs2 "$phone_number")
ATCMD="AT+CMGS=\"$phone_number_ucs2\""
send_at_command "$ATCMD"
runcmd=$((echo -en "$message_encoded"; sleep 1; echo -en "\x1A") | microcom -t 1000 /dev/ttyOUT2)
send_at_command "AT+CMGS=\"$phone_number\","$Command""
runcmd=$((echo -en "$message_encoded"; echo -en "\x1A") | microcom -t 500 /dev/ttyOUT2)
echo "$runcmd"