diff --git a/bin/radmonAgent.py b/bin/radmonAgent.py old mode 100755 new mode 100644 index 3bfbff1..17518f8 --- a/bin/radmonAgent.py +++ b/bin/radmonAgent.py @@ -1,6 +1,6 @@ #!/usr/bin/python -u -## The -u option above turns off block buffering of python output. This -## assures that each error message gets individually printed to the log file. +# The -u option above turns off block buffering of python output. This +# assures that each error message gets individually printed to the log file. # # Module: radmonAgent.py # @@ -48,12 +48,12 @@ _USER = os.environ['USER'] - ### DEFAULT WEATHER STATION URL ### + ### DEFAULT RADIATION MONITOR URL ### # ip address of radiation monitoring device -_DEFAULT_RADIATION_MONITOR_URL = '{your radmon device url}' +_DEFAULT_RADIATION_MONITOR_URL = "{your radiation device url}" # url if this is a mirror server -_PRIMARY_SERVER_URL = '{your primary server weather data url}' +_PRIMARY_SERVER_URL = "{your primary server radiation data url}" ### FILE AND FOLDER LOCATIONS ### @@ -61,12 +61,12 @@ _DOCROOT_PATH = "/home/%s/public_html/radmon/" % _USER # folder for charts and output data file _CHARTS_DIRECTORY = _DOCROOT_PATH + "dynamic/" - # database that stores weather data -_RRD_FILE = "/home/%s/database/radmonData.rrd" % _USER # location of data input file _INPUT_DATA_FILE = _DOCROOT_PATH + "dynamic/radmonInputData.dat" # location of data output file _OUTPUT_DATA_FILE = _DOCROOT_PATH + "dynamic/radmonOutputData.js" +# database that stores weather data +_RRD_FILE = "/home/%s/database/radmonData.rrd" % _USER ### GLOBAL CONSTANTS ### # interval in seconds between data requests to radiation monitor @@ -153,10 +153,12 @@ def getRadiationData(): if _MIRROR_SERVER: sUrl = _PRIMARY_SERVER_URL - elif remoteDeviceReset: - sUrl = radiationMonitorUrl + "/reset" else: - sUrl = radiationMonitorUrl + "/rdata" + sUrl = radiationMonitorUrl + if remoteDeviceReset: + sUrl += "/reset" + else: + sUrl += "/rdata" try: conn = urllib2.urlopen(sUrl, timeout=_HTTP_REQUEST_TIMEOUT) @@ -207,8 +209,7 @@ def parseDataString(sData, dData): dData['status'] = 'online' if len(dData) != 6: - print "%s parse failed: corrupted data string: %s" % \ - (getTimeStamp(), sData) + print "%s parse failed: corrupted data string" % getTimeStamp() return False; return True @@ -224,19 +225,18 @@ def convertData(dData): result = True try: - - # Uncomment below to use timestamp from radiation monitoring device - # otherwise the requesting server (this) will generate the - # timestamp. Allowing the server to generate the timestamp - # prevents timestamp errors due to the radiation monitoring device - # failing to synchronize with a NTP time server. - - #dData['UTC'] = time.time() - - ## Convert UTC from radiation monitoring device to local time. + # Convert the UTC timestamp provided by the radiation monitoring + # device to epoch local time in seconds. ts_utc = time.strptime(dData['UTC'], "%H:%M:%S %m/%d/%Y") - local_sec = calendar.timegm(ts_utc) - dData['UTC'] = local_sec + epoch_local_sec = calendar.timegm(ts_utc) + dData['ELT'] = epoch_local_sec + + # Uncomment the code line below to use a timestamp generated by the + # requesting server (this) instead of the timestamp provided by the + # radiation monitoring device. Using the server generated timestamp + # prevents errors that occur when the radiation monitoring device + # fails to synchronize with a valid NTP time server. + #dData['ELT'] = time.time() dData['Mode'] = dData['Mode'].lower() @@ -247,7 +247,7 @@ def convertData(dData): dData['CPS'] = int(dData.pop('CPS')) except Exception, exError: - print "%s convertData: %s" % (getTimeStamp(), exError) + print "%s convert data failed: %s" % (getTimeStamp(), exError) result = False return result @@ -262,13 +262,17 @@ def writeOutputDataFile(dData): Returns true if successful, false otherwise. """ # Set date to current time and data - dData['date'] = getTimeStamp() + dData['date'] = time.strftime("%m/%d/%Y %T", time.localtime(dData['ELT'])) # Format the weather data as string using java script object notation. sData = '[{' - for key in dData: - sData += "\"%s\":\"%s\"," % (key, dData[key]) - sData = sData[:-1] + '}]' + sData += "\"date\":\"%s\"," % dData['date'] + sData += "\"CPM\":\"%s\"," % dData['CPM'] + sData += "\"CPS\":\"%s\"," % dData['CPS'] + sData += "\"uSvPerHr\":\"%s\"," % dData['uSvPerHr'] + sData += "\"Mode\":\"%s\"," % dData['Mode'] + sData += "\"status\":\"%s\"," % dData['status'] + sData = sData[:-1] + '}]\n' # Write the string to the output data file for use by html documents. try: @@ -318,7 +322,7 @@ def updateDatabase(dData): # Create the rrdtool update command. strCmd = "rrdtool update %s %s:%s:%s" % \ - (_RRD_FILE, dData['UTC'], dData['CPM'], SvPerHr) + (_RRD_FILE, dData['ELT'], dData['CPM'], SvPerHr) if debugOption and False: print "%s" % strCmd # DEBUG