获取usbmodem状态

This commit is contained in:
刘有缘 2023-06-12 10:20:24 +08:00
parent 60b0a91506
commit 3eaca67d03
5 changed files with 129 additions and 256 deletions

View File

@ -23,6 +23,8 @@ function index()
entry({ "admin", "network", "usbmodem", "delete_sms" }, call("deleteSms"), nil).leaf = true
entry({ "admin", "network", "usbmodem", "send_at" }, call("sendAt"), nil).leaf = true
entry({ "admin", "network", "usbmodem", "modem_status" }, call("status"), nil).leaf = true
end
-- 删除短信
@ -49,6 +51,7 @@ function readSms()
luci.http.write_json(sim)
end
-- 发送短信
function sendSms()
local devv = tostring(uci:get("usbmodem", "@service[0]", "readport"))
local phone = http.formvalue("phone")
@ -64,6 +67,7 @@ function sendSms()
end
end
-- 发送指令
function sendAt()
local devv = tostring(uci:get("usbmodem", "@service[0]", "readport"))
local at_code = http.formvalue("code")
@ -76,3 +80,24 @@ function sendAt()
http.write_json(http.formvalue())
end
end
-- 获取状态
function status()
if luci.sys.call("usbmodem.sh status") == 0 then
leasefile="/tmp/usbmodem_status.log"
local fd = io.open(leasefile, "r")
if not fd then return end
while true do
local ln = fd:read("*l")
if not ln then
break
end
luci.http.write(ln)
luci.http.write("|")
end
fd:close()
else
luci.http.write("")
end
end

View File

