-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathswitch_by_technology.rsc
92 lines (87 loc) · 3.11 KB
/
switch_by_technology.rsc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Setup and read current values, "up" SIM slot will be used for roaming, "down" for home network
:global simSlot [/system routerboard sim get sim-slot]
:global timeoutLTE 60
:global timeoutConnect 60
:global lastTechnology
:local egprs "GSM EGPRS"
:local lte "Evolved 3G (LTE)"
# Wait for LTE to initialize for maximum "timeoutLTE" seconds
:local i 0
:local isLTEinit false
:while ($i<$timeoutLTE) do={
:foreach n in=[/interface lte find] do={:set $isLTEinit true}
:if ($isLTEinit=true) do={
:set $i $timeoutLTE
}
:set $i ($i+1)
:delay 1s
}
# Check if LTE is initialized, or try power-reset the modem
:if ($isLTEinit=true) do={
# Wait for LTE interface to connect to mobile network for maximum "timeoutConnet" seconds
:local isConnected false
:set $i 0
:while ($i<$timeoutConnect) do={
:if ([/interface lte get [find name="lte1"] running]=true) do={
:set $isConnected true
:set $i $timeoutConnect
}
:set $i ($i+1)
:delay 1s
}
# Check if LTE is connected
if ($isConnected=true) do={
:local Info [/interface lte info [find name="lte1"] once as-value]
:local operator ($Info->"current-operator")
:local technology ($Info->"access-technology")
# Check which SIM slot is used
:if ($simSlot="down") do={
#Down card
:log info message="Operator $operator, technology $technology, last technology $lastTechnology"
:if ($technology=$egprs) do={
:log info message="EGPRS detected, switching to SIM UP"
:if ($lastTechnology="egprs") do={
:log info message="Previous technology was EGPRS too"
:global lastTechnology ""
/system scheduler set [find name="checkTechnology"] interval="10m"
} else={
:log info message="Previous technology was LTE/3G"
:global lastTechnology "egprs"
/system routerboard sim set sim-slot=up
}
} else={
:log info message="LTE/3G detected"
:if ($lastTechnology="egprs") do={
system scheduler set [find name="checkTechnology"] interval="1m"
:global lastTechnology ""
}
}
} else={
#Up card
:log info message="Operator $operator, technology $technology, last technology $lastTechnology"
:if ($technology=$egprs) do={
:log info message="EGPRS detected, switching to SIM UP"
:if ($lastTechnology="egprs") do={
:log info message="Previous technology was EGPRS too"
:global lastTechnology ""
/system scheduler set [find name="checkTechnology"] interval="10m"
} else={
:log info message="Previous technology was LTE/3G"
:global lastTechnology "egprs"
/system routerboard sim set sim-slot=down
}
} else={
:log info message="LTE/3G detected"
:if ($lastTechnology="egprs") do={
system scheduler set [find name="checkTechnology"] interval="1m"
:global lastTechnology ""
}
}
}
} else={
:log info message="LTE interface did not connect to network, wait for next scheduler"
}
} else={
:log info message="LTE modem did not appear, trying power-reset"
/system routerboard usb power-reset duration=5s
}