-
Notifications
You must be signed in to change notification settings - Fork 1
/
cmd.sh
executable file
·213 lines (185 loc) · 7.11 KB
/
cmd.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
#!/bin/bash
#-------------------------------------------------------------------------------
# Copyright 2016 Congduc Pham, University of Pau, France.
#
#
# This file is part of the low-cost LoRa gateway developped at University of Pau
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with the program. If not, see <http://www.gnu.org/licenses/>.
#-------------------------------------------------------------------------------
choice="Z"
if [ ! -f gateway_id.txt ]
then
echo "ERROR: gateway_id.txt file not found"
echo "should create it by running echo \"000000XXXXXXXXXX\" > gateway_id.txt"
echo "where XXXXXXXXXX is the last 5 bytes of your MAC Ethernet interface address"
echo "Example: echo \"00000027EBBEDA21\" > gateway_id.txt"
echo "Here is your MAC Ethernet interface address:"
echo "-------------------------------------------------------"
ifconfig | grep "eth0"
echo "-------------------------------------------------------"
echo "Enter the last 5 hex bytes of your MAC Ethernet interface address"
echo "in capital character and without the : separator"
echo "example: HWaddr b8:27:eb:be:da:21 then just enter 27EBBEDA21"
read macaddr
echo "Will write 000000$macaddr into gateway_id.txt"
echo "000000$macaddr" > gateway_id.txt
echo "Done"
fi
gatewayid=`cat gateway_id.txt`
while [ "$choice" != "Q" ]
do
echo "=======================================* Gateway $gatewayid *==="
echo "0- nohup python start_gw.py & +"
echo "1- sudo ./lora_gateway --mode 1 +"
echo "2- sudo ./lora_gateway --mode 1|python post_processing_gw.py -t -m 2 +"
echo "3- ps aux | grep -e start_gw -e lora_gateway -e post_proc -e log_gw +"
echo "4- tail --line=25 ../Dropbox/LoRa-test/post-processing_*.log +"
echo "5- tail --line=25 -f ../Dropbox/LoRa-test/post-processing_*.log +"
echo "------------------------------------------------------* Bluetooth *--+"
echo "a- run: sudo hciconfig hci0 piscan +"
echo "b- run: sudo python rfcomm-server.py +"
echo "c- run: nohup sudo python rfcomm-server.py -bg > rfcomm.log & +"
echo "d- run: ps aux | grep rfcomm +"
echo "e- run: tail -f rfcomm.log +"
echo "---------------------------------------------------* Connectivity *--+"
echo "f- test: ping www.univ-pau.fr +"
echo "--------------------------------------------------* Configuration *--+"
echo "A- show global_conf.json +"
echo "B- show local_conf.json +"
echo "C- edit global_conf.json +"
echo "-----------------------------------------------------------* kill *--+"
echo "K- kill all gateway related processes +"
echo "k- kill rfcomm-server process +"
echo "---------------------------------------------------------------------+"
echo "Q- quit +"
echo "======================================================================"
echo "Enter your choice: "
read choice
echo "----------------------------------------------------------------------"
echo "BEGIN OUTPUT"
if [ "$choice" = "0" ]
then
echo "Running in background the full LoRa gateway"
python start_gw.py &
disown %1
echo "Check ../Dropbox/LoRa-test/post-processing_$gatewayid.log file (select command 5)"
fi
if [ "$choice" = "1" ]
then
echo "Running simple lora_gateway... CTRL-C to exit"
sudo ./lora_gateway --mode 1
fi
if [ "$choice" = "2" ]
then
echo "Running lora_gateway with post-processing... CTRL-C to exit"
sudo ./lora_gateway --mode 1 | python post_processing_gw.py -t -m 2
fi
if [ "$choice" = "3" ]
then
echo "Check for lora_gateway process"
echo "##############################"
ps aux | grep -e start_gw -e lora_gateway -e post_processing -e log_gw
echo "##############################"
echo "The gateway is running if you see the lora_gateway process"
fi
if [ "$choice" = "4" ]
then
echo "Displaying last 25 lines of ../Dropbox/LoRa-test/post-processing_$gatewayid.log"
echo "Current UTC date is"
date --utc
tail --line=25 ../Dropbox/LoRa-test/post-processing_$gatewayid.log
fi
if [ "$choice" = "5" ]
then
echo "Following last lines of ../Dropbox/LoRa-test/post-processing_$gatewayid.log. CTRL-C to return"
echo "Current UTC date is"
date --utc
trap "echo" SIGINT
tail --line=25 -f ../Dropbox/LoRa-test/post-processing_$gatewayid.log
fi
if [ "$choice" = "a" ]
then
echo "Testing the Bluetooth interface"
echo "###############################"
sudo hciconfig hci0 piscan
echo "###############################"
echo "if no error then the RPI is visible with Bluetooth"
fi
if [ "$choice" = "b" ]
then
echo "Running rfcomm server for Bluetooth queries... CTRL-C to exit"
sudo python rfcomm-server.py
fi
if [ "$choice" = "c" ]
then
echo "Running in background the rfcomm server for Bluetooth queries. Logs in rfcomm.log"
nohup sudo python rfcomm-server.py -bg > rfcomm.log &
fi
if [ "$choice" = "d" ]
then
echo "Check for rfcomm-server process"
echo "###############################"
ps aux | grep rfcomm-server
echo "###############################"
echo "You should see python rfcomm-server.py for Bluetooth queries"
fi
if [ "$choice" = "e" ]
then
echo "Following last lines of rfcomm.log. CTRL-C to return"
echo "Current UTC date is"
date --utc
trap "echo" SIGINT
tail -f rfcomm.log
fi
if [ "$choice" = "f" ]
then
echo "Test Internet connectivity. CTRL-C to return"
trap "echo" SIGINT
ping www.univ-pau.fr
fi
if [ "$choice" = "A" ]
then
echo "Showing global_conf.json"
cat global_conf.json
fi
if [ "$choice" = "B" ]
then
echo "Showing local_conf.json"
cat local_conf.json
fi
if [ "$choice" = "C" ]
then
echo "Editing global_conf.json. CTRL-O to save, CTRL-X to return"
nano global_conf.json
fi
if [ "$choice" = "K" ]
then
echo "Killing all gateway related processes"
sudo kill $(ps aux | grep -e start_gw -e lora_gateway -e post_processing -e log_gw | awk '{print $2}')
fi
if [ "$choice" = "k" ]
then
echo "Killing rfcomm-server process"
sudo kill $(ps aux | grep -e rfcomm-server | awk '{print $2}')
fi
echo "END OUTPUT"
if [ "$choice" != "Q" ]
then
echo "Press RETURN/ENTER..."
read k
fi
done
echo "Bye."