Browse code

2017-12-2 minor update

fractalxaos authored on 12/02/2017 23:59:08
Showing 3 changed files
1 1
old mode 100755
2 2
new mode 100644
... ...
@@ -34,7 +34,7 @@
34 34
 #   * v21 released 27 Nov 2017 by J L Owrey; bug fixes; updates
35 35
 #
36 36
 
37
-_MIRROR_SERVER = True
37
+_MIRROR_SERVER = False
38 38
 
39 39
 import os
40 40
 import urllib2
... ...
@@ -48,24 +48,24 @@ _USER = os.environ['USER']
48 48
 
49 49
    ### DEFAULT WEATHER STATION URL ###
50 50
 
51
-if _MIRROR_SERVER:
52
-    _DEFAULT_RADIATION_MONITOR_URL = \
53
-        "http://73.157.139.23:7361/~pi/radmon/dynamic/rad.dat"
54
-else:
55
-    _DEFAULT_RADIATION_MONITOR_URL = "http://192.168.1.8"
51
+# ip address of radiation monitoring device
52
+_RADIATION_MONITOR_URL = "http://YOUR_RADIATION_MONITOR_IP_ADDRESS"
53
+# url if this is a mirror server
54
+_PRIMARY_SERVER_URL = \
55
+    "http://YOUR_PRIMARY_SERVER/USER/radmon/dynamic/radmonInputData.dat"
56 56
 
57 57
     ### FILE AND FOLDER LOCATIONS ###
58 58
 
59 59
 # folder for containing dynamic data objects
60
-_DYNAMIC_FOLDER_PATH = "/home/%s/public_html/radmon/dynamic/" % _USER
60
+_DOCROOT_PATH = "/home/%s/public_html/radmon/" % _USER
61 61
 # folder for charts and output data file
62
-_CHARTS_DIRECTORY = _DYNAMIC_FOLDER_PATH
62
+_CHARTS_DIRECTORY = _DOCROOT_PATH + "dynamic/"
63 63
  # database that stores weather data
64 64
 _RRD_FILE = "/home/%s/database/radmonData.rrd" % _USER
65
+# location of data input file
66
+INPUT_DATA_FILE = _DOCROOT_PATH + "dynamic/radmonInputData.dat"
65 67
 # location of data output file
66
-_OUTPUT_DATA_FILE = _DYNAMIC_FOLDER_PATH + "radmonData.js"
67
-# location of data forwarding file
68
-_DATA_FORWARDING_FILE = _DYNAMIC_FOLDER_PATH + "rad.dat"
68
+_OUTPUT_DATA_FILE = _DOCROOT_PATH + "dynamic/radmonOutputData.js"
69 69
 
70 70
     ### GLOBAL CONSTANTS ###
71 71
 # interval in seconds between data requests to radiation monitor
... ...
@@ -92,11 +92,10 @@ radiationMonitorOnline = True
92 92
 radiationMonitorOfflineCount = 0
93 93
 # status of reset command to radiation monitor
94 94
 remoteDeviceReset = False
95
+# ip address of radiation monitor
96
+radiationMonitorUrl = _RADIATION_MONITOR_URL
95 97
 # web update frequency
96 98
 dataRequestInterval = _DEFAULT_DATA_REQUEST_INTERVAL
97
-# radiation monitor network address
98
-radiationMonitorUrl = _DEFAULT_RADIATION_MONITOR_URL
99
-
100 99
 
101 100
   ###  PRIVATE METHODS  ###
102 101
 
... ...
@@ -127,8 +126,8 @@ def setOfflineStatus(dData):
127 126
     # that we are now offline.
128 127
     if radiationMonitorOnline:
129 128
         print "%s: radiation monitor offline" % getTimeStamp()
130
-        if os.path.exists(_DATA_FORWARDING_FILE):
131
-            os.remove(_DATA_FORWARDING_FILE)
129
+        if os.path.exists(INPUT_DATA_FILE):
130
+            os.remove(INPUT_DATA_FILE)
132 131
         radiationMonitorOnline = False
133 132
 
134 133
     for key in dData:
... ...
@@ -156,14 +155,12 @@ def getRadiationData():
156 155
     global radiationMonitorOnline, radiationMonitorOfflineCount, \
157 156
            remoteDeviceReset
158 157
 
159
-    sUrl = radiationMonitorUrl
160
-
161
-    if not _MIRROR_SERVER:
162
-        if remoteDeviceReset:
163
-            sUrl += "/reset"
164
-            remoteDeviceReset = False
165
-        else:
166
-            sUrl += "/rdata"
158
+    if _MIRROR_SERVER:
159
+        sUrl = _PRIMARY_SERVER_URL
160
+    elif remoteDeviceReset:
161
+        sUrl = radiationMonitorUrl + "/reset"
162
+    else:
163
+        sUrl = radiationMonitorUrl + "/rdata"
167 164
 
168 165
     try:
169 166
         conn = urllib2.urlopen(sUrl, timeout=_HTTP_REQUEST_TIMEOUT)
... ...
@@ -190,10 +187,7 @@ def getRadiationData():
190 187
         print "%s radiation monitor online" % getTimeStamp()
191 188
         radiationMonitorOnline = True
192 189
 
193
-    if debugOption:
194
-        #print content
195
-        pass
196
-
190
+    #print content
197 191
     return content
198 192
 ##end def
199 193
 
... ...
@@ -218,6 +212,11 @@ def parseDataString(sData, dData):
218 212
             dData[item.split('=')[0]] = item.split('=')[1]
219 213
     dData['status'] = 'online'
220 214
 
215
+    if len(dData) != 6:
216
+        print "%s parse failed: corrupted data string: %s" % \
217
+               (getTimeStamp(), sData)
218
+        return False;
219
+
221 220
     return True
