Browse code

bug fixes

gandolf authored on 01/22/2020 05:51:25
Showing 5 changed files
... ...
@@ -8,13 +8,16 @@
8 8
 APP_PATH="/home/$USER/bin"
9 9
 LOG_PATH="/home/$USER/log"
10 10
 
11
-if [ `hostname` == "raspi2" ]; then
12
-  AGENT_NAME="[a]rednsigAgent.py"
13
-  NODE_URL="-u http://192.168.1.30/cgi-bin/signal.json"
14
-else
15
-  AGENT_NAME="[a]rednsigMirrorAgent.py"
16
-  NODE_URL="-u http://73.157.139.23:7361/arednsig/dynamic/arednsigOutputData.js"
17
-fi
11
+#AGENT_NAME="[a]rednsigAgent.py"
12
+#NODE_URL="http://localnode:8080/cgi-bin/signal.json"
13
+
14
+AGENT_NAME="[a]rednsigAgent.py"
15
+NODE_URL="http://192.168.1.30:8080/cgi-bin/signal.json"
16
+
17
+#AGENT_NAME="[a]rednsigMirrorAgent.py"
18
+#NODE_URL="http://73.157.139.23:7361/arednsig/dynamic/arednsigOutputData.js"
19
+
20
+POLLING_INTERVAL="60"
18 21
 
19 22
 PROCESS_ID="$(ps x | awk -v a=$AGENT_NAME '$7 ~ a {print $1}')"
20 23
 
... ...
@@ -25,5 +28,6 @@ if [ -n "$PROCESS_ID" ]; then
25 28
 else
26 29
   printf "starting up arednsig agent\n"
27 30
   cd $APP_PATH
28
-  ./$AGENT_NAME $NODE_URL >> $LOG_PATH/arednsigAgent.log 2>&1 &
31
+  $(./$AGENT_NAME -u $NODE_URL -p $POLLING_INTERVAL >> \
32
+ $LOG_PATH/arednsigAgent.log 2>&1 &)
29 33
 fi
... ...
@@ -1,11 +1,9 @@
1 1
 #!/bin/bash
2 2
 # Stop the radmon agent process and clean up environment.
3 3
 
4
-if [ `hostname` == "raspi2" ]; then
5
-  AGENT_NAME="[a]rednsigAgent.py"
6
-else
7
-  AGENT_NAME="[a]rednsigMirrorAgent.py"
8
-fi
4
+
5
+AGENT_NAME="[a]rednsigAgent.py"
6
+#AGENT_NAME="[a]rednsigMirrorAgent.py"
9 7
 
10 8
 PROCESS_ID="$(ps x | awk -v a=$AGENT_NAME '$7 ~ a {print $1}')"
11 9
 
... ...
@@ -11,7 +11,7 @@
11 11
 #     - conversion of data items
12 12
 #     - update a round robin (rrdtool) database with the node data
13 13
 #     - periodically generate graphic charts for display in html documents
14
-#     - write the processed radmon data to a JSON file for use by html
14
+#     - write the processed node status to a JSON file for use by html
15 15
 #       documents
16 16
 #
17 17
 # Copyright 2020 Jeff Owrey
... ...
@@ -47,7 +47,8 @@ _USER = os.environ['USER']
47 47
    ### DEFAULT AREDN NODE URL ###
48 48
 
49 49
 # ip address of the aredn node
50
-_DEFAULT_AREDN_NODE_URL = "http://192.168.1.30/cgi-bin/signal.json"
50
+#_DEFAULT_AREDN_NODE_URL = "http://localnode:8080/cgi-bin/signal.json"
51
+_DEFAULT_AREDN_NODE_URL = "http://192.168.1.30:8080/cgi-bin/signal.json"
51 52
 
52 53
     ### FILE AND FOLDER LOCATIONS ###
53 54
 
... ...
@@ -59,7 +60,7 @@ _CHARTS_DIRECTORY = _DOCROOT_PATH + "dynamic/"
59 60
 _OUTPUT_DATA_FILE = _DOCROOT_PATH + "dynamic/arednsigOutputData.js"
