-
Notifications
You must be signed in to change notification settings - Fork 1
/
gateway-config.sh
306 lines (283 loc) · 10.1 KB
/
gateway-config.sh
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#!/bin/sh
do_setup_admin_password() {
dialog --title "Setup admin password" --msgbox "You will be asked to enter a new password." 5 60
passwd admin
RET=$?
if [ $RET -eq 0 ]; then
dialog --title "Setup admin password" --msgbox "Password has been changed succesfully." 5 60
else
exit $RET
fi
}
do_setup_concentrator_shield() {
FUN=$(dialog --title "Setup LoRa concentrator shield" --menu "Select shield:" 15 60 4 \
1 "IMST - iC880A" \
2 "RAK - RAK831 & RAK2245" \
3 "RisingHF - RHF0M301" \
4 "Sandbox - LoRaGo PORT" \
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 0 ]; then
case "$FUN" in
1) do_prompt_concentrator_reset_pin && do_setup_ic880a;;
2) do_set_concentrator_reset_pin 17 && do_setup_rak831;;
3) do_set_concentrator_reset_pin 7 && do_setup_rhf0m301;;
4) do_set_concentrator_reset_pin 25 && do_setup_lorago_port;;
esac
fi
}
do_setup_ic880a() {
FUN=$(dialog --title "Channel-plan configuration" --menu "Select the channel-plan:" 15 60 1 \
1 "EU868" \
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
do_main_menu
elif [ $RET -eq 0 ]; then
case "$FUN" in
1) do_copy_global_conf "ic880a" "eu868" && do_copy_loraserver_config "eu868";;
esac
fi
}
do_setup_rak831() {
FUN=$(dialog --title "Channel-plan configuration" --menu "Select the channel-plan:" 15 60 8 \
1 "EU868" \
2 "AU915" \
3 "US915" \
4 "AS920-923" \
5 "AS923-925" \
6 "KR920-923" \
7 "IN865-867" \
8 "CN470-510" \
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
do_main_menu
elif [ $RET -eq 0 ]; then
case "$FUN" in
1) do_copy_global_conf "rak831" "eu868" && do_copy_loraserver_config "eu868";;
2) do_select_au915_block "rak831";;
3) do_select_us915_block "rak831";;
4) do_copy_global_conf "rak831" "as1" && do_copy_loraserver_config "as1";;
5) do_copy_global_conf "rak831" "as2" && do_copy_loraserver_config "as2";;
6) do_copy_global_conf "rak831" "kr" && do_copy_loraserver_config "kr";;
7) do_copy_global_conf "rak831" "in" && do_copy_loraserver_config "in";;
8) do_copy_global_conf "rak831" "cn470" && do_copy_loraserver_config "cn470";;
esac
fi
}
do_setup_lorago_port() {
FUN=$(dialog --title "Channel-plan configuration" --menu "Select the channel-plan:" 15 60 2 \
1 "EU868" \
2 "US915" \
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
do_main_menu
elif [ $RET -eq 0 ]; then
case "$FUN" in
1) do_copy_global_conf "lorago_port" "eu868" && do_copy_loraserver_config "eu868";;
2) do_select_us915_block "lorago_port";;
esac
fi
}
do_select_us915_block() {
# $1: concentrator type
FUN=$(dialog --title "Channel-plan configuration" --menu "Select the US915 channel-block:" 15 60 8 \
1 "Channels 0 - 7 + 64" \
2 "Channels 8 - 15 + 65" \
3 "Channels 16 - 23 + 66" \
4 "Channels 24 - 31 + 67" \
5 "Channels 32 - 39 + 68" \
6 "Channels 40 - 47 + 69" \
7 "Channels 48 - 55 + 70" \
8 "Channels 56 - 64 + 71" \
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
do_main_menu
elif [ $RET -eq 0 ]; then
case "$FUN" in
1) do_copy_global_conf $1 "us915_0" && do_copy_loraserver_config "us915_0";;
2) do_copy_global_conf $1 "us915_1" && do_copy_loraserver_config "us915_1";;
3) do_copy_global_conf $1 "us915_2" && do_copy_loraserver_config "us915_2";;
4) do_copy_global_conf $1 "us915_3" && do_copy_loraserver_config "us915_3";;
5) do_copy_global_conf $1 "us915_4" && do_copy_loraserver_config "us915_4";;
6) do_copy_global_conf $1 "us915_5" && do_copy_loraserver_config "us915_5";;
7) do_copy_global_conf $1 "us915_6" && do_copy_loraserver_config "us915_6";;
8) do_copy_global_conf $1 "us915_7" && do_copy_loraserver_config "us915_7";;
esac
fi
}
do_select_au915_block() {
# $1: concentrator type
FUN=$(dialog --title "Channel-plan configuration" --menu "Select the AU915 channel-block:" 15 60 8 \
1 "Channels 0 - 7 + 64" \
2 "Channels 8 - 15 + 65" \
3 "Channels 16 - 23 + 66" \
4 "Channels 24 - 31 + 67" \
5 "Channels 32 - 39 + 68" \
6 "Channels 40 - 47 + 69" \
7 "Channels 48 - 55 + 70" \
8 "Channels 56 - 64 + 71" \
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
do_main_menu
elif [ $RET -eq 0 ]; then
case "$FUN" in
1) do_copy_global_conf $1 "au915_0" && do_copy_loraserver_config "au915_0";;
2) do_copy_global_conf $1 "au915_1" && do_copy_loraserver_config "au915_1";;
3) do_copy_global_conf $1 "au915_2" && do_copy_loraserver_config "au915_2";;
4) do_copy_global_conf $1 "au915_3" && do_copy_loraserver_config "au915_3";;
5) do_copy_global_conf $1 "au915_4" && do_copy_loraserver_config "au915_4";;
6) do_copy_global_conf $1 "au915_5" && do_copy_loraserver_config "au915_5";;
7) do_copy_global_conf $1 "au915_6" && do_copy_loraserver_config "au915_6";;
8) do_copy_global_conf $1 "au915_7" && do_copy_loraserver_config "au915_7";;
esac
fi
}
do_setup_rhf0m301() {
FUN=$(dialog --title "Channel-plan configuration" --menu "Select the channel-plan:" 15 60 2 \
1 "EU868" \
2 "US915" \
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
do_main_menu
elif [ $RET -eq 0 ]; then
case "$FUN" in
1) do_copy_global_conf "rhf0m301" "eu868" && do_copy_loraserver_config "eu868";;
2) do_copy_global_conf "rhf0m301" "us915" && do_copy_loraserver_config "us915_0";;
esac
fi
}
do_prompt_concentrator_reset_pin() {
PIN=$(dialog --inputbox "Please enter the GPIO pin to which the concentrator reset is connected: " 8 60 \
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
do_setup_concentrator_shield
elif [ $RET -eq 0 ]; then
do_set_concentrator_reset_pin $PIN
fi
}
do_set_concentrator_reset_pin() {
sed -i "s/^\(CONCENTRATOR_RESET_PIN=\).*$/\1$1/" /etc/default/lora-packet-forwarder
}
do_copy_global_conf() {
# $1 concentrator type
# $2 channel-plan
RET=0
if [ -f /etc/lora-packet-forwarder/global_conf.json ]; then
dialog --yesno "A packet-forwarder configuration file already exists. Do you want to overwrite it?" 6 60
RET=$?
fi
if [ $RET -eq 0 ]; then
cp /etc/lora-packet-forwarder/$1/global_conf.$2.json /etc/lora-packet-forwarder/global_conf.json
RET=$?
if [ $RET -eq 0 ]; then
dialog --title "Channel-plan configuration" --msgbox "Channel-plan configuration has been copied." 5 60
do_set_gateway_id
fi
fi
}
do_copy_loraserver_config() {
# $1 channel plan
if [ ! -d /etc/loraserver ]; then
return;
fi
RET=0
if [ -f /etc/loraserver/loraserver.toml ]; then
dialog --yesno "A LoRa Server configuration file already exists. Do you want to overwrite it?" 6 60
RET=$?
fi
if [ $RET -eq 0 ]; then
cp /etc/loraserver/config/$1.toml /etc/loraserver/loraserver.toml
do_restart_loraserver
fi
}
do_set_gateway_id() {
/opt/lora-packet-forwarder/update_gwid.sh /etc/lora-packet-forwarder/global_conf.json
RET=$?
if [ $RET -eq 0 ]; then
dialog --title "Set Gateway ID" --msgbox "The Gateway ID has been set." 5 60
do_restart_packet_forwarder
fi
}
do_restart_packet_forwarder() {
monit restart lora-packet-forwarder
RET=$?
if [ $RET -eq 0 ]; then
dialog --title "Restart packet-forwarder" --msgbox "The packet-forwarder has been restarted." 5 60
else
exit $RET
fi
}
do_restart_loraserver() {
monit restart loraserver
RET=$?
if [ $RET -eq 0 ]; then
dialog --title "Restart LoRa Server" --msgbox "LoRa Server has been restarted." 5 60
else
exit $RET
fi
}
do_restart_lora_gateway_bridge() {
monit restart lora-gateway-bridge
RET=$?
if [ $RET -eq 0 ]; then
dialog --title "Restart LoRa Gateway Bridge" --msgbox "The LoRa Gateway Bridge has been restarted." 5 60
else
exit $RET
fi
}
do_configure_wifi() {
dialog --title "Configure WIFI" --msgbox "This will open the 'connmanctl' utility to configure the WIFI." 5 75
dialog --title "connmanctl quickstart" --msgbox "1) Enable wifi:\n
enable wifi\n\n
2) Scan available wifi networks:\n
scan wifi\n\n
3) Display available wifi networks:\n
services\n\n
4) Turn on agent:\n
agent on\n\n
5) Connect to network:\n
connect wifi_...\n\n
6) Quit connmanctl:\n
quit" 25 60
clear
connmanctl
RET=$?
if [ ! $RET -eq 0 ]; then
exit $RET
fi
}
do_main_menu() {
FUN=$(dialog --title "LoRa Gateway OS" --cancel-label "Quit" --menu "Configuration options:" 15 60 7 \
1 "Set admin password" \
2 "Setup LoRa concentrator shield" \
3 "Edit packet-forwarder config" \
4 "Edit LoRa Gateway Bridge config" \
5 "Restart packet-forwarder" \
6 "Restart LoRa Gateway Bridge" \
7 "Configure WIFI" \
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
clear
exit 0
elif [ $RET -eq 0 ]; then
case "$FUN" in
1) do_setup_admin_password;;
2) do_setup_concentrator_shield;;
3) nano /etc/lora-packet-forwarder/global_conf.json;;
4) nano /etc/lora-gateway-bridge/lora-gateway-bridge.toml;;
5) do_restart_packet_forwarder;;
6) do_restart_lora_gateway_bridge;;
7) do_configure_wifi;;
esac
fi
do_main_menu
}
do_main_menu