Browse code

revisions 2018-07-23

fractalxaos authored on 07/23/2018 21:17:50
Showing 3 changed files
1 1
Binary files a/DIY Radmon Project Description.pdf and b/DIY Radmon Project Description.pdf differ
2 2
old mode 100644
3 3
new mode 100755
... ...
@@ -40,7 +40,8 @@ _MIRROR_SERVER = False
40 40
 
41 41
 import os
42 42
 import urllib2
43
-import sys   
43
+import sys
44
+import signal
44 45
 import subprocess
45 46
 import multiprocessing
46 47
 import time
... ...
@@ -69,6 +70,8 @@ _OUTPUT_DATA_FILE = _DOCROOT_PATH + "dynamic/radmonOutputData.js"
69 70
 _RRD_FILE = "/home/%s/database/radmonData.rrd" % _USER
70 71
 
71 72
     ### GLOBAL CONSTANTS ###
73
+# max number of failed data requests allowed
74
+_MAX_FAILED_DATA_REQUESTS = 2
72 75
 # interval in seconds between data requests to radiation monitor
73 76
 _DEFAULT_DATA_REQUEST_INTERVAL = 5
74 77
 # defines how often the charts get updated in seconds
... ...
@@ -77,10 +80,9 @@ _CHART_UPDATE_INTERVAL = 300
77 80
 _DATABASE_UPDATE_INTERVAL = 30
78 81
 # number seconds to wait for a response to HTTP request
79 82
 _HTTP_REQUEST_TIMEOUT = 3
80
-# max number of failed data requests allowed
81
-_MAX_FAILED_DATA_REQUESTS = 2
82
-# radmon chart dimensions
83
+# standard chart width in pixels
83 84
 _CHART_WIDTH = 600
85
+# standard chart height in pixels
84 86
 _CHART_HEIGHT = 150
85 87
 
86 88
    ### GLOBAL VARIABLES ###
... ...
@@ -135,6 +137,20 @@ def setOfflineStatus(dData):
135 137
     return
136 138
 ##end def
137 139
 
140
+def signal_term_handler(signal, frame):
141
+    """Send message to log when process killed
142
+       Parameters: signal, frame - sigint parameters
143
+       Returns: nothing
144
+    """
145
+    print '%s terminating radmon agent process' % \
146
+              (getTimeStamp())
147
+    if os.path.exists(_OUTPUT_DATA_FILE):
148
+        os.remove(_OUTPUT_DATA_FILE)
149
+    if os.path.exists(_INPUT_DATA_FILE):
150
+        os.remove(_INPUT_DATA_FILE)
151
+    sys.exit(0)
152
+##end def
153
+
138 154
   ###  PUBLIC METHODS  ###
139 155
 
140 156
 def getRadiationData():
... ...
@@ -267,9 +283,9 @@ def writeOutputDataFile(dData):
267 283
     # Format the weather data as string using java script object notation.
268 284
     sData = '[{'
269 285
     sData += "\"date\":\"%s\"," % dData['date']
270
-    sData += "\"CPM\":\"%s\"," % dData['CPM']
271
-    sData += "\"CPS\":\"%s\"," % dData['CPS']
272
-    sData += "\"uSvPerHr\":\"%s\"," % dData['uSvPerHr']
286
+    sData += "\"CPM\":\"%d\"," % dData['CPM']
287
+    sData += "\"CPS\":\"%d\"," % dData['CPS']
288
+    sData += "\"uSvPerHr\":\"%.2f\"," % dData['uSvPerHr']
273 289
     sData += "\"Mode\":\"%s\"," % dData['Mode']
274 290
     sData += "\"status\":\"%s\"," % dData['status']
275 291
     sData = sData[:-1] + '}]\n'
... ...
@@ -470,6 +486,10 @@ def main():
470 486
        Parameters: none
471 487
        Returns nothing.
472 488
     """
489
+    signal.signal(signal.SIGTERM, signal_term_handler)
490
+
491
+    print '%s starting up radmon agent process' % \
492
+                  (getTimeStamp())
473 493
 
474 494
     # last time output JSON file updated
475 495
     lastDataRequestTime = -1
... ...
@@ -483,8 +503,9 @@ def main():
483 503
 
484 504
     ## Exit with error if rrdtool database does not exist.
485 505
     if not os.path.exists(_RRD_FILE):
486
-        print "cannot find rrdtool database\nuse createWeatherRrd script to" \
487
-              " create rrdtool database\n"
506
+        print 'rrdtool database does not exist\n' \
507
+              'use createWeatherRrd script to ' \
508
+              'create rrdtool database\n'
488 509
         exit(1)
489 510
  
490 511
     ## main loop
... ...
@@ -550,7 +571,8 @@ if __name__ == '__main__':
550 571
     try:
551 572
         main()
552 573
     except KeyboardInterrupt:
553
-        print '\nInterrupted'
574
+        print '\n%s terminating radmon agent process' % \
575
+              (getTimeStamp())
554 576
         if os.path.exists(_OUTPUT_DATA_FILE):
555 577
             os.remove(_OUTPUT_DATA_FILE)
556 578
         if os.path.exists(_INPUT_DATA_FILE):
557 579
old mode 100644
558 580
new mode 100755
... ...
@@ -1,5 +1,10 @@
1 1
 #!/bin/bash
2 2
 #
3
+# The monitor url can look something like http://192.168.1.155, or
4
+# something linke http://radiationMonitor.domain.com depending on
5
+# whether your local network uses a domain name server.
6
+#
7
+MONITOR_URL="{your monitor url}"
3 8
 
4 9
 APP_PATH="/home/$USER/bin"
5 10
 LOG_PATH="/home/$USER/log"
... ...
@@ -13,5 +18,5 @@ if [ -n "$PROCESS_ID" ]; then
13 18
 else
14 19
   printf "starting up radmon agent\n"
15 20
   cd $APP_PATH
16
-  ./radmonAgent.py -t 10 -u 'http://73.157.139.23:4371' >> $LOG_PATH/radmonAgent.log 2>&1 &
21
+  ./radmonAgent.py -t 10 -u $MONITOR_URL >> $LOG_PATH/radmonAgent.log 2>&1 &
17 22
 fi