我有一个不支持alwasys工作属性的USB GSM调制解调器(Huawei E367u-2)有时会重置(USB设备在日志中断开连接/重新连接),当它恢复时,它具有不同的ttyUSB编号。有时在启动时,usb_modswitch似乎没有被解雇。该计算机是运行Raspbian的Raspberry Pi。
我对此有一个简单的解决方案,CRON每分钟都会运行以下脚本:
If WVDIAL is not running:
Run WVDIAL
我想将脚本更改为:
If /dev/ttyUSB0 is not present:
If DevicePresent(12d1:1446):
ResetDevice(12d1:1446)
ElseIs DevicePresemt(12d1:1506)
ResetUSB(12d1:1506)
If WVDIAL is not running:
Run WVDIAL
显然,这是伪代码,但是我需要将以下几行内容串在一起,但我不知道如何做:
如果未运行,则会加载wvdial:
#! /bin/sh
# /etc/init.d/wvdial
### BEGIN INIT INFO
# Provides: TheInternet
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Simple script to start a program at boot
# Description: A simple script from www.stuffaboutcode.com which will start / stop a program a boot / shutdown.
### END INIT INFO
# If you want a command to always run, put it here
# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting GPRS Internet"
# run application you want to start
/sbin/start-stop-daemon --start --background --quiet --exec /usr/bin/wvdial internet
;;
stop)
echo "Stopping GPRS Internet"
# kill application you want to stop
/sbin/start-stop-daemon --stop --exec /usr/bin/wvdial
;;
*)
echo "Usage: /etc/init.d/noip {start|stop}"
exit 1
;;
esac
exit 0
这使我可以找到/sys
特定设备的路径:
for X in /sys/bus/usb/devices/*; do
echo "$X"
cat "$X/idVendor" 2>/dev/null
cat "$X/idProduct" 2>/dev/null
echo
done
如果您知道正确的/ sys路径,这将重置USB设备:
echo 0 > /sys/bus/usb/devices/1-1.2.1.1/authorized
echo 1 > /sys/bus/usb/devices/1-1.2.1.1/authorized
因此,我需要将最后两节和一个测试字符串/dev/ttyUSB0
放入“如果您希望命令始终运行。请放在此处”部分下的部分中。
更新1
usbreset尽管可以正常工作,但却无法完成任务。只有回显0到1才能authroized
正确模拟设备断开/重新连接。
这就是将设备或usb_modeswitch引导回生活的诀窍。因此,我设法将以下内容凑在一起:
echo "Searching for $1"
devPath=`lsusb | grep $1 | sed -r 's/Bus ([0-9]{3}) Device ([0-9]{3}).*/bus\/usb\/\1\/\2/g;'`
echo "Found $1 @ $devPath"
echo "Searching for sysPath"
for sysPath in /sys/bus/usb/devices/*; do
echo "$sysPath/uevent"
devName=`cat "$sysPath/uevent" | grep $devPath`
#echo devName=$devName
if [ ! -z $devName ]
then
break
fi
done
if [ ! -z $devName ]
then
echo "Found $1 @ $sysPath, Resetting"
echo "echo 0 > $sysPath/authorized"
echo 0 > $sysPath/authorized
echo "echo 1 > $sysPath/authorized"
echo 1 > $sysPath/authorized
else
echo "Could not find $1"
fi
我认为因此现在要做的就是将其放入init.d脚本中:
if ttyUSB0 not present
if 12d1:1446 present
/usr/sbin/resetdevicebyauthorized 12d1:1446
else if 12d1:1506 present
/usr/sbin/resetdevicebyauthorized 12d1:1506
fi
fi
usbreset
失败与华为调制解调器,调制解调器无法恢复并且在重新启动时冻结。我目前正在解决相同的问题,并且可能很快就会有一个可以正常工作的解决方案。