@ -1,19 +1,71 @@
<%+header%>
<script type="text/javascript" src="<%=resource%>/cbi.js"></script>
<style>
.table {
border-collapse: collapse;
width: 100%;
}
.table .th, .td {
border-bottom: 1px solid var(--border-color-medium);
font-size: 12px;
padding: 10px;
text-align: justify;
display: table-cell;
vertical-align: top;
}
.table .tr:nth-child(odd) {
background-color: var(--background-color-medium)
}
.table .th span {
font-weight: normal;
padding-left: 5px;
}
</style>
<script>
function match(text, reg) {
let result = text.match(reg);
if (result && result.length > 0) {
return result[0].replaceAll(reg, '$1');
}
return '';
}
let $L = function (obj) {
return {
obj: obj,
html: function (html) {
this.obj.innerHTML = html
}
}
}
let $A = function (objs) {
return {
array: objs,
eachMatch: function (text, regx) {
for (let i = 0; i < regx.length; i++) {
if (this.array.length > i) {
$L(this.array[i]).html(match(text, regx[i]))
}
}
}
};
}
</script>
<div class="cbi-map">
<div class="cbi-map-descr" style="font-size: 28px; font-weight: bold;line-height: 50px">5G模组状态</div>
<div class="cbi-section">
<legend>基本信息</legend>
<div class="cbi-section-node">
<div class="table">
<div class="tr table-titles">
<div class="th">模组 :</div>
<div class="th">模组ID :</div>
<div class="th">厂商 :</div>
<div class="th">通讯端口 :</div>
<div class="th">温度 :</div>
<div class="th">协议 :</div>
<div class="tr table-titles" id="baseInfo">
<div class="th">厂商 : <span>读取中..</span></div>
<div class="th">模组 :<span>读取中..</span></div>
<div class="th">模组版本 :<span>读取中..</span></div>
<div class="th">温度 :<span>读取中..</span></div>
<div class="th">电压 :<span>读取中..</span></div>
</div>
</div>
</div>
@ -22,61 +74,49 @@
<legend>SIM卡信息</legend>
<div class="cbi-section-node">
<div class="table">
<div class="tr table-titles">
<div class="th">IMEI :</div>
<div class="th">IMSI :</div>
<div class="th">ICCID :</div>
<div class="th">电话号码 :</div>
<div class="th">SIM名称 :</div>
<div class="tr table-titles" id="SimInfo">
<div class="th">IMEI :<span>读取中..</span></div>
<div class="th">CIMI :<span>读取中..</span></div>
<div class="th">QCCID :<span>读取中..</span></div>
</div>
</div>
</div>
</div>
<div class="cbi-section">
<legend>信号情况</legend>
<div class="cbi-section-node">
<div class="table">
<div class="tr table-titles">
<div class="th">网络类型 :</div>
<div class="th">CSQ :</div>
<div class="th">信号强度 :</div>
<div class="th">RSSI :</div>
<div class="th">SINR :</div>
<div class="tr table-titles" id="CSQInfo">
<div class="th">网络类型 :<span>读取中..</span></div>
<div class="th">CSQ :<span>读取中..</span></div>
<div class="th">信号强度 :<span>读取中..</span></div>
</div>
</div>
<div class="table">
<div class="tr table-titles">
<div class="th">ECIO3G/RSRQ4G/SS_RSRQ5G :</div>
<div class="th">RSCP3G/RSRP4G/SS_RSRP5G :</div>
<div class="tr table-titles" id="ServingCell">
<div class="th">servingcell :<span>读取中..</span></div>
</div>
</div>
</div>
</div>
<div class="cbi-section">
<legend>其他信息</legend>
<div class="cbi-section-node">
<div class="table">
<div class="tr table-titles">
<div class="th"><%:MCC MNC :%></div>
<div class="th"><%:RNC%><g><%:3G%></g><%:/eNB ID%><g><%:4G/5G%></g> </div>
<div class="th"><%:LAC%><g><%:3G%></g><%:/TAC%><g><%:4G/5G%></g> :</div>
</div>
</div>
<div class="table">
<div class="tr table-titles">
<div class="th"><%:Cell ID : %></div>
<div class="th"><%:Band : %></div>
<div class="th"><%:Channel : %></div>
<div class="th"><%:PCI : %></div>
<div class="th"><%:Maximum Qos : %></div>
</div>
</div>
</div>
</div>
</div>
<script>
(new XHR()).get('<%=luci.dispatcher.build_url("admin", "network", "usbmodem", "modem_status")%>', null, function (x) {
var text = x.responseText;
console.log(text)
let regx = [/AT\+CGMI\|([^|]+)/g, /AT\+GMM\|([^|]+)/g, /AT\+GMR\|([^|]+)/g, /\+QTEMP:"qfe_wtr_pa0","([^\|]+)"/g, /\+CBC: ([^\|]+)/g];
$A(document.querySelectorAll("#baseInfo span")).eachMatch(text, regx);
regx = [/AT\+GSN\|([^\|]+)/g, /AT\+CIMI\|([^\|]+)/g, /\+QCCID: ([^\|]+)/g];
$A(document.querySelectorAll("#SimInfo span")).eachMatch(text, regx);
regx = [/\+QSPN: ([^\|]+)/g, /\+CSQ: ([^\|]+)/g, /\+QCCID: ([^\|]+)/g];
$A(document.querySelectorAll("#CSQInfo span")).eachMatch(text, regx);
regx = [/\+QENG: "servingcell",([^\|]+)/g];
$A(document.querySelectorAll("#ServingCell span")).eachMatch(text, regx);
}
);
</script>
<%+footer%>

View File

@ -2,5 +2,5 @@ config service
option tool 'quectel-CM'
option device '/dev/cdc-wdm0'
option enabled '0'
option readport ''
option readport '/dev/ttyUSB2'
option storage 'SM'

View File

@ -1,4 +1,4 @@
leovs @2023.6.2
#leovs @2023.6.2
opengt
set com 115200n81
@ -46,7 +46,7 @@ let t=time()+f
gosub getresult
if $s="^mTIMEOUT ERROR" print $s
#获取ICCID
#获取QCCID
send "AT+QCCID^m"
let t=time()+f
gosub getresult
@ -71,10 +71,10 @@ gosub getresult
if $s="^mTIMEOUT ERROR" print $s
#获取本地IP地址
send "AT+CGPADDR^m"
let t=time()+f
gosub getresult
if $s="^mTIMEOUT ERROR" print $s
#send "AT+CGPADDR^m"
#let t=time()+f
#gosub getresult
#if $s="^mTIMEOUT ERROR" print $s
#获取SIM卡状态
send "AT+CPIN?^m"
@ -125,12 +125,11 @@ gosub getresult
if $s="^mTIMEOUT ERROR" print $s
#获取电话号码
send "AT+QCCID^m"
send "AT+QENG=\"servingcell\"^m"
let t=time()+f
gosub getresult
if $s="^mTIMEOUT ERROR" print $s
exit 0
:getresult