60 61
 # dummy output data file
61 62
 _DUMMY_OUTPUT_FILE = _DOCROOT_PATH + "dynamic/nodeOnline.js"
62
-# database that stores radmon data
63
+# database that stores node data
63 64
 _RRD_FILE = "/home/%s/database/arednsigData.rrd" % _USER
64 65
 
65 66
     ### GLOBAL CONSTANTS ###
... ...
@@ -74,8 +75,9 @@ _HTTP_REQUEST_TIMEOUT = 10
74 75
 _CHART_WIDTH = 600
75 76
 # standard chart height in pixels
76 77
 _CHART_HEIGHT = 150
77
-# source of time stamp attached to output data file
78
-_USE_NODE_TIMESTAMP = True
78
+# Set this to True only if this server is intended to relay raw
79
+# node data to a mirror server.
80
+_RELAY_SERVER = False
79 81
 
80 82
    ### GLOBAL VARIABLES ###
81 83
 
... ...
@@ -91,8 +93,6 @@ failedUpdateCount = 0
91 93
 # detected status of aredn node device
92 94
 nodeOnline = True
93 95
 
94
-# status of reset command to aredn node
95
-remoteDeviceReset = False
96 96
 # ip address of aredn node
97 97
 arednNodeUrl = _DEFAULT_AREDN_NODE_URL
98 98
 # frequency of data requests to aredn node
... ...
@@ -322,9 +322,6 @@ def writeOutputDataFile(sData, ldData):
322 322
                    to the output data file
323 323
        Returns: True if successful, False otherwise
324 324
     """
325
-    if verboseDebug:
326
-        print "write output data file: %d bytes" % len(sData)
327
-
328 325
     # Write file for use by html clients.  The following two
329 326
     # data items are sent to the client file.
330 327
     #    * The last database update date and time
... ...
@@ -338,18 +335,22 @@ def writeOutputDataFile(sData, ldData):
338 335
         fc.write(sDate)
339 336
         fc.close()
340 337
     except Exception, exError:
341
-        print "%s write output file failed: %s" % (getTimeStamp(), exError)
338
+        print "%s write node file failed: %s" % (getTimeStamp(), exError)
342 339
         return False
343
-    return True
344 340
 
345
-    # Write the entire node data response to the output data file.
346
-    try:
347
-        fc = open(_OUTPUT_DATA_FILE, "w")
348
-        fc.write(sData)
349
-        fc.close()
350
-    except Exception, exError:
351
-        print "%s write output file failed: %s" % (getTimeStamp(), exError)
352
-        return False
341
+    if _RELAY_SERVER:
342
+        # Write the entire node data response to the output data file.
343
+        try:
344
+            fc = open(_OUTPUT_DATA_FILE, "w")
345
+            fc.write(sData)
346
+            fc.close()
347
+        except Exception, exError:
348
+            print "%s write output file failed: %s" % \
349
+                  (getTimeStamp(), exError)
350
+            return False
351
+        if verboseDebug:
352
+            print "write output data file: %d bytes" % len(sData)
353
+
353 354
     return True
354 355
 ## end def
355 356
 
... ...
@@ -384,7 +385,7 @@ def setNodeStatus(updateSuccess):
384 385
 
385 386
 def createGraph(fileName, dataItem, gLabel, gTitle, gStart,
386 387
                 lower, upper, addTrend, autoScale):
387
-    """Uses rrdtool to create a graph of specified radmon data item.
388
+    """Uses rrdtool to create a graph of specified node data item.
388 389
        Parameters:
389 390
            fileName - name of file containing the graph
390 391
            dataItem - data item to be graphed
... ...
@@ -436,7 +437,7 @@ def createGraph(fileName, dataItem, gLabel, gTitle, gStart,
436 437
                   % trendWindow[gStart]
437 438
      
438 439
     if verboseDebug:
439
-        print "\n%s" % strCmd # DEBUG
440
+        print "%s" % strCmd # DEBUG
440 441
     
441 442
     # Run the formatted rrdtool command as a subprocess.
442 443
     try:
... ...
@@ -448,7 +449,7 @@ def createGraph(fileName, dataItem, gLabel, gTitle, gStart,
448 449
         return False
449 450
 
450 451
     if debugOption:
451
-        print "rrdtool graph: %s" % result,
452
+        print "rrdtool graph: %s\n" % result,
452 453
     return True
453 454
 
454 455
 ##end def
... ...
@@ -460,50 +461,88 @@ def generateGraphs():
460 461
     """
