Temat: Modemy 3G w trybie NDIS/CDC i multiwan inaczej
Witam,
z chęcią podzielę się moimi doświadczeniami i skryptami związanymi z połączeniami przez modemy 3G w trybie NDIS/CDC, kilku modemów z multiwanem.
Przykładowa konfiguracja to:
Router Linksys WRT160NL
2 modemy HUAWEI E173
hub USB
OpenWrt Backfire 10.03.1
2 karty SIM Aero2
port WAN podłączny do modemu kablowego (to konfiguracja testowa)
Założenia:
Szybsze nawiązywanie połączania i większy transfer dzięki NDIS
Niezawodne wznawianie połączenia
Prawie wszystko konfigurowalne z /etc/config/network
Na początek instalacja CDC tak aby modemy mogły pracować w trybie NDIS:
(Jest to wszystko świetnie opisane u Cezarego http://eko.one.pl/?p=openwrt-ndis więc nie będzie tu szczegułów)
opkg update
opkg install kmod-usb-net-cdc-etherTeraz ustawienia dla network:
uci set network.wan2=interface
uci set network.wan2.ifname=usb0
uci set network.wan2.proto=dhcp
uci set network.wan2.comm=/dev/ttyUSB2
uci set network.wan2.mode="AT^SYSCFG=2,2,3FFFFFFF,2,4"
uci set network.wan2.pincode=
uci set network.wan2.apn=darmowy
uci set network.wan2.username=
uci set network.wan2.password=
uci set network.wan2.macaddr=00:01:02:03:04:05
uci set network.wan2.auto=0
uci set network.wan2.defaultroute=0
uci set network.wan2.peerdns=0
uci set network.wan2.dns='8.8.8.8 8.8.4.4'
uci set network.wan3=interface
uci set network.wan3.ifname=usb1
uci set network.wan3.proto=dhcp
uci set network.wan3.comm=/dev/ttyUSB5
uci set network.wan3.mode="AT^SYSCFG=2,2,3FFFFFFF,2,4"
uci set network.wan3.pincode=
uci set network.wan3.apn=darmowy
uci set network.wan3.username=
uci set network.wan3.password=
uci set network.wan3.macaddr=00:01:02:03:04:05
uci set network.wan3.auto=0
uci set network.wan3.defaultroute=0
uci set network.wan3.peerdns=0
uci set network.wan3.dns='8.8.8.8 8.8.4.4'
uci commit networkDodatkiem są dwa parametry:
- “comm” to port komunikacyjny (najczęściej ostatni dla danego modemu)
- “mode” identycznie jak w rozwiązaniach Cezarego, dodatkowe ustawianie trybu pracy modemu.
Poniżej podpowiedź ja skonstruować komendę według własnych potrzeb:
AT^SYSCFG=$mode, $acqOrder, $band, $roam, $srvDomain
$mode
2=Auto-Select
13=GSM only
14=WCDMA only
16=no Change
$acqOrder
0=Automatic
1=GSM prefered
2=WCDMA prefered
3=no Change
$band
EGSM(900): 00000100
DCS(1800): 00000080
PCS(1900): 00200000
GSM850: 00080000
WCDMA2100: 00400000
3fffffff = All
$roam
0=Not Supported
1=Supported
2=no Change
$srvDomain
0=Circuit-Switched only
1=Packet-Switched only
2=Circuit- & Packet-Switched
3=Any
4=no Change
I przykłady:
Any : AT^SYSCFG=2,0,3FFFFFFF,2,4
2G only : AT^SYSCFG=13,1,3FFFFFFF,2,4
3G only : AT^SYSCFG=14,2,3FFFFFFF,2,4
2G preferred : AT^SYSCFG=2,1,3FFFFFFF,2,4
3G preferred : AT^SYSCFG=2,2,3FFFFFFF,2,4
Teraz fire wall:
uci add firewall zone
uci set firewall.@zone[-1]=zone
uci set firewall.@zone[-1].name=wan2
uci set firewall.@zone[-1].network=wan2
uci set firewall.@zone[-1].input=REJECT
uci set firewall.@zone[-1].output=ACCEPT
uci set firewall.@zone[-1].forward=REJECT
uci set firewall.@zone[-1].masq=1
uci set firewall.@zone[-1].mtu_fix=1
uci add firewall forwarding
uci set firewall.@forwarding[-1]=forwarding
uci set firewall.@forwarding[-1].src=lan
uci set firewall.@forwarding[-1].dest=wan2
uci add firewall zone
uci set firewall.@zone[-1]=zone
uci set firewall.@zone[-1].name=wan3
uci set firewall.@zone[-1].network=wan3
uci set firewall.@zone[-1].input=REJECT
uci set firewall.@zone[-1].output=ACCEPT
uci set firewall.@zone[-1].forward=REJECT
uci set firewall.@zone[-1].masq=1
uci set firewall.@zone[-1].mtu_fix=1
uci add firewall forwarding
uci set firewall.@forwarding[-1]=forwarding
uci set firewall.@forwarding[-1].src=lan
uci set firewall.@forwarding[-1].dest=wan3
uci commit firewallNastępnie edytujemy plik /etc/rc.local dodając na końcu dwie linie:
sleep 5
/bin/3gtester.shJeszcze pozostaje dodanie do crontab wywołanie 3gtestera, linijka może wyglądać tak:
*/2 * * * * /bin/3gtester.shI jeszcze instalacja i konfiguracja multiwan-u:
opkg update
opkg install multiwan
uci set multiwan.config=multiwan
uci set multiwan.config.health_monitor=serial
uci set multiwan.config.default_route=balancer
uci set multiwan.config.debug=0
uci set multiwan.wan=interface
uci set multiwan.wan.health_fail_retries=3
uci set multiwan.wan.health_interval=10
uci set multiwan.wan.health_recovery_retries=5
uci set multiwan.wan.weight=10
uci set multiwan.wan.icmp_hosts=dns
uci set multiwan.wan.timeout=3
uci set multiwan.wan.failover_to=balancer
uci set multiwan.wan.dns=auto
uci set multiwan.wan2=interface
uci set multiwan.wan2.health_fail_retries=3
uci set multiwan.wan2.health_interval=10
uci set multiwan.wan2.health_recovery_retries=5
uci set multiwan.wan2.weight=10
uci set multiwan.wan2.icmp_hosts=dns
uci set multiwan.wan2.timeout=3
uci set multiwan.wan2.failover_to=balancer
uci set multiwan.wan2.dns='8.8.8.8 8.8.4.4'
uci set multiwan.wan3=interface
uci set multiwan.wan3.health_fail_retries=3
uci set multiwan.wan3.health_interval=10
uci set multiwan.wan3.health_recovery_retries=5
uci set multiwan.wan3.weight=10
uci set multiwan.wan3.icmp_hosts=dns
uci set multiwan.wan3.timeout=3
uci set multiwan.wan3.failover_to=balancer
uci set multiwan.wan3.dns='8.8.8.8 8.8.4.4'
uci delete multiwan.@mwanfw[-1]
uci delete multiwan.@mwanfw[-1]
uci delete multiwan.@mwanfw[-1]
uci add multiwan mwanfw
uci set multiwan.@mwanfw[-1]=mwanfw
uci set multiwan.@mwanfw[-1].wanrule=fastbalancer
uci add multiwan mwanfw
uci set multiwan.@mwanfw[-1]=mwanfw
uci set multiwan.@mwanfw[-1].wanrule=wan
uci add multiwan mwanfw
uci set multiwan.@mwanfw[-1]=mwanfw
uci set multiwan.@mwanfw[-1].wanrule=wan2
uci add multiwan mwanfw
uci set multiwan.@mwanfw[-1]=mwanfw
uci set multiwan.@mwanfw[-1].wanrule=wan3
uci commit multiwan
/etc/init.d/multiwan start
/etc/init.d/multiwan enableA tu zaczyna się coś najważniejszego w tej koncepcji![]()
Tak wygląda skrypt do podnoszenia połączenia 3G, należy wkleić go do pliku /bin/3gtester.sh
#!/bin/sh
# Establishing 3G modem connection in dialup or NDIS mode
# Script version 1.00 Rafal Drzymala 2012
#
# Changelog
# 1.00 RD First stable code
#
SCR=$(basename $0)
ICMP="8.8.8.8"
WANS=$(uci show network | awk -F[.=] '{if (($3=="proto" && $4=="3g") || ($3=="ifname" && match($4,"usb[0-9]"))) print $2}')
for WAN in $WANS; do
NDIS="N"
[ $(uci -q get network.$WAN.proto) != "3g" ] && NDIS="Y"
DEV_IFNAME=$(uci -q get network.$WAN.ifname)
DEV_APN=$(uci -q get network.$WAN.apn)
DEV_PINCODE=$(uci -q get network.$WAN.pincode)
DEV_MODE=$(uci -q get network.$WAN.mode)
[ "$NDIS" == "Y" ] && DEV_COMM=$(uci -q get network.$WAN.comm)
[ "$NDIS" == "N" ] && DEV_COMM=$(uci -q get network.$WAN.device)
DEV_AUTO="1"
[ "$NDIS" == "N" ] && DEV_AUTO=$(uci -q get network.$WAN.auto)
logger -t $SCR "Checking $WAN for active connection"
logger -t $SCR " interface=$DEV_IFNAME"
logger -t $SCR " apn=$DEV_APN"
logger -t $SCR " comm=$DEV_COMM"
[ "$DEV_MODE" != "" ] && logger -t $SCR " mode=$DEV_MODE"
if [ "$DEV_AUTO" == "1" ]; then
if [ -e $DEV_COMM ]; then
if ping -q -c 1 -W 5 -I $DEV_IFNAME $ICMP > /dev/null; then
logger -t $SCR "ICMP successfully sent via $WAN"
else
logger -t $SCR "Restarting $WAN connection"
if [ "$NDIS" == "N" ]; then
(ifdown $WAN; sleep 2; ifup $WAN) &
else
(ifdown $WAN; PINCODE=$DEV_PINCODE APN=$DEV_APN MODE=$DEV_MODE gcom -d $DEV_COMM -s /etc/gcom/ndisup.gcom; sleep 5; ifup $WAN) &
fi
fi
else
logger -t $SCR "Device $DEV_COMM for $WAN not exist"
fi
fi
done
# DoneA oto skrypt dla gcom, należy go wkleić do pliku /etc/gcom/ndisup.gcom
opengt
let $x="ndisup:"+$basename($dev())+" "
print $x+"Establishing 3G modem connection in NDIS mode\n"
print $x+"Script for comgt version 1.00 Rafal Drzymala 2012\n"
#
# Changelog
# 1.00 RD First stable code
#
# Modem succesfuly tested
# - HUAWEI E173 11.126.85.00.209
# Modem tested, not supported
# - HUAWEI E160G 11.608.02.02.55
# - HUAWEI E160 11.604.09.00.00
# - HUAWEI E220
#
set com 115200n81
set ignorecase on
set comecho off
set senddelay 0.02
let $a=$env("APN")
let $m=$env("MODE")
let $p=$env("PINCODE")
if $a = "" print $x+"APN environment var not specified\n" goto finish
let r1=0
:start
# Initializing communication with modem
if r1=1 print $x+"Try to communicate with modem\n"
if r1>1 print $x+"Again try to communicate with modem (",r1,")\n"
waitquiet 2 0.5
send "ATQ0; E0^m"
waitfor 1 "OK"
if % = -1 goto comm_timeout
send "AT+CMEE=2^m"
waitfor 1 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
if % = -1 goto comm_timeout
if % = 2 waitquiet 1 0.5
send "AT\^CURC=0^m"
waitfor 1 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
if % = -1 goto comm_timeout
if % = 2 waitquiet 1 0.5
# Getting device information
print $x+"Getting device information\n"
waitquiet 1 0.2
send "AT+CGMI^m"
get 1 "^mOK^m" $i1
if % != 0 goto comm_timeout
waitquiet 1 0.1
send "AT+CGMM^m"
get 1 "^mOK^m" $i2
if % != 0 goto comm_timeout
waitquiet 1 0.1
send "AT+CGMR^m"
get 1 "^mOK^m" $i3
if % != 0 goto comm_timeout
waitquiet 1 0.1
send "AT+CGSN^m"
get 1 "^mOK^m" $i4
if % != 0 goto comm_timeout
if len($i1)>1 let $i1=$right($i1,len($i1)-1)
if len($i2)>1 let $i2=$right($i2,len($i2)-1)
if len($i3)>1 let $i3=$right($i3,len($i3)-1)
if len($i4)>1 let $i4=$right($i4,len($i4)-1)
print $x+"- modem: "+$toupper($i1)+" "+$toupper($i2)+"\n"
print $x+"- firmware: "+$i3+"\n"
print $x+"- IMEI: "+$i4+"\n"
:end_devinfo
# Checking modem for NDIS support
print $x+"Checking modem for NDIS support\n"
send "AT\^DIALMODE?^m"
waitfor 5 "\^DIALMODE:","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
if % = -1 goto comm_timeout
if % > 0 print $x+"- This modem doesn't support NDIS mode\n" goto abort
get 1 "^mOK^m" $i1
if % != 0 goto comm_timeout
let $i1=$left($i1,1)
if $i1 = "1" goto ok_ndis_check
if $i1 = "2" goto ok_ndis_check
print $x+"- This modem doesn't support NDIS mode\n"
goto abort
:ok_ndis_check
print $x+"- NDIS mode is supported by this modem\n"
waitquiet 1 1
# Checking for password input request
print $x+"Checking for password input request\n"
let u=0
send "AT+CPIN?^m"
waitfor 5 "+CPIN: ","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
if % = -1 goto comm_timeout
if % = 1 print $x+"Error while checking for password input request\n" goto end_chkpin
if % = 2 gosub cme_error print $x+"Error "+$e+" while checking for password input request\n" goto end_chkpin
if % = 3 print $x+"Command not supported\n" goto end_chkpin
get 1 "^mOK^m" $i1
if % != 0 goto comm_timeout
let $d="Unknown modem response ("+$i1+")"
if $i1 = "READY" let $d="MT without password input request"
if $i1 = "SIM PIN" let $d="UICC/SIM PIN password request"
if $i1 = "SIM PUK" let $d="UICC/SIM PUK password request, to unblock the SIM PIN which was blocked for 3 verification failure"
if $i1 = "SIM PIN2" let $d="PIN2 password request"
if $i1 = "SIM PUK2" let $d="PUK2 password request, to unblock the SIM PIN2 which was blocked for 3 verification failure"
if $i1 = "PH-SIM PIN" let $d="SIM lock (phone-to-SIM) is required"
if $i1 = "PH-NET PIN" let $d="Network personnalisation is required"
print $x+"- state: "+$d+"\n"
if $i1 = "SIM PIN" goto do_pin_unlock
if $i1 <> "READY" goto finish
:end_chkpin
# Unlock the PIN
goto end_pin_unlock
:do_pin_unlock
print $x+"UICC/SIM unlocking by PIN\n"
if $p = "" print $x+"PINCODE environment var not specified\n" goto abort
send "AT+CPIN="+$p"^m"
waitfor 5 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
if % = -1 goto comm_timeout
if % = 1 print $x+"Error while unlocking by PIN\n" goto abort
if % = 2 gosub cme_error print $x+"Error "+$e+" while unlocking by PIN\n" goto abort
if % = 3 print $x+"Command not supported\n" goto end_chkpin
print $x+"UICC/SIM unlocked successfully\n"
let r2=0
:wait_for_reg
let r2=r2+1
if r2>5 print $x+"Number of retries exhausted\n" goto abort
print $x+"Waiting for network registration (",r2,")\n"
send "AT+CGREG=0; +CGREG?^m"
waitfor 2 "+CGREG: ","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
if % = -1 goto comm_timeout
if % = 1 print $x+"Error while getting network registration status\n" goto end_pin_unlock
if % = 2 gosub cme_error print $x+"Error "+$e+" while getting network registration status\n" goto end_pin_unlock
if % = 3 print $x+"Command not supported\n" goto end_pin_unlock
get 1 "," $i1
if % != 0 goto comm_timeout
get 1 "^m^mOK^m" $i2
if % != 0 goto comm_timeout
let $d="Unknown modem response ("+$i2+")"
if $i2 = "0" waitquiet 1 5 goto wait_for_reg
if $i2 = "1" goto end_pin_unlock
if $i2 = "2" waitquiet 1 5 goto wait_for_reg
if $i2 = "3" let $d="Registration rejected"
if $i2 = "4" let $d="Unknown reasons"
if $i2 = "5" goto end_pin_unlock
print $x+"- error: "+$d+"\n"
goto abort
:end_pin_unlock
# Getting system information
:do_sysinfo
print $x+"Getting system information\n"
send "AT\^SYSINFO^m"
waitfor 5 "\^SYSINFO:","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
if % = -1 goto comm_timeout
if % = 1 print $x+"Error while getting system information\n" goto end_sysinfo
if % = 2 gosub cme_error print $x+"Error "+$e+" while getting system information\n" goto end_sysinfo
if % = 3 print $x+"Command not supported\n" goto end_sysinfo
get 1 "," $i1
if % != 0 goto comm_timeout
get 1 "," $i2
if % != 0 goto comm_timeout
get 1 "," $i3
if % != 0 goto comm_timeout
get 1 "," $i4
if % != 0 goto comm_timeout
get 1 "^mOK^m" $i5
if % != 0 goto comm_timeout
if len($i5)>3 let $i6=$right($i5,1)
let $i5=$left($i5,1)
let $d="Unknown modem response ("+$i1+")"
if $i1 = "0" let $d="No service"
if $i1 = "1" let $d="Restricted service"
if $i1 = "2" let $d="Valid service"
if $i1 = "3" let $d="Restricted regional service"
if $i1 = "4" let $d="Power-saving and deep sleep state"
print $x+"- service state: "+$d+"\n"
let $d="Unknown modem response ("+$i2+")"
if $i2 = "0" let $d="No service"
if $i2 = "1" let $d="Only CS service"
if $i2 = "2" let $d="Only PS service"
if $i2 = "3" let $d="PS+CS service"
if $i2 = "4" let $d="CS and PS not registered, searching"
print $x+"- domain: "+$d+"\n"
let $d="Unknown modem response ("+$i3+")"
if $i3 = "0" let $d="Non roaming state"
if $i3 = "1" let $d="Roaming state"
print $x+"- roaming: "+$d+"\n"
let $d="Unknown modem response ("+$i4+")"
if $i4 = "0" let $d="No service"
if $i4 = "1" let $d="AMPS mode"
if $i4 = "2" let $d="CDMA mode"
if $i4 = "3" let $d="GSM/GPRS mode"
if $i4 = "4" let $d="HDR mode"
if $i4 = "5" let $d="WCDMA mode"
if $i4 = "6" let $d="GPS mode"
if $i4 = "7" let $d="GSM/WCDMA"
if $i4 = "8" let $d="CDMA/HDR HYBRID"
if $i4 = "15" let $d="TD-SCDMA mode"
print $x+"- mode: "+$d+"\n"
let $d="Unknown modem response ("+$i5+")"
if $i5 = "0" let $d="Invalid USIM card state or pin code locked"
if $i5 = "1" let $d="Valid USIM card state"
if $i5 = "2" let $d="USIM is invalid in case of CS"
if $i5 = "3" let $d="USIM is invalid in case of PS"
if $i5 = "4" let $d="USIM is invalid in case of either CS or PS"
if $i5 = "255" let $d="USIM card is not existent"
print $x+"- SIM: "+$d+"\n"
let $d="Unknown modem response ("+$i6+")"
if $i6 = "0" let $d="No service"
if $i6 = "1" let $d="GSM mode"
if $i6 = "2" let $d="GPRS mode"
if $i6 = "3" let $d="EDGE mode"
if $i6 = "4" let $d="WCDMA mode"
if $i6 = "5" let $d="HSDPA mode"
if $i6 = "6" let $d="HSUPA mode"
if $i6 = "7" let $d="HSDPA mode and HSUPA mode"
if $i6 = "8" let $d="TD_SCDMA mode"
if $i6 = "9" let $d="HSPA+ mode"
if $i6 = "17" let $d="HSPA+(64QAM) mode"
if $i6 = "18" let $d="HSPA+(MIMO) mode"
print $x+"- sub mode: "+$d+"\n"
# Invalid state for finish
if $i2 = "1" goto abort
if $i5 = "0" goto abort
if $i5 = "3" goto finish
if $i5 = "4" goto finish
if $i5 = "255" goto finish
# Invalid state for restart_modem
if $i1 = "0" goto restart_modem
if $i1 = "4" goto restart_modem
if $i2 = "0" goto restart_modem
if $i2 = "4" goto restart_modem
if $i4 = "0" goto restart_modem
:end_sysinfo
# Getting received signal strength
print $x+"Getting received signal strength\n"
send "AT+CSQ^m"
waitfor 5 "+CSQ: ","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
if % = -1 goto comm_timeout
if % = 1 print $x+"Error while getting received signal strength\n" goto end_sigstr
if % = 2 gosub cme_error print $x+"Error "+$e+" while getting received signal strength\n" goto end_sigstr
get 1 "," $i1
if % != 0 goto comm_timeout
get 1 "^mOK^m" $i2
if % != 0 goto comm_timeout
if $i1 = "99" print $x+" signal strength: unknown\n" goto end_sigstr
let s1=val($i1)
let s2=(s1*2)-113
let s3=((s1*100000)/31000)
print $x+"- signal strength: (",s1,"), ",s2," dBm, ",s3,"%\n"
let s3=s3/5
let $s3=$left("####################",s3)+$left("--------------------",20-s3)
print $x+"- signal strength: ["+$s3+"]\n"
:end_sigstr
# Getting network registration status
print $x+"Getting network registration status\n"
let $i2=""
send "AT+CGREG=2; +CGREG?^m"
waitfor 2 "+CGREG: ","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
if % = -1 goto comm_timeout
if % = 1 print $x+"Error while getting network registration status\n" goto end_cgreg
if % = 2 gosub cme_error print $x+"Error "+$e+" while getting network registration status\n" goto end_cgreg
if % = 3 print $x+"Command not supported\n" goto end_cgreg
get 1 "," $i1
if % != 0 goto comm_timeout
get 1 "^m^mOK^m" $i4
if % != 0 goto comm_timeout
let $i2=$left($i4,1)
if len($i4)>2 let $i3=$mid($i4,2,len($i4)-2)
let $d="Unknown modem response ("+$i2+")"
if $i2 = "0" let $d="Not registered. The MS is not searching the new operators to be registered"
if $i2 = "1" let $d="Local network is registered"
if $i2 = "2" let $d="Not registered. But the MS is searching the new operators to be registered"
if $i2 = "3" let $d="Registration rejected"
if $i2 = "4" let $d="Unknown reasons"
if $i2 = "5" let $d="Roaming network is registered"
print $x+"- status: "+$d+"\n"
print $x+"- lac, ci: "+$i3+"\n"
send "AT+CGREG=0^m"
waitfor 1 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
if % = -1 goto comm_timeout
if % = 2 waitquiet 1 0.5
:end_cgreg
# Disable CME error report
send "AT+CMEE=0^m"
waitfor 5 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
if % = -1 goto comm_timeout
# Verify if the modem is connected
print $x+"Verify if the modem is connected\n"
send "AT\^DHCP?^m"
waitfor 5 "\^DHCP:","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
if % = -1 goto comm_timeout
if % = 0 print $x+"Modem is already connected\n" goto do_disconnect
if % = 3 print $x+"Command not supported\n" goto abort
print $x+"No connection detected\n"
# Disconnecting from current APN
goto end_disconnect
:do_disconnect
print $x+"Disconnecting from current APN\n"
send "AT\^NDISDUP=1,0^m"
waitfor 5 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
if % = -1 goto comm_timeout
if % = 1 print $x+"Error while disconnecting from current APN\n" goto abort
if % = 2 gosub cme_error print $x+"Error "+$e+" while disconnecting from current APN\n" goto abort
if % = 3 print $x+"Command not supported\n" goto abort
print $x+"Disconnected successfully\n"
waitquiet 1 0.5
:end_disconnect
# Setting mode
if $m = "" goto end_mode_set
print $x+"Setting mode "+$m+"\n"
send $m+"^m"
waitfor 5 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
if % = -1 goto comm_timeout
if % = 1 print $x+"Error while setting mode error\n" goto abort
if % = 2 gosub cme_error print $x+"Error "+$e+" while setting mode error\n" goto abort
if % = 3 print $x+"Command not supported\n" goto abort
print $x+"Mode set successfully\n"
:end_mode_set
# Establishing connection
print $x+"Try to establish connection via APN "+$a+"\n"
send "AT\^NDISDUP=1,1,\""+$a+"\"^m"
waitfor 5 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
if % = -1 goto comm_timeout
if % = 1 print $x+"Error while connecting\n" goto abort
if % = 2 gosub cme_error print $x+"Error "+$e+" while connecting\n" goto abort
if % = 3 print $x+"Command not supported\n" goto abort
print $x+"Waiting for establish connection\n"
let r3=0
:wait_for_connection
let r3=r3+1
if r3>20 goto restart_modem
send "AT\^DHCP?^m"
waitfor 5 "\^DHCP:","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
if % = -1 goto comm_timeout
if % = 0 print $x+"Connection established\n" goto finish
if % = 1 waitquiet 1 1 goto wait_for_connection
if % = 2 waitquiet 1 1 goto wait_for_connection
if % = 3 print $x+"Command not supported\n" goto abort
# In case of normal exit
:finish
print $x+"Done.\n"
exit 0
# In case of occurred an error
:abort
print $x+"Done!\n"
exit 1
# Error CME routine
:cme_error
get 1 "^m" $e
let $e="'"+$e+"'"
return
# Restarting modem and start all
:restart_modem
let r1=r1+1
if r1>5 print $x+"Number of retries exhausted\n" goto abort
print $x+"Restarting modem\n"
waitquiet 2 2
send "AT\^NDISDUP=1,0^m"
waitquiet 2 1
send "ATZ^m"
waitquiet 2 1
send "AT&F^m"
waitquiet 2 1
send "AT+CFUN=1^m"
waitquiet 2 1
goto start
# Timeout detected
:comm_timeout
print $x+"Modem is not responding, timeout detected\n"
goto restart_modem
# DoneBędę wdzięczny za uwagi. Pozdrawiam.
Tu moje skrypty na GitHub