ec20好不容易开始工作了,但是发现在并发比较高的情况下,出现了卡状态的问题,具体表现为 呼叫已经结束,但是asterisk中设备状态认为停留在dialing状态,无法释放,这时候也无法呼出,因为软件认为这个设备正忙
查询ec20 AT指令 发现了AT+CPAS指令 可以查询获取 设备状态,在此基础上结合重启命令,可以很大程度上自动恢复。
AT+CPAS
+CPAS: 0
0 准备(ME 允许来自 TA/TE 的命令)
2 未知(ME 未授权响应指令)
3 振铃(ME 准备好接收来自 TA/TE 的命令,但正在振铃)
4 呼叫进行中(ME 准备好来自 TA/TE 的命令,但当前有一个呼叫正在进行)
在写脚本的过程中,发现了比较麻烦的点是:
#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# 检查 Asterisk 服务是否运行
if ! pidof asterisk >/dev/null; then
echo "Asterisk service is not running. Exiting..."
exit 1
fi
check_device_state() {
local device_name=$1
local device_state=$(asterisk -rx "quectel show device state $device_name" | grep -E "State\s+:" | awk '{print $3}')
echo "$device_state"
}
device_info=$(asterisk -rx "quectel show devices" | grep "Dialing" | awk '{print $1}')
echo "$device_info"
for line in $device_info; do
# 循环10次
need_deal=0
need_try=10
for ((i=1; i<=need_try; i++)); do
# 定义设备名称
device_name=${line%% *}
# 获取设备状态
device_state=$(check_device_state "$device_name")
echo "$device_name state: $device_state"
# 判断设备状态是否为 Dialing
if [[ $device_state == "Dialing" ]]; then
# 进入 Asterisk 命令
cpas_result=$(expect -c "
spawn asterisk -r
expect \"CLI>\"
send \"quectel cmd $device_name \\\"AT+CPAS\\\"\\r\"
expect \"OK\"
expect \"CLI>\"
exit
")
# 提取值并判断
cpas_value=$(echo $cpas_result | grep -oE "+CPAS: [0-9]+" | awk '{print $2}')
if [[ $cpas_value == "0" ]]; then
# 执行重启命令
((need_deal++))
echo "$device_name may be something wrong,checks:$need_deal"
sleep 3
#asterisk -rx "quectel restart now $device_name"
else
echo "$device_name looks normal..."
break
fi
fi
done
if [[ $need_deal == $need_try ]]; then
echo "$device_name looks wrong"
/etc/asterisk/sh/tell_qy.sh "$device_name 发现问题,重启中..."
asterisk -rx "quectel restart now $device_name"
fi
done