461 462
     autoScale = False
462 463
 
464
+    # The following will force creation of charts
465
+    # of only signal strength and S/N charts.  Note that the following
466
+    # data items appear constant and do not show variation with time:
467
+    # noise level, rx mcs, rx rate, tx mcs, tx rate.  Therefore, until
468
+    # these parameters are demonstrated to vary in time, there is no point
469
+    # in creating the charts for these data items.
470
+    createAllCharts = False
471
+
472
+    # 24 hour stock charts
473
+
463 474
     createGraph('24hr_signal', 'S', 'dBm', 
464 475
                 'RSSI\ -\ Last\ 24\ Hours', 'end-1day', 0, 0, 2, autoScale)
465
-    createGraph('24hr_noise', 'N', 'dBm', 
466
-                'Noise\ -\ Last\ 24\ Hours', 'end-1day', 0, 0, 2, autoScale)
467 476
     createGraph('24hr_snr', 'SNR', 'dB', 
468 477
                 'SNR\ -\ Last\ 24\ Hours', 'end-1day', 0, 0, 2, autoScale)
469
-    createGraph('24hr_rx_rate', 'RX_RATE', 'Mbps',
470
-                'Rx\ Rate\ -\ Last\ 24\ Hours', 'end-1day', 0, 0, 2, autoScale)
471
-    createGraph('24hr_tx_rate', 'TX_RATE', 'Mbps',
472
-                'Tx\ Rate\ -\ Last\ 24\ Hours', 'end-1day', 0, 0, 2, autoScale)
473
-    #createGraph('24hr_rx_mcs', 'RX_MCS', 'Index',
474
-    #            'Rx\ MCS\ -\ Last\ 24\ Hours', 'end-1day', 0, 0, 2, autoScale)
475
-    #createGraph('24hr_tx_mcs', 'TX_MCS', 'Index',
476
-    #            'Tx\ MCS\ -\ Last\ 24\ Hours', 'end-1day', 0, 0, 2, autoScale)
478
+
479
+    if createAllCharts:
480
+        createGraph('24hr_noise', 'N', 'dBm', 
481
+                    'Noise\ -\ Last\ 24\ Hours', 'end-1day', 0, 0, 2,
482
+                    autoScale)
483
+        createGraph('24hr_rx_rate', 'RX_RATE', 'Mbps',
484
+                    'Rx\ Rate\ -\ Last\ 24\ Hours', 'end-1day', 0, 0, 2,
485
+                    autoScale)
486
+        createGraph('24hr_tx_rate', 'TX_RATE', 'Mbps',
487
+                    'Tx\ Rate\ -\ Last\ 24\ Hours', 'end-1day', 0, 0, 2,
488
+                    autoScale)
489
+        createGraph('24hr_rx_mcs', 'RX_MCS', 'Index',
490
+                    'Rx\ MCS\ -\ Last\ 24\ Hours', 'end-1day', 0, 0, 2,
491
+                     autoScale)
492
+        createGraph('24hr_tx_mcs', 'TX_MCS', 'Index',
493
+                    'Tx\ MCS\ -\ Last\ 24\ Hours', 'end-1day', 0, 0, 2,
494
+                     autoScale)
495
+
496
+    # 4 week stock charts
477 497
 
478 498
     createGraph('4wk_signal', 'S', 'dBm', 
479 499
                 'RSSI\ -\ Last\ 4\ Weeks', 'end-4weeks', 0, 0, 2, autoScale)