View File

@ -1,207 +1,16 @@
#!/bin/sh
# leovs @2023.6.2
device=/dev/ttyUSB2
device=$(uci get usbmodem.@service[0].readport)
pidfile=/var/run/usbmodem.pid
status() {
OX=$(gcom -d "$device" -s "/lib/usbmodem/usbmodem_status.gcom")
OX=$(echo $OX | tr 'a-z' 'A-Z')
CSQ=$(echo $OX | grep -o "+CSQ: [0-9]\{1,2\}" | grep -o "[0-9]\{1,2\}")
if [ -z "$CSQ" ] || [ "$CSQ" = "99" ]; then
CSQ="-"
CSQ_PER="-"
CSQ_RSSI="-"
else
CSQ_PER=$(($CSQ * 100 / 31))"%"
CSQ_RSSI=$((2 * CSQ - 113))" dBm"
if ! test -e $pidfile; then
touch $pidfile
echo '' > /tmp/usbmodem_status.log
gcom -d "$device" -s "/lib/usbmodem/usbmodem_status.gcom" >> /tmp/usbmodem_status.log
rm -f $pidfile
fi
echo $OX
MODTYPE="-"
NETMODE="-"
LBAND="-"
PCI="-"
LTEINFO=$(echo $OX | grep -o "!LTEINFO: .\+ INTRAFREQ:" | tr " " ",")
LTEINFO=$(echo "$LTEINFO" | grep -o "[0-9]\{1,6\}\,[0-9]\{3\}\,.\+")
if [ -n "$LTEINFO" ]; then
PCI=$(echo $LTEINFO | cut -d, -f10 | grep -o "[0-9]\{1,3\}")
if [ -z "$PCI" ]; then
PCI="-"
fi
fi
LTEINFO=$(echo $OX | grep -o "!LTEINFO: .\+ INTRAFREQ:" | tr " " ",")
LTEINFO=$(echo "$LTEINFO" | grep -o "[0-9]\{1,6\}\,[0-9]\{3\}\,.\+")
if [ -n "$LTEINFO" ]; then
PCI=$(echo $LTEINFO | cut -d, -f10 | grep -o "[0-9]\{1,3\}")
if [ -z "$PCI" ]; then
PCI="-"
fi
fi
SINR=$(echo $OX | grep -o "SINR (.B): [-.0-9]\{1,5\}" | tr '\n' ' ' | cut -d' ' -f3)
if [ -n "$SINR" ]; then
SINR5=$(echo $OX | grep -o "NR5G SINR (.B): [-]*[.0-9]\{1,5\}" | cut -d' ' -f4)
if [ -n "$SINR5" ]; then
SINR=$SINR" dB, "$SINR5
fi
SINR=$SINR" dB"
else
SINR="-"
fi
TEMP=$(echo $OX | grep -o "TEMPERATURE: [-.0-9]\+ " | grep -o "[-.0-9]\+" | tr '\n' ' ')
if [ -n "$TEMP" ]; then
TEMP=$(printf "$(echo $TEMP | cut -d' ' -f2)\xc2\xb0C")
else
TEMP="unknown"
fi
RAT=$(echo $OX | grep -o "SYSTEM MODE: [^ ]\{3,10\}" | cut -d' ' -f3)
MODE=$RAT
case $RAT in
"WCDMA")
MODE=$(echo $OX | grep -o " \*CNTI: 0,[^ ]\+" | cut -d, -f2)
if [ -z "$MODE" ] || [ "$MODE" = "NONE" ]; then
MODE=$RAT
fi
CHANNEL=$(echo $OX | grep -o "WCDMA CHANNEL: [0-9]\{3,5\}" | cut -d' ' -f3)
if [ -n "$CHANNEL" ]; then
LOCKCHAN=$(echo $OX | grep -o "!UMTSCHAN? ENABLE: 01 CHANNEL: [0-9]\{3,5\}")
if [ -n "$LOCKCHAN" ]; then
LOCKCHAN=$(echo $LOCKCHAN | grep -o "CHANNEL: [0-9]\+" | grep -o "[0-9]\+")
CHANNEL=$CHANNEL" (Soft locked to $LOCKCHAN)"
fi
else
CHANNEL="-"
fi
ECIO=$(echo $OX | grep -o "EC/IO: [+-]\?[.0-9]\+")
ECIO=$(echo "$ECIO")
ECIO1=$(echo "$ECIO" | cut -d' ' -f4)
ECIO=$(echo "$ECIO" | cut -d' ' -f2)
RSCP=$(echo $OX | grep -o "RSCP: -[.0-9]\+")
RSCP=$(echo "$RSCP")
RSCP1=$(echo "$RSCP" | cut -d' ' -f4)
RSCP=$(echo "$RSCP" | cut -d' ' -f2)
;;
"LTE")
LBAND=$(echo $OX | grep -o "LTE BAND: B[0-9]\+ LTE BW: [.012345]\+ MHZ" | grep -o "[.0-9]\+")
LBAND=$(printf "B%d (Bandwidth %s MHz)" $LBAND)
CHANNEL=$(echo $OX | grep -o "LTE RX CHAN: [0-9]\{1,6\}" | grep -o "[0-9]\+")
SLBAND=$(echo $OX | grep -o " ACTIVE LTE SCELL BAND:[ ]*B[0-9]\+ LTE SCELL BW:[ ]*[.012345]\+ MHZ")
if [ -n "$SLBAND" ]; then
SLBAND=$(echo $SLBAND | grep -o "[.0-9]\+")
SLBAND=$(printf "<br />B%d (CA, Bandwidth %s MHz)" $SLBAND)
LBAND=$LBAND$SLBAND
XTRACHAN=$(echo $OX | grep -o " LTE SCELL CHAN:[0-9]\+" | grep -o "[0-9]\{2,6\}")
CHANNEL=$CHANNEL", "$XTRACHAN
fi
SSCLIST=$(echo $OX | grep -o "LTE S[CS]C[0-9] STATE:[ ]\?ACTIVE" | grep -o "[0-9]")
for SSCVAL in $(echo "$SSCLIST"); do
SSCx="S[CS]C"$SSCVAL
read_ssc
done
if [ -n "$LTEINFO" ]; then
RSCP=$(echo $LTEINFO | cut -d, -f12 | grep -o "[-][.0-9]\{2,5\}")
ECIO=$(echo $LTEINFO | cut -d, -f11 | grep -o "[-.0-9]\{1,5\}")
fi
if [ -z "$RSCP" ]; then
RSCP=$(echo $OX | grep -o "PCC RXM RSRP: -[0-9]\{2,3\} " | cut -d' ' -f4)
fi
if [ -n "$RSCP" ]; then
RSCP1=$(echo $OX | grep -o "PCC RXD RSRP: -[0-9]\{2,3\} " | cut -d' ' -f4)
if [ -z "$RSCP1" ]; then
RSCP1=$(echo $OX | grep -o "PCC RXD RSSI: -[0-9]\+ RSRP (DBM): -[0-9]\{2,3\} " | cut -d' ' -f7)
fi
else
RSCP=$(echo $OX | grep -o "RSRP (DBM): -[0-9]\{2,3\} " | tr '\n' ' ' | cut -d' ' -f3)
fi
if [ -z "$ECIO" ]; then
ECIO=$(echo $OX | grep -o "RSRQ (DB): [-.0-9]\{1,5\} " | cut -d' ' -f3)
fi
;;
"ENDC")
MODE="LTE/NR EN-DC"
LBAND=$(echo $OX | grep -o "LTE BAND: B[0-9]\+ LTE BW: [.012345]\+ MHZ" | grep -o "[.0-9]\+")
LBAND=$(printf "B%d (Bandwidth %s MHz)" $LBAND)
CHANNEL=$(echo $OX | grep -o "LTE RX CHAN: [0-9]\{1,6\}" | grep -o "[0-9]\+")
NBAND=$(echo $OX | grep -o "NR5G BAND: N[0-9]\+ NR5G BW: [0-9]\+ MHZ")
NBAND=$(echo "$NBAND" | cut -d' ' -f3)" "$(echo "$NBAND" | cut -d' ' -f6)
if [ "$NBAND" != " " ]; then
NBAND=$(echo $NBAND | grep -o "[.0-9]\+")
NBAND=$(printf "<br />n%d (Bandwidth %s MHz)" $NBAND)
LBAND=$LBAND$NBAND
NCHAN=$(echo $OX | grep -o "NR5G RX CHAN: [0-9]\{6\}" | cut -d' ' -f4)
CHANNEL=$CHANNEL", "$NCHAN
fi
SSCLIST=$(echo $OX | grep -o "LTE S[CS]C[0-9] STATE:[ ]\?ACTIVE" | grep -o "[0-9]")
for SSCVAL in $(echo "$SSCLIST"); do
SSCx="S[CS]C"$SSCVAL
read_ssc
done
RSCP=$(echo $OX | grep -o "PCC RXM RSRP: -[0-9]\{2,3\} " | cut -d' ' -f4)
RSCP1=$(echo $OX | grep -o "NR5G RSRP (DBM): -[0-9]\{2,3\} " | cut -d' ' -f4)
ECIO=$(echo $OX | grep -o "RSRQ (DB): [-.0-9]\{1,5\} " | tr '\n' ' ' | cut -d' ' -f3)
ECIO1=$(echo $OX | grep -o "NR5G RSRQ (DB): [-.0-9]\{1,5\} " | cut -d' ' -f4)
;;
"NR5G")
MODE="NR5G-SA"
NBAND=$(echo $OX | grep -o "NR5G BAND: N[0-9]\+ NR5G BW: [0-9]\+ MHZ")
NBAND=$(echo "$NBAND" | cut -d' ' -f3)" "$(echo "$NBAND" | cut -d' ' -f6)
CHANNEL=$(echo $OX | grep -o "NR5G RX CHAN: [0-9]\{1,6\}" | grep -o "[0-9]\+")
RSCP=$(echo $OX | grep -o "PCC RXM RSRP: -[0-9]\{2,3\} " | cut -d' ' -f4)
ECIO=$(echo $OX | grep -o "RSRQ (DB): [-.0-9]\{1,5\} " | cut -d' ' -f3)
;;
esac
SELRAT=$(echo $OX | grep -o "!SELRAT:[^0-9]\+[0-9]\{2\}" | grep -o "[0-9]\{2\}")
if [ -n "$SELRAT" ]; then
MODTYPE="2"
case $SELRAT in
"01")
NETMODE="5"
;;
"02")
NETMODE="3"
;;
"06")
NETMODE="7"
;;
*)
NETMODE="1"
;;
esac
fi
CMODE=$(uci -q get modem.modem$CURRMODEM.cmode)
if [ "$CMODE" = 0 ]; then
NETMODE="10"
fi
if [ -z "$RSCP1" ]; then
RSCP1=" "
fi
if [ -z "$ECIO1" ]; then
ECIO1=" "
fi
echo 'CSQ="'"$CSQ"'"'
echo 'CSQ_PER="'"$CSQ_PER"'"'
echo 'CSQ_RSSI="'"$CSQ_RSSI"'"'
echo 'ECIO="'"$ECIO"'"'
echo 'RSCP="'"$RSCP"'"'
echo 'ECIO1="'"$ECIO1"'"'
echo 'RSCP1="'"$RSCP1"'"'
echo 'MODE="'"$MODE"'"'
echo 'MODTYPE="'"$MODTYPE"'"'
echo 'NETMODE="'"$NETMODE"'"'
echo 'CHANNEL="'"$CHANNEL"'"'
echo 'LBAND="'"$LBAND"'"'
echo 'PCI="'"$PCI"'"'
echo 'TEMP="'"$TEMP"'"'
echo 'SINR="'"$SINR"'"'
}
case "$1" in