-
Notifications
You must be signed in to change notification settings - Fork 41
/
pistar-remote
executable file
·524 lines (464 loc) · 24.3 KB
/
pistar-remote
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
#!/usr/bin/python
###############################################################################
# #
# Pi-Star Auto Remote Control #
# #
# Version 1.9, Code, Design and Development by Andy Taylor (MW0MWZ). #
# #
# This Python script is desiged to look for specific things in the logs for #
# MMDVMHost and act on those to give RF control over the repeater. #
# #
###############################################################################
import datetime
import time
import linecache
import os
import subprocess
import ConfigParser
import random
# Read the config;
config = ConfigParser.RawConfigParser()
config.read('/etc/pistar-remote')
# Read the MMDVMHost config;
mmdvmConfig = ConfigParser.RawConfigParser()
mmdvmConfig.read('/etc/mmdvmhost')
# Read the YSFGateway config;
ysfGatewayConfig = ConfigParser.RawConfigParser()
ysfGatewayConfig.read('/etc/ysfgateway')
# If not enabled, die;
isEnabled = config.get('enable', 'enabled')
if (isEnabled != 'true'):
quit()
# Substitute variables from config
mmdvmLogPath = mmdvmConfig.get('Log', 'FilePath')
mmdvmFileRoot = mmdvmConfig.get('Log', 'FileRoot')
ysfGatewayLogPath = ysfGatewayConfig.get('Log', 'FilePath')
ysfGatewayFileRoot = ysfGatewayConfig.get('Log', 'FileRoot')
keeperCall = config.get('keeper', 'callsign')
# DMR Control Options
if config.has_option('dmr', 'svckill'):
dmrstop = config.get('dmr', 'svckill')
else:
dmrstop = str(999999999999)
if config.has_option('dmr', 'svcrestart'):
dmrrestart = config.get('dmr', 'svcrestart')
else:
dmrrestart = str(999999999999)
if config.has_option('dmr', 'reboot'):
dmrreboot = config.get('dmr', 'reboot')
else:
dmrreboot = str(999999999999)
if config.has_option('dmr', 'shutdown'):
dmrshutdown = config.get('dmr', 'shutdown')
else:
dmrshutdown = str(999999999999)
if config.has_option('dmr', 'hostfiles'):
dmrhostfiles = config.get('dmr', 'hostfiles')
else:
dmrhostfiles = str(999999999999)
# D-Star Control Options
if config.has_option('d-star', 'svckill'):
dstarstop = config.get('d-star', 'svckill')
else:
dstarstop = str(999999999999)
if config.has_option('d-star', 'svcrestart'):
dstarrestart = config.get('d-star', 'svcrestart')
else:
dstarrestart = str(999999999999)
if config.has_option('d-star', 'reboot'):
dstarreboot = config.get('d-star', 'reboot')
else:
dstarreboot = str(999999999999)
if config.has_option('d-star', 'shutdown'):
dstarshutdown = config.get('d-star', 'shutdown')
else:
dstarshutdown = str(999999999999)
if config.has_option('d-star', 'hostfiles'):
dstarhostfiles = config.get('d-star', 'hostfiles')
else:
dstarhostfiles = str(999999999999)
if config.has_option('d-star', 'getip'):
dstargetip = config.get('d-star', 'getip')
else:
dstargetip = str(999999999999)
if config.has_option('d-star', 'wifissid'):
dstargetwifissid = config.get('d-star', 'wifissid')
else:
dstargetwifissid = str(999999999999)
if config.has_option('d-star', 'wifirssi'):
dstargetwifirssi = config.get('d-star', 'wifirssi')
else:
dstargetwifirssi = str(999999999999)
if config.has_option('d-star', '8Ball'):
dstar8ball = config.get('d-star', '8Ball')
else:
dstar8ball = str(999999999999)
dstarmodule = mmdvmConfig.get('General', 'Callsign').ljust(7) + mmdvmConfig.get('D-Star', 'Module')
# YSF Control Options
if config.has_option('ysf', 'svckill'):
ysfstop = config.get('ysf', 'svckill')
else:
ysfstop = str(999999999999)
if config.has_option('ysf', 'svcrestart'):
ysfrestart = config.get('ysf', 'svcrestart')
else:
ysfrestart = str(999999999999)
if config.has_option('ysf', 'reboot'):
ysfreboot = config.get('ysf', 'reboot')
else:
ysfreboot = str(999999999999)
if config.has_option('ysf', 'shutdown'):
ysfshutdown = config.get('ysf', 'shutdown')
else:
ysfshutdown = str(999999999999)
if config.has_option('ysf', 'hostfiles'):
ysfhostfiles = config.get('ysf', 'hostfiles')
else:
ysfhostfiles = str(999999999999)
# P25 Control Options
if config.has_option('p25', 'svckill'):
p25stop = config.get('p25', 'svckill')
else:
p25stop = str(999999999999)
if config.has_option('p25', 'svcrestart'):
p25restart = config.get('p25', 'svcrestart')
else:
p25restart = str(999999999999)
if config.has_option('p25', 'reboot'):
p25reboot = config.get('p25', 'reboot')
else:
p25reboot = str(999999999999)
if config.has_option('p25', 'shutdown'):
p25shutdown = config.get('p25', 'shutdown')
else:
p25shutdown = str(999999999999)
if config.has_option('p25', 'hostfiles'):
p25hostfiles = config.get('p25', 'hostfiles')
else:
p25hostfiles = str(999999999999)
# 8-Ball answers
magic8ball = [
'It is certain',
'It is decidedly so',
'Without a doubt',
'Yes definitely',
'You may rely on it',
'As I see it, yes',
'Most likely',
'Outlook good',
'Yes',
'Signs point to yes',
'Reply hazy try agn',
'Ask again later',
'Tell you later',
'Cannot predict now',
'Concentrate, ask agn',
'Dont count on it',
'My reply is no',
'My sources say no',
'Outlook not so good',
'Very doubtful'
]
# Some Variables that are important later
txtTransmitOldBin = '/usr/local/bin/texttransmit'
txtTransmitNewBin = '/usr/local/bin/texttransmitd'
if os.path.isfile(txtTransmitOldBin):
txtTransmitBin = '/usr/local/bin/texttransmit'
if os.path.isfile(txtTransmitNewBin):
txtTransmitBin = '/usr/local/bin/texttransmitd'
# Now run the loop
while True:
# Check that the process is running, if its not there is no point in trying to stop it.
checkproc = subprocess.Popen('pgrep' + ' MMDVMHost', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if checkproc.stdout.readlines():
# This is the main loop that keeps waiting, we dont want to hammer the logs too often, every 30 secs should be enough.
utcnow = datetime.datetime.utcnow()
datenow = utcnow.strftime('%Y-%m-%d')
dateminus60sec = datetime.datetime.utcnow() - datetime.timedelta(seconds=30)
logstampnow = utcnow.strftime('%Y-%m-%d %H:%M:%S')
logstampnowminus60sec = dateminus60sec.strftime('%Y-%m-%d %H:%M:%S')
currentLog = mmdvmLogPath + '/' + mmdvmFileRoot + '-' + datenow + '.log'
currentLogYSF = ysfGatewayLogPath + '/' + ysfGatewayFileRoot + '-' + datenow + '.log'
# Open the MMDVMHost Log
logfile = open(currentLog, 'r')
loglist = logfile.readlines()
logfile.close()
# Parse the log lines
for line in loglist:
# We only care about logs in the last 60 secs
if line[3:22] >= logstampnowminus60sec and line[3:22] <= logstampnow:
# DMR Stop MMDVMHost
# M: 2017-07-03 09:39:38.208 DMR Slot 2, received RF voice header from M1ABC to 123456
if str('received RF voice header from ' + keeperCall + ' to ' + dmrstop) in line:
# Kill the Services
os.system(r'systemctl stop mmdvmhost.timer')
os.system(r'systemctl stop pistar-watchdog.timer')
os.system(r'systemctl stop mmdvmhost.service')
os.system(r'systemctl stop pistar-watchdog.service')
# DMR Restart MMDVMHost
# M: 2017-07-03 09:39:38.208 DMR Slot 2, received RF voice header from M1ABC to 123456
if str('received RF voice header from ' + keeperCall + ' to ' + dmrrestart) in line:
# Restart the Services
os.system(r'systemctl restart mmdvmhost.service')
os.system(r'systemctl restart dmrgateway.service')
time.sleep(30)
# DMR Restart the OS
# M: 2017-07-03 09:39:38.208 DMR Slot 2, received RF voice header from M1ABC to 123456
if str('received RF voice header from ' + keeperCall + ' to ' + dmrreboot) in line:
# Restart the OS
os.system(r'shutdown -r now')
# DMR Shutdown the OS
# M: 2017-07-03 09:39:38.208 DMR Slot 2, received RF voice header from M1ABC to 123456
if str('received RF voice header from ' + keeperCall + ' to ' + dmrshutdown) in line:
# Shutdown the OS
os.system(r'shutdown -h now')
# DMR Update Hostfiles
# M: 2017-07-03 09:39:38.208 DMR Slot 2, received RF voice header from M1ABC to 123456
if str('received RF voice header from ' + keeperCall + ' to ' + dmrhostfiles) in line:
# Update Host files
os.system(r'/bin/mount -o remount,rw /')
os.system(r'/usr/local/sbin/HostFilesUpdate.sh')
# P25 Stop MMDVMHost
# M: 2017-08-08 08:02:43.352 P25, received RF transmission from M1ABC to TG 123456
if str('P25, received RF transmission from ' + keeperCall + ' to TG ' + p25stop) in line:
# Kill the Services
os.system(r'systemctl stop mmdvmhost.timer')
os.system(r'systemctl stop pistar-watchdog.timer')
os.system(r'systemctl stop mmdvmhost.service')
os.system(r'systemctl stop pistar-watchdog.service')
# P25 Restart MMDVMHost
# M: 2017-08-08 08:02:43.352 P25, received RF transmission from M1ABC to TG 123456
if str('P25, received RF transmission from ' + keeperCall + ' to TG ' + p25restart) in line:
# Restart the Services
os.system(r'systemctl restart mmdvmhost.service')
os.system(r'systemctl restart dmrgateway.service')
time.sleep(30)
# P25 Restart the OS
# M: 2017-08-08 08:02:43.352 P25, received RF transmission from M1ABC to TG 123456
if str('P25, received RF transmission from ' + keeperCall + ' to TG ' + p25reboot) in line:
# Restart the OS
os.system(r'shutdown -r now')
# P25 Shutdown the OS
# M: 2017-08-08 08:02:43.352 P25, received RF transmission from M1ABC to TG 123456
if str('P25, received RF transmission from ' + keeperCall + ' to TG ' + p25shutdown) in line:
# Shutdown the OS
os.system(r'shutdown -h now')
# P25 Update Hostfiles
# M: 2017-08-08 08:02:43.352 P25, received RF transmission from M1ABC to TG 123456
if str('P25, received RF transmission from ' + keeperCall + ' to TG ' + p25hostfiles) in line:
# Update Host Files
os.system(r'/bin/mount -o remount,rw /')
os.system(r'/usr/local/sbin/HostFilesUpdate.sh')
# D-Star Stop MMDVMHost
# M: 2017-07-03 11:38:57.349 D-Star, received RF header from M1ABC /1234 to COMMAND1
if str('D-Star, received RF header from ' + keeperCall + ' ') and str(dstarstop) in line:
# Kill the Services
os.system(txtTransmitBin + ' -text "Shutting down at keeper request" "' + dstarmodule + '"')
time.sleep(5)
os.system(r'systemctl stop mmdvmhost.timer')
os.system(r'systemctl stop pistar-watchdog.timer')
os.system(r'systemctl stop mmdvmhost.service')
os.system(r'systemctl stop pistar-watchdog.service')
# D-Star Restart MMDVMHost
# M: 2017-07-03 11:38:57.349 D-Star, received RF header from M1ABC /1234 to COMMAND1
if str('D-Star, received RF header from ' + keeperCall + ' ') and str(dstarrestart) in line:
# Restart the Services
os.system(txtTransmitBin + ' -text "Restarting services at keeper request" "' + dstarmodule + '"')
time.sleep(5)
os.system(r'systemctl restart ircddbgateway.service')
os.system(r'systemctl restart mmdvmhost.service')
time.sleep(30)
# D-Star Reboot the OS
# M: 2017-07-03 11:38:57.349 D-Star, received RF header from M1ABC /1234 to COMMAND1
if str('D-Star, received RF header from ' + keeperCall + ' ') and str(dstarreboot) in line:
# Kill the Services
os.system(txtTransmitBin + ' -text "Rebooting OS at keeper request" "' + dstarmodule + '"')
time.sleep(5)
os.system(r'shutdown -r now')
# D-Star Shutdown the OS
# M: 2017-07-03 11:38:57.349 D-Star, received RF header from M1ABC /1234 to COMMAND1
if str('D-Star, received RF header from ' + keeperCall + ' ') and str(dstarshutdown) in line:
# Shutdown
os.system(txtTransmitBin + ' -text "Shutting down OS at keeper request" "' + dstarmodule + '"')
time.sleep(5)
os.system(r'shutdown -h now')
# D-Star Hostfiles Update
# M: 2017-07-03 11:38:57.349 D-Star, received RF header from M1ABC /1234 to COMMAND1
if str('D-Star, received RF header from ' + keeperCall + ' ') and str(dstarhostfiles) in line:
# Update Host files
os.system(txtTransmitBin + ' -text "Updating Hostfiles at keeper request" "' + dstarmodule + '"')
time.sleep(5)
os.system(r'/bin/mount -o remount,rw /')
os.system(r'/usr/local/sbin/HostFilesUpdate.sh')
# D-Star Get the current IP
# M: 2017-07-03 11:38:57.349 D-Star, received RF header from M1ABC /1234 to COMMAND1
if str('D-Star, received RF header from ' + keeperCall + ' ') and str(dstargetip) in line:
# Get the IP
myIP = os.popen('/bin/hostname -I | awk \'{print $1}\'').read()
os.system(txtTransmitBin + ' -text "IP: ' + myIP + '" "' + dstarmodule + '"')
# D-Star Get the wifi SSID
# M: 2017-07-03 11:38:57.349 D-Star, received RF header from M1ABC /1234 to COMMAND1
if str('D-Star, received RF header from ' + keeperCall + ' ') and str(dstargetwifissid) in line:
# Get the SSID
if os.path.islink('/sys/class/net/wlan0'):
ssid = os.popen('/sbin/iwconfig wlan0 | grep ESSID | awk -F ":" \'{print $2}\' | sed \'s/"//g\'').read()
os.system(txtTransmitBin + ' -text "SSID: ' + ssid + '" "' + dstarmodule + '"')
else:
os.system(txtTransmitBin + ' -text "WiFi: Not connected" "' + dstarmodule + '"')
# D-Star Get the wifi RSSI
# M: 2017-07-03 11:38:57.349 D-Star, received RF header from M1ABC /1234 to COMMAND1
if str('D-Star, received RF header from ' + keeperCall + ' ') and str(dstargetwifirssi) in line:
# Get the SSID
if os.path.islink('/sys/class/net/wlan0'):
rssi = os.popen('/sbin/iwconfig wlan0 | grep -i "signal level" | awk -F "=" \'{print $3}\'').read()
os.system(txtTransmitBin + ' -text "RSSI: ' + rssi + '" "' + dstarmodule + '"')
else:
os.system(txtTransmitBin + ' -text "WiFi: Not connected" "' + dstarmodule + '"')
# D-Star 8Ball
# M: 2017-07-03 11:38:57.349 D-Star, received RF header from M1ABC /1234 to COMMAND1
if str('D-Star, received RF header from ' + keeperCall + ' ') and str(dstar8ball) in line:
# Ask the 8Ball
magic8ballanswer = random.choice(magic8ball)
os.system(txtTransmitBin + ' -text "' + magic8ballanswer + '" "' + dstarmodule + '"')
# YSF
# M: 2017-07-13 19:50:43.464 YSF, received RF header from M1ABC to ALL
if str('YSF, received RF header from ' + keeperCall + ' ') in line:
# YSF Log Checking here
logfileysf = open(currentLogYSF, 'r')
loglistysf = logfileysf.readlines()
logfileysf.close()
checkproc = subprocess.Popen('pgrep' + ' YSFGateway', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if checkproc.stdout.readlines():
# Parse the log lines
for lineysf in loglistysf:
# We only care about logs in the last 60 secs
if lineysf[3:22] >= logstampnowminus60sec and lineysf[3:22] <= logstampnow:
# YSF Stop MMDVMHost
# M: 2017-07-13 19:24:59.704 Trying to find non existent reflector with an id of 12345
if (str('Trying to find non existent') and str(ysfstop) in lineysf) or (str('Received Connect to') and str(ysfstop) in lineysf):
# Kill the Services
os.system(r'systemctl stop mmdvmhost.timer')
os.system(r'systemctl stop pistar-watchdog.timer')
os.system(r'systemctl stop mmdvmhost.service')
os.system(r'systemctl stop pistar-watchdog.service')
# YSF Restart MMDVMHost
# M: 2017-07-13 19:24:59.704 Trying to find non existent reflector with an id of 12345
if (str('Trying to find non existent') and str(ysfrestart) in lineysf) or (str('Received Connect to') and str(ysfrestart) in lineysf):
# Restart the Services
os.system(r'systemctl restart ysfgateway.service')
os.system(r'systemctl restart mmdvmhost.service')
time.sleep(30)
# YSF Reboot the OS
# M: 2017-07-13 19:24:59.704 Trying to find non existent reflector with an id of 12345
if (str('Trying to find non existent') and str(ysfreboot) in lineysf) or (str('Received Connect to') and str(ysfreboot) in lineysf):
# Reboot the OS
os.system(r'shutdown -r now')
# YSF Shutdown the OS
# M: 2017-07-13 19:24:59.704 Trying to find non existent reflector with an id of 12345
if (str('Trying to find non existent') and str(ysfshutdown) in lineysf) or (str('Received Connect to') and str(ysfshutdown) in lineysf):
# Shutdown the OS
os.system(r'shutdown -h now')
# YSF Update the Hostfiles
# M: 2017-07-13 19:24:59.704 Trying to find non existent reflector with an id of 12345
if (str('Trying to find non existent') and str(ysfhostfiles) in lineysf) or (str('Received Connect to') and str(ysfhostfiles) in lineysf):
# Update the host files
os.system(r'/bin/mount -o remount,rw /')
os.system(r'/usr/local/sbin/HostFilesUpdate.sh')
# This is the 30 second sleep before the next pass.
time.sleep(30)
# Check that the process is running, if its not there is no point in trying to stop it.
checkproc = subprocess.Popen('pgrep' + ' dstarrepeaterd', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if checkproc.stdout.readlines():
# This is the main loop that keeps waiting, we dont want to hammer the logs too often, every 30 secs should be enough.
utcnow = datetime.datetime.utcnow()
datenow = utcnow.strftime('%Y-%m-%d')
dateminus60sec = datetime.datetime.utcnow() - datetime.timedelta(minutes=1)
logstampnow = utcnow.strftime('%Y-%m-%d %H:%M:%S')
logstampnowminus60sec = dateminus60sec.strftime('%Y-%m-%d %H:%M:%S')
# Best figure out the log name now
currentLogDStarOld = '/var/log/pi-star/DStarRepeater-' + datenow + '.log'
currentLogDStarNew = '/var/log/pi-star/dstarrepeaterd-' + datenow + '.log'
if os.path.isfile(currentLogDStarOld):
currentLogDStar = currentLogDStarOld
if os.path.isfile(currentLogDStarNew):
currentLogDStar = currentLogDStarNew
# Open the DStarRepeater Log
logfile = open(currentLogDStar, 'r')
loglist = logfile.readlines()
logfile.close()
# Parse the log lines
for line in loglist:
# We only care about logs in the last 60 secs
if line[3:22] >= logstampnowminus60sec and line[3:22] <= logstampnow:
# D-Star Stop Services
# M: 2017-12-24 20:40:15: Radio header decoded - My: M1ABC /M Your: COMMAND1 Rpt1: M1ABC B Rpt2: M1ABC G Flags: 40 00 00
if str('Radio header decoded - My: ' + keeperCall + ' ') and str('Your: ' + dstarstop) in line:
# Kill the Services
os.system(txtTransmitBin + ' -text "Shutting down at keeper request" "' + dstarmodule + '"')
time.sleep(5)
os.system(r'systemctl stop dstarrepeater.timer')
os.system(r'systemctl stop pistar-watchdog.timer')
os.system(r'systemctl stop dstarrepeater.service')
os.system(r'systemctl stop pistar-watchdog.service')
# D-Star Restart Services
# M: 2017-12-24 20:40:15: Radio header decoded - My: M1ABC /M Your: COMMAND1 Rpt1: M1ABC B Rpt2: M1ABC G Flags: 40 00 00
if str('Radio header decoded - My: ' + keeperCall + ' ') and str('Your: ' + dstarrestart) in line:
# Restart the Services
os.system(txtTransmitBin + ' -text "Restarting services at keeper request" "' + dstarmodule + '"')
time.sleep(5)
os.system(r'systemctl restart ircddbgateway.service')
os.system(r'systemctl restart dstarrepeater.service')
# D-Star Reboot the OS
# M: 2017-12-24 20:40:15: Radio header decoded - My: M1ABC /M Your: COMMAND1 Rpt1: M1ABC B Rpt2: M1ABC G Flags: 40 00 00
if str('Radio header decoded - My: ' + keeperCall + ' ') and str('Your: ' + dstarreboot) in line:
# Reboot
os.system(txtTransmitBin + ' -text "Rebooting OS at keeper request" "' + dstarmodule + '"')
time.sleep(5)
os.system(r'shutdown -r now')
# D-Star Shutdown the OS
# M: 2017-12-24 20:40:15: Radio header decoded - My: M1ABC /M Your: COMMAND1 Rpt1: M1ABC B Rpt2: M1ABC G Flags: 40 00 00
if str('Radio header decoded - My: ' + keeperCall + ' ') and str('Your: ' + dstarshutdown) in line:
# Shutdown
os.system(txtTransmitBin + ' -text "Shutting down OS at keeper request" "' + dstarmodule + '"')
time.sleep(5)
os.system(r'shutdown -h now')
# D-Star Update the host files
# M: 2017-12-24 20:40:15: Radio header decoded - My: M1ABC /M Your: COMMAND1 Rpt1: M1ABC B Rpt2: M1ABC G Flags: 40 00 00
if str('Radio header decoded - My: ' + keeperCall + ' ') and str('Your: ' + dstarhostfiles) in line:
# Update the host files
os.system(txtTransmitBin + ' -text "Updating Hostfiles at keeper request" "' + dstarmodule + '"')
time.sleep(5)
os.system(r'/bin/mount -o remount,rw /')
os.system(r'/usr/local/sbin/HostFilesUpdate.sh')
# D-Star Get the current IP
# M: 2017-12-24 20:40:15: Radio header decoded - My: M1ABC /M Your: COMMAND1 Rpt1: M1ABC B Rpt2: M1ABC G Flags: 40 00 00
if str('Radio header decoded - My: ' + keeperCall + ' ') and str('Your: ' + dstargetip) in line:
# Get the IP
myIP = os.popen('/bin/hostname -I | awk \'{print $1}\'').read()
os.system(txtTransmitBin + ' -text "My IP: ' + myIP + '" "' + dstarmodule + '"')
# D-Star Get the wifi SSID
# M: 2017-12-24 20:40:15: Radio header decoded - My: M1ABC /M Your: COMMAND1 Rpt1: M1ABC B Rpt2: M1ABC G Flags: 40 00 00
if str('Radio header decoded - My: ' + keeperCall + ' ') and str('Your: ' + dstargetwifissid) in line:
# Get the SSID
if os.path.islink('/sys/class/net/wlan0'):
ssid = os.popen('/sbin/iwconfig wlan0 | grep ESSID | awk -F ":" \'{print $2}\' | sed \'s/"//g\'').read()
os.system(txtTransmitBin + ' -text "SSID: ' + ssid + '" "' + dstarmodule + '"')
else:
os.system(txtTransmitBin + ' -text "WiFi: Not connected" "' + dstarmodule + '"')
# D-Star Get the wifi RSSI
# M: 2017-12-24 20:40:15: Radio header decoded - My: M1ABC /M Your: COMMAND1 Rpt1: M1ABC B Rpt2: M1ABC G Flags: 40 00 00
if str('Radio header decoded - My: ' + keeperCall + ' ') and str('Your: ' + dstargetwifirssi) in line:
# Get the SSID
if os.path.islink('/sys/class/net/wlan0'):
rssi = os.popen('/sbin/iwconfig wlan0 | grep -i "signal level" | awk -F "=" \'{print $3}\'').read()
os.system(txtTransmitBin + ' -text "RSSI: ' + rssi + '" "' + dstarmodule + '"')
else:
os.system(txtTransmitBin + ' -text "WiFi: Not connected" "' + dstarmodule + '"')
# D-Star 8Ball
# M: 2017-12-24 20:40:15: Radio header decoded - My: M1ABC /M Your: COMMAND1 Rpt1: M1ABC B Rpt2: M1ABC G Flags: 40 00 00
if str('Radio header decoded - My: ' + keeperCall + ' ') and str('Your: ' + dstar8ball) in line:
# Ask the 8Ball
magic8ballanswer = random.choice(magic8ball)
os.system(txtTransmitBin + ' -text "' + magic8ballanswer + '" "' + dstarmodule + '"')
# This is the 30 second sleep before the next pass.
time.sleep(30)