480
-    createGraph('4wk_noise', 'N', 'dBm', 
481
-                'Noise\ -\ Last\ 4\ Weeks', 'end-4weeks', 0, 0, 2, autoScale)
482 500
     createGraph('4wk_snr', 'SNR', 'dB', 
483 501
                 'SNR\ -\ Last\ 4\ Weeks', 'end-4weeks', 0, 0, 2, autoScale)
484
-    createGraph('4wk_rx_rate', 'RX_RATE', 'Mbps',
485
-                'Rx\ Rate\ -\ Last\ 4\ Weeks', 'end-4weeks', 0, 0, 2, autoScale)
486
-    createGraph('4wk_tx_rate', 'TX_RATE', 'Mbps',
487
-                'Tx\ Rate\ -\ Last\ 4\ Weeks', 'end-4weeks', 0, 0, 2, autoScale)
488
-    #createGraph('4wk_rx_mcs', 'RX_MCS', 'Index',
489
-    #            'Rx\ MCS\ -\ Last\ 4\ Weeks', 'end-4weeks', 0, 0, 2, autoScale)
490
-    #createGraph('4wk_tx_mcs', 'TX_MCS', 'Index',
491
-    #            'Tx\ MCS\ -\ Last\ 4\ Weeks', 'end-4weeks', 0, 0, 2, autoScale)
502
+
503
+    if createAllCharts:
504
+        createGraph('4wk_noise', 'N', 'dBm', 
505
+                    'Noise\ -\ Last\ 4\ Weeks', 'end-4weeks', 0, 0, 2,
506
+                    autoScale)
507
+        createGraph('4wk_rx_rate', 'RX_RATE', 'Mbps',
508
+                    'Rx\ Rate\ -\ Last\ 4\ Weeks', 'end-4weeks', 0, 0, 2,
509
+                    autoScale)
510
+        createGraph('4wk_tx_rate', 'TX_RATE', 'Mbps',
511
+                    'Tx\ Rate\ -\ Last\ 4\ Weeks', 'end-4weeks', 0, 0, 2,
512
+                    autoScale)
513
+        createGraph('4wk_rx_mcs', 'RX_MCS', 'Index',
514
+                    'Rx\ MCS\ -\ Last\ 4\ Weeks', 'end-4weeks', 0, 0, 2,
515
+                    autoScale)
516
+        createGraph('4wk_tx_mcs', 'TX_MCS', 'Index',
517
+                    'Tx\ MCS\ -\ Last\ 4\ Weeks', 'end-4weeks', 0, 0, 2,
518
+                    autoScale)
519
+
520
+    # 12 month stock charts
492 521
 
493 522
     createGraph('12m_signal', 'S', 'dBm', 
494 523
                 'RSSI\ -\ Past\ Year', 'end-12months', 0, 0, 2, autoScale)
495
-    createGraph('12m_noise', 'N', 'dBm', 
496
-                'Noise\ -\ Past\ Year', 'end-12months', 0, 0, 2, autoScale)
497 524
     createGraph('12m_snr', 'SNR', 'dB', 
498 525
                 'SNR\ -\ Past\ Year', 'end-12months', 0, 0, 2, autoScale)
