Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SORACOM Air + FS01BU or AK-020 を、Raspberry Pi や Intel Edison (debianインストール&USB-OTGケーブルで接続) で使用するための接続スクリプト(要: wvdial / usb-modeswitch)と、init用スクリプト by dietposter
#!/bin/bash
init_fs01bu()
{
usb_modeswitch -t <<EOF
DefaultVendor= 0x$1
DefaultProduct= 0x$2
TargetVendor= 0x$3
TargetProduct= 0x$4
MessageEndpoint= not set
MessageContent="55534243123456780000000080000606f50402527000000000000000000000"
NeedResponse=0
ResponseEndpoint= not set
Interface=0x00
EOF
modprobe usbserial vendor=0x$3 product=0x$4
modprobe -v option
echo "$3 $4" > /sys/bus/usb-serial/drivers/option1/new_id
}
init_ak020()
{
if (lsusb | grep 15eb:7d0e > /dev/null && [ -e /dev/ttyUSB0 ])
then
echo AT+CFUN=1 > /dev/ttyUSB0
sleep 1
return 0
elif (lsusb | grep 15eb:a403> /dev/null)
then
echo -n "Configuring modem ... "
cat << EOF > /etc/udev/rules.d/40-ak-020.rules
ACTION=="add", ATTRS{idVendor}=="15eb", ATTRS{idProduct}=="a403", RUN+="/usr/sbin/usb_modeswitch --std-eject --default-vendor 0x15eb --default-product 0xa403 --target-product 0x15eb --target-product 0x7d0e"
ACTION=="add", ATTRS{idVendor}=="15eb", ATTRS{idProduct}=="7d0e", RUN+="/sbin/modprobe usbserial vendor=0x15eb product=0x7d0e"
EOF
udevadm control --reload-rules
udevadm trigger -c add --attr-match=idVendor=15eb --attr-match=idProduct=a403
echo done.
echo waiting for modem device
for i in {1..30}
do
[ -e /dev/ttyUSB0 ] && break
echo -n .
sleep 1
done
echo done.
echo -n Resetting modem ...
init_ak020
sleep 5
echo done
fi
return 1
}
dialup()
{
cat > /etc/wvdial.conf << EOF
[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Init3 = AT+CGDCONT=1,"IP","$2"
Dial Attempts = 3
Stupid Mode = 1
Modem Type = Analog Modem
Dial Command = ATD
Stupid Mode = yes
Baud = 460800
New PPPD = yes
Modem = $1
ISDN = 0
APN = $2
Phone = *99***1#
Username = $3
Password = $4
Carrier Check = no
Auto DNS = 1
Check Def Route = 1
EOF
grep replacedefaultroute /etc/ppp/peers/wvdial &> /dev/null || echo replacedefaultroute >> /etc/ppp/peers/wvdial
echo waiting for modem device
for i in {1..30}
do
[ -e $1 ] && break
echo -n .
sleep 1
done
[ $i = 30 ] && ( echo modem not found ; exit 1 )
while [ 1 ] ; do wvdial ; sleep 60 ; done
}
if [ $UID != 0 ]
then
echo please execute as root or use sudo command.
exit 1
elif [ ! -x /usr/bin/wvdial ]
then
echo 'wvdial is not installed! please answer "y" when asked to continue.'
echo
apt-get update && apt-get install wvdial || exit 1
fi
if (lsusb | grep 1c9e: > /dev/null)
then
echo Found FS01BU
init_fs01bu 1c9e 98ff 1c9e 6801 && \
dialup /dev/ttyUSB2 soracom.io sora sora
elif (lsusb | grep 15eb: > /dev/null)
then
echo Found AK-020
init_ak020 || echo could not initialize AK-020 && \
dialup /dev/ttyUSB0 soracom.io sora sora
else
echo No supported modem found. Please wait for a while and re-execute script.
exit 1
fi
#!/bin/sh
### BEGIN INIT INFO
# Provides: soracomair
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d. This example start a
# single forking daemon capable of writing a pid
# file. To get other behavoirs, implemend
# do_start(), do_stop() or other functions to
# override the defaults in /lib/init/init-d-script.
### END INIT INFO
#SORACOM Air接続スクリプトのフルパスを設定
cmd="/opt/sora/connect_air.sh"
start(){
#working /opt/sora/connect_air.sh
echo -n "connect air...\n"
#スクリプトの実行
bash $cmd &
return 0
}
stop(){
echo -n "stopping connect air...\n"
#スクリプトが実行されているプロセスのPIDを設定
pid=`ps ax | grep -v grep | grep "$cmd" | awk '{ print $1 }'`
#スクリプトの停止
kill $pid
#ダイヤラーwvdialの停止 pppdも停止する
killall wvdial
return 0
}
case $1 in
start)
start
;;
stop)
stop
;;
*)
echo "Usage: $0 {start|stop}"
exit 2
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.