... | ... |
@@ -86,15 +86,13 @@ _AVERAGE_LINE_COLOR = '#006600' |
86 | 86 |
### GLOBAL VARIABLES ### |
87 | 87 |
|
88 | 88 |
# debug output options |
89 |
-debugOption = False |
|
90 |
-verboseDebug = False |
|
89 |
+debugMode = False |
|
90 |
+verboseMode = False |
|
91 | 91 |
|
92 | 92 |
# frequency of data requests to sensors |
93 | 93 |
dataRequestInterval = _DEFAULT_DATA_REQUEST_INTERVAL |
94 | 94 |
# how often charts get updated |
95 | 95 |
chartUpdateInterval = _CHART_UPDATE_INTERVAL |
96 |
-# last node request time |
|
97 |
-lastDataPointTime = -1 |
|
98 | 96 |
|
99 | 97 |
# Define each sensor. This also initialzes each sensor. |
100 | 98 |
pwr = ina260.ina260(_PWR_SENSOR_ADDR, _BUS_SEL) |
... | ... |
@@ -170,41 +168,6 @@ def getSensorData(dData): |
170 | 168 |
return True |
171 | 169 |
## end def |
172 | 170 |
|
173 |
-def updateDatabase(dData): |
|
174 |
- """ |
|
175 |
- Update the rrdtool database by executing an rrdtool system command. |
|
176 |
- Format the command using the data extracted from the sensors. |
|
177 |
- Parameters: dData - dictionary object containing data items to be |
|
178 |
- written to the rr database file |
|
179 |
- Returns: True if successful, False otherwise |
|
180 |
- """ |
|
181 |
- |
|
182 |
- epochTime = getEpochSeconds(dData['time']) |
|
183 |
- |
|
184 |
- # Format the rrdtool update command. |
|
185 |
- strFmt = "rrdtool update %s %s:%s:%s:%s:%s:%s" |
|
186 |
- strCmd = strFmt % (_RRD_FILE, epochTime, dData['current'], \ |
|
187 |
- dData['voltage'], dData['power'], dData['battemp'], \ |
|
188 |
- dData['ambtemp']) |
|
189 |
- |
|
190 |
- if verboseDebug: |
|
191 |
- print("%s" % strCmd) # DEBUG |
|
192 |
- |
|
193 |
- # Run the command as a subprocess. |
|
194 |
- try: |
|
195 |
- subprocess.check_output(strCmd, shell=True, \ |
|
196 |
- stderr=subprocess.STDOUT) |
|
197 |
- except subprocess.CalledProcessError as exError: |
|
198 |
- print("%s: rrdtool update failed: %s" % \ |
|
199 |
- (getTimeStamp(), exError.output)) |
|
200 |
- return False |
|
201 |
- |
|
202 |
- if debugOption and not verboseDebug: |
|
203 |
- print("database updated") |
|
204 |
- |
|
205 |
- return True |
|
206 |
-## end def |
|
207 |
- |
|
208 | 171 |
def writeOutputFile(dData): |
209 | 172 |
""" |
210 | 173 |
Write sensor data items to the output data file, formatted as |
... | ... |
@@ -222,8 +185,8 @@ def writeOutputFile(dData): |
222 | 185 |
# * The sensor values |
223 | 186 |
|
224 | 187 |
# Create a JSON formatted string from the sensor data. |
188 |
+ jsData = json.loads("{}") |
|
225 | 189 |
try: |
226 |
- jsData = json.loads("{}") |
|
227 | 190 |
for key in dData: |
228 | 191 |
jsData.update({key:dData[key]}) |
229 | 192 |
jsData.update({"chartUpdateInterval": chartUpdateInterval}) |
... | ... |
@@ -232,7 +195,7 @@ def writeOutputFile(dData): |
232 | 195 |
print("%s writeOutputFile: %s" % (getTimeStamp(), exError)) |
233 | 196 |
return False |
234 | 197 |
|
235 |
- if verboseDebug: |
|
198 |
+ if debugMode: |
|
236 | 199 |
print(sData) |
237 | 200 |
|
238 | 201 |
# Write the JSON formatted data to the output data file. |
... | ... |
@@ -249,6 +212,41 @@ def writeOutputFile(dData): |
249 | 212 |
return True |
250 | 213 |
## end def |
251 | 214 |
|
215 |
+def updateDatabase(dData): |
|
216 |
+ """ |
|
217 |
+ Update the rrdtool database by executing an rrdtool system command. |
|
218 |
+ Format the command using the data extracted from the sensors. |
|
219 |
+ Parameters: dData - dictionary object containing data items to be |
|
220 |
+ written to the rr database file |
|
221 |
+ Returns: True if successful, False otherwise |
|
222 |
+ """ |
|
223 |
+ |
|
224 |
+ epochTime = getEpochSeconds(dData['time']) |
|
225 |
+ |
|
226 |
+ # Format the rrdtool update command. |
|
227 |
+ strFmt = "rrdtool update %s %s:%s:%s:%s:%s:%s" |
|
228 |
+ strCmd = strFmt % (_RRD_FILE, epochTime, dData['current'], \ |
|
229 |
+ dData['voltage'], dData['power'], dData['battemp'], \ |
|
230 |
+ dData['ambtemp']) |
|
231 |
+ |
|
232 |
+ if debugMode: |
|
233 |
+ print("%s" % strCmd) # DEBUG |
|
234 |
+ |
|
235 |
+ # Run the command as a subprocess. |
|
236 |
+ try: |
|
237 |
+ subprocess.check_output(strCmd, shell=True, \ |
|
238 |
+ stderr=subprocess.STDOUT) |
|
239 |
+ except subprocess.CalledProcessError as exError: |
|
240 |
+ print("%s: rrdtool update failed: %s" % \ |
|
241 |
+ (getTimeStamp(), exError.output)) |
|
242 |
+ return False |
|
243 |
+ |
|
244 |
+ if verboseMode and not debugMode: |
|
245 |
+ print("database updated") |
|
246 |
+ |
|
247 |
+ return True |
|
248 |
+## end def |
|
249 |
+ |
|
252 | 250 |
def createGraph(fileName, dataItem, gLabel, gTitle, gStart, |
253 | 251 |
lower=0, upper=0, trendLine=0, scaleFactor=1, |
254 | 252 |
autoScale=True, alertLine=""): |
... | ... |
@@ -314,8 +312,8 @@ def createGraph(fileName, dataItem, gLabel, gTitle, gStart, |
314 | 312 |
if alertLine != "": |
315 | 313 |
strCmd += "HRULE:%s#FF0000:Critical\ Low\ Voltage " % (alertLine) |
316 | 314 |
|
317 |
- if verboseDebug: |
|
318 |
- print("%s" % strCmd) # DEBUG |
|
315 |
+ if debugMode: |
|
316 |
+ print("%s\n" % strCmd) # DEBUG |
|
319 | 317 |
|
320 | 318 |
# Run the formatted rrdtool command as a subprocess. |
321 | 319 |
try: |
... | ... |
@@ -326,7 +324,7 @@ def createGraph(fileName, dataItem, gLabel, gTitle, gStart, |
326 | 324 |
print("rrdtool graph failed: %s" % (exError.output)) |
327 | 325 |
return False |
328 | 326 |
|
329 |
- if debugOption: |
|
327 |
+ if verboseMode and not debugMode: |
|
330 | 328 |
print("rrdtool graph: %s" % result.decode('utf-8')) |
331 | 329 |
return True |
332 | 330 |
|
... | ... |
@@ -398,20 +396,20 @@ def getCLarguments(): |
398 | 396 |
""" |
399 | 397 |
Get command line arguments. There are three possible arguments |
400 | 398 |
-d turns on debug mode |
401 |
- -v turns on verbose debug mode |
|
399 |
+ -v turns on verbose mode |
|
402 | 400 |
-p sets the sensor query period |
403 | 401 |
-c sets the chart update period |
404 | 402 |
Returns: nothing |
405 | 403 |
""" |
406 |
- global debugOption, verboseDebug, dataRequestInterval, chartUpdateInterval |
|
404 |
+ global debugMode, verboseMode, dataRequestInterval, chartUpdateInterval |
|
407 | 405 |
|
408 | 406 |
index = 1 |
409 | 407 |
while index < len(sys.argv): |
410 |
- if sys.argv[index] == '-d': |
|
411 |
- debugOption = True |
|
412 |
- elif sys.argv[index] == '-v': |
|
413 |
- debugOption = True |
|
414 |
- verboseDebug = True |
|
408 |
+ if sys.argv[index] == '-v': |
|
409 |
+ verboseMode = True |
|
410 |
+ elif sys.argv[index] == '-d': |
|
411 |
+ debugMode = True |
|
412 |
+ verboseMode = True |
|
415 | 413 |
elif sys.argv[index] == '-p': |
416 | 414 |
try: |
417 | 415 |
dataRequestInterval = abs(int(sys.argv[index + 1])) |
... | ... |
@@ -475,7 +473,6 @@ def main(): |
475 | 473 |
if currentTime - lastDataRequestTime > dataRequestInterval: |
476 | 474 |
lastDataRequestTime = currentTime |
477 | 475 |
dData = {} |
478 |
- result = True |
|
479 | 476 |
|
480 | 477 |
# Get the data from the sensors. |
481 | 478 |
result =getSensorData(dData) |
... | ... |
@@ -501,7 +498,7 @@ def main(): |
501 | 498 |
# the next update interval. |
502 | 499 |
|
503 | 500 |
elapsedTime = time.time() - currentTime |
504 |
- if debugOption: |
|
501 |
+ if verboseMode: |
|
505 | 502 |
if result: |
506 | 503 |
print("update successful: %6f sec\n" |
507 | 504 |
% elapsedTime) |
... | ... |
@@ -16,7 +16,10 @@ if [ -n "$PROCESS_ID" ]; then |
16 | 16 |
else |
17 | 17 |
printf "starting up node agent\n" |
18 | 18 |
cd $APP_PATH |
19 |
- $(./$AGENT_NAME >> \ |
|
20 |
- $LOG_PATH/npwAgent.log 2>&1 &) |
|
19 |
+ if [ "$1" != "" ]; then |
|
20 |
+ ./$AGENT_NAME $1 |
|
21 |
+ else |
|
22 |
+ ./$AGENT_NAME >> $LOG_PATH/npwAgent.log 2>&1 & |
|
23 |
+ fi |
|
21 | 24 |
fi |
22 | 25 |
|
... | ... |
@@ -240,6 +240,10 @@ Status: |
240 | 240 |
<a href="https://github.com/fractalxaos/ham/tree/master/nodepower" target="_new"> |
241 | 241 |
<i>Github.com</i> |
242 | 242 |
</a>.</li> |
243 |
+<li>Project plans and software also available via the mesh |
|
244 |
+<a href="http://ka7jlo-web.local.mesh/file-manager/files/KA7JLO/Apps/nodepower/nodepower.zip" target="_new"> |
|
245 |
+<i>here</i> |
|
246 |
+</a>.</li> |
|
243 | 247 |
<li>Project plans include detailed instructions on how to use a Raspberry |
244 | 248 |
Pi Zero to add power bus and battery temperature monitoring |
245 | 249 |
for your AREDN node.</li> |