499
-    createGraph('12m_rx_rate', 'RX_RATE', 'Mbps',
500
-                'Rx\ Rate\ -\ Past\ Year', 'end-12months', 0, 0, 2, autoScale)
501
-    createGraph('12m_tx_rate', 'TX_RATE', 'Mbps',
502
-                'Tx\ Rate\ -\ Past\ Year', 'end-12months', 0, 0, 2, autoScale)
503
-    #createGraph('12m_rx_mcs', 'RX_MCS', 'Index',
504
-    #            'Rx\ MCS\ -\ Past\ Year', 'end-12months', 0, 0, 2, autoScale)
505
-    #createGraph('12m_tx_mcs', 'TX_MCS', 'Index',
506
-    #            'Tx\ MCS\ -\ Past\ Year', 'end-12months', 0, 0, 2, autoScale)
526
+
527
+    if createAllCharts:
528
+        createGraph('12m_noise', 'N', 'dBm', 
529
+                    'Noise\ -\ Past\ Year', 'end-12months', 0, 0, 2,
530
+                    autoScale)
531
+        createGraph('12m_rx_rate', 'RX_RATE', 'Mbps',
532
+                    'Rx\ Rate\ -\ Past\ Year', 'end-12months', 0, 0, 2,
533
+                    autoScale)
534
+        createGraph('12m_tx_rate', 'TX_RATE', 'Mbps',
535
+                    'Tx\ Rate\ -\ Past\ Year', 'end-12months', 0, 0, 2,
536
+                    autoScale)
537
+        createGraph('12m_rx_mcs', 'RX_MCS', 'Index',
538
+                    'Rx\ MCS\ -\ Past\ Year', 'end-12months', 0, 0, 2,
539
+                    autoScale)
540
+        createGraph('12m_tx_mcs', 'TX_MCS', 'Index',
541
+                    'Tx\ MCS\ -\ Past\ Year', 'end-12months', 0, 0, 2,
542
+                    autoScale)
543
+    if debugOption:
544
+        #print # print a blank line to improve readability when in debug mode
545
+        pass
507 546
 ##end def
508 547
 
509 548
 def getCLarguments():
... ...
@@ -536,7 +575,7 @@ def getCLarguments():
536 575
             index += 1
537 576
         else:
538 577
             cmd_name = sys.argv[0].split('/')
539
-            print "Usage: %s [-d] [-v] [-pt seconds] [-u url}" % cmd_name[-1]
578
+            print "Usage: %s [-d] [-v] [-p seconds] [-u url]" % cmd_name[-1]
540 579
             exit(-1)
541 580
         index += 1
542 581
 ##end def
... ...
@@ -566,12 +605,12 @@ def main():
566 605
 
567 606
     requestIntervalSeconds = dataRequestInterval * 60 # convert to seconds
568 607
 
569
-    chartUpdateInterval = dataRequestInterval # get charts when updating database
608
+    chartUpdateInterval = dataRequestInterval # get charts interval
570 609
 
571 610
     ## Exit with error if rrdtool database does not exist.
572 611
     if not os.path.exists(_RRD_FILE):
573 612
         print 'rrdtool database does not exist\n' \
574
-              'use createRadmonRrd script to ' \
613
+              'use createArednsigRrd script to ' \
575 614
               'create rrdtool database\n'
576 615
         exit(1)
577 616
  
... ...
@@ -630,7 +669,7 @@ def main():
630 669
             if result:
631 670
                 print "%s update successful:" % getTimeStamp(),
632 671
             else:
633
-               print "%s update failed:" % getTimeStamp(),
672
+                print "%s update failed:" % getTimeStamp(),
634 673
             print "%6f seconds processing time\n" % elapsedTime 
635 674
         remainingTime = requestIntervalSeconds - elapsedTime
636 675
         if remainingTime > 0.0:
637 676
new file mode 100755
... ...
@@ -0,0 +1,16 @@
1
+#!/bin/sh
2
+#
3
+# Create a directory in the temporary file system for arednsig dynamic
4
+# data.  Set ownership and permissions to allow the Apache www-data user
5
+# read and write access to this folder.
6
+mkdir /tmp/arednsig
7
+sudo chown :www-data /tmp/arednsig
8
+chmod g+w /tmp/arednsig
9
+
10
+# Uncomment the following line if you choose to mount the dynamic
11
+# folder to the folder created above.
12
+#sudo mount --bind /tmp/arednsig  /home/pi/public_html/arednsig/dynamic
13
+
14
+# Start arednsig agent
15
+(sleep 5; /home/pi/bin/ardstart;) &
16
+
0 17
deleted file mode 120000
... ...
@@ -1 +0,0 @@
1
-/tmp/arednsig
2 0
\ No newline at end of file