222 221
 ##end def
223 222
 
... ...
@@ -289,10 +288,11 @@ def writeOutputDataFile(dData):
289 288
     return True
290 289
 ## end def
291 290
 
292
-def writeForwardingFile(sData):
291
+def writeInputDataFile(sData):
293 292
     # Write the string to the output data file for use by html documents.
293
+    sData += "\n"
294 294
     try:
295
-        fc = open(_DATA_FORWARDING_FILE, "w")
295
+        fc = open(INPUT_DATA_FILE, "w")
296 296
         fc.write(sData)
297 297
         fc.close()
298 298
     except Exception, exError:
... ...
@@ -515,7 +515,7 @@ def main():
515 515
 
516 516
             # If conversion successful, write data to output file.
517 517
             if result:
518
-                writeForwardingFile(sData)
518
+                writeInputDataFile(sData)
519 519
                 writeOutputDataFile(dData)
520 520
                 if debugOption:
521 521
                     print "http request successful"
... ...
@@ -1,5 +1,6 @@
1
+<!DOCTYPE html>
1 2
 <html>
2 3
 <head>
3
-  <meta http-equiv="refresh" content="0; url=radmon.html">
4
+  <meta http-equiv="refresh" content="0; url=./radmon.html">
4 5
 </head>
5 6
 </html>
... ...
@@ -82,7 +82,9 @@ text.chartNav {
82 82
 
83 83
 <div class="mainContainer">
84 84
 
85
-<h2>DIY Radiation Monitor</h2>
85
+<h2><a href="https://github.com/fractalxaos/radmon" 
86
+style="text-decoration:none" target="_new">
87
+DIY Radiation Monitor</a></h2>
86 88
 <h4>Albany, Oregon</h4>
87 89
 
88 90
 <div class="datetime">
... ...
@@ -109,7 +111,7 @@ uSv per hour:
109 111
 <div class="currentDataCell">
110 112
 <ins>Radiation Monitor</ins><br><br>
111 113
 <div class="dataItems">
112
-Device:<br>
114
+Status:<br>
113 115
 Mode:
114 116
 </div>
115 117
 <div class="dataItems">
... ...
@@ -122,9 +124,12 @@ Mode:
122 124
 <span class="chartNav">
123 125
 <ul class="chartNav">
124 126
 <li class="chartNav">Select charts:</li>
125
-<li class="chartNav"><text class="chartNav" onclick="show_charts(1)">24 hours</text></li>
126
-<li class="chartNav"><text class="chartNav" onclick="show_charts(2)">4 weeks</text></li>
127
-<li class="chartNav"><text class="chartNav" onclick="show_charts(3)">12 months</text></li>
127
+<li class="chartNav"><text class="chartNav" onclick="show_charts(1)">
128
+24 hours</text></li>
129
+<li class="chartNav"><text class="chartNav" onclick="show_charts(2)">
130
+4 weeks</text></li>
131
+<li class="chartNav"><text class="chartNav" onclick="show_charts(3)">
132
+12 months</text></li>
128 133
 </ul>
129 134
 </span>
130 135
 <br>
... ...
@@ -141,11 +146,13 @@ Mode:
141 146
 <b>NOTES:</b>
142 147
 <ul>
143 148
 <li>DIY Radiation Monitor project plans and software available at
144
-<a href="https://github.com/fractalxaos/radmon" target="_new"><i>Github.com</i></a>.</li>
145
-<li>Project sponsored by <a href="http://www.eugenemakerspace.com" TARGET="_NEW">
149
+<a href="https://github.com/fractalxaos/radmon" target="_new">
150
+<i>Github.com</i></a>.</li>
151
+<li>Project sponsored by 
152
+<a href="http://www.eugenemakerspace.com" TARGET="_NEW">
146 153
 <i>Eugene Maker Space</i></a>, Eugene, Oregon.</li>
147
-<li>For more information about the effects of radiation on the human body see
148
-<a href="https://xkcd.com/radiation/" target="_blank">
154
+<li>For more information about the effects of radiation on the human body
155
+see <a href="https://xkcd.com/radiation/" target="_blank">
149 156
 Radiation Dose Chart</a> by Randall Monroe.</li>
150 157
 </ul>
151 158
 </div>
... ...
@@ -155,7 +162,7 @@ Radiation Dose Chart</a> by Randall Monroe.</li>
155 162
 <script>
156 163
 
157 164
 /* Globals */
158
-var radmonDataUrl = "dynamic/radmonData.js";
165
+var radmonDataUrl = "dynamic/radmonOutputData.js";
159 166
 var httpRequest = new XMLHttpRequest();
160 167
 var graphPeriod;
161 168
 
... ...
@@ -175,7 +182,7 @@ var status_e = document.getElementById("status");
175 182
 function main() {
176 183
     getRadmonData();
177 184
     show_charts(1);
178
-    setInterval(getRadmonData, 10000);
185
+    setInterval(getRadmonData, 5000);
179 186
 }
180 187
 
181 188
 function getRadmonData() {
... ...
@@ -226,7 +233,8 @@ function displayData(dataItem) {
226 233
     localTimeZone = localDateObj.getTimezoneOffset() / 60;
227 234
     
228 235
     date_e.innerHTML = date;    
229
-    time_e.innerHTML = hourminute + "  <small>(GMT+" + localTimeZone + ")</small>";    
236
+    time_e.innerHTML = hourminute +
237
+        "  <small>(GMT+" + localTimeZone + ")</small>";    
230 238
     cpm_e.innerHTML = dataItem.CPM;    
231 239
     cps_e.innerHTML = dataItem.CPS;    
232 240
     uSvPerHr_e.innerHTML = dataItem.uSvPerHr;