#!/bin/sh
PRJ_NAME=`cat /uinit/product/name`
NET_LIST=/tmp/WiFi.RSSI.Reading.Result
CLI_PROC=/usr/bin/wpa_cli
#兼容不同平台的wpa_cil
if [ ! -e ${CLI_PROC} ]; then
CLI_PROC=/usr/bin/wpa_cli_rtl
fi
killall wpa_cli
sleep 0.5
fBuffer=`ps | grep -r "/uinit/bin/wpa_supplicant" | grep -v "grep"`
if [ "${fBuffer}" == "" ]; then
/uinit/bin/wpa_supplicant -Dnl80211 -iwlan0 -c /uinit/script/wifi.scan.conf /var/run/wpa_supplicant -B &
sleep 1
fi
while true;
do
${CLI_PROC} -iwlan0 scan
sleep 3
#获取扫描结果,剔除第一行标题,然后将RSSI和SSID以|拼接到一起
${CLI_PROC} -iwlan0 scan_result |awk "NR>1"|awk '{
#最后一个]的位置的所有
last_bracket_index = 0;
for (i = length($0); i >= 1; i--) {
if (substr($0, i, 1) == "]") {
last_bracket_index = i;
break;
}
}
#SSID
SSID= substr($0, last_bracket_index + 1);
gsub(/^\s+|\s+$/, "",SSID);
#信号强度
RSSI = $3;
#将信号强度和SSID以|拼接到一起
print RSSI "|" SSID;
}'> ${NET_LIST}
echo "[wifi::rssi:reading] finished ..."
ssidNum=$(wc -l < "$NET_LIST" | awk '{print $1}')
echo "file line:${ssidNum}"
#扫描长度大于0表示扫描到WIFI,反之未扫到重新进入扫描
if [ $ssidNum -gt 0 ]; then
echo "ssidNum:$ssidNum"
break
else
echo "ssidNum <= 0"
continue
fi
done
killall wpa_cli
killall wpa_cli_rtl
rm -rf ${NET_BUSY}
echo "[wifi::rssi:reading] exit ..."
exit 0
Linex嵌入式扫描WIFI
最新推荐文章于 2024-08-15 10:49:31 发布