... | ... |
@@ -92,6 +92,9 @@ _AVERAGE_LINE_COLOR = '#006600' |
92 | 92 |
|
93 | 93 |
### GLOBAL VARIABLES ### |
94 | 94 |
|
95 |
+# Container for sensor objects. |
|
96 |
+dSensors = {} |
|
97 |
+ |
|
95 | 98 |
# turns on or off extensive debugging messages |
96 | 99 |
debugMode = False |
97 | 100 |
verboseMode = False |
... | ... |
@@ -167,7 +170,7 @@ def terminateAgentProcess(signal, frame): |
167 | 170 |
|
168 | 171 |
### PUBLIC METHODS ### |
169 | 172 |
|
170 |
-def getSensorData(dSensors, dData): |
|
173 |
+def getSensorData(dData): |
|
171 | 174 |
""" |
172 | 175 |
Poll sensors for data. Store the data in a dictionary object for |
173 | 176 |
use by other subroutines. The dictionary object passed in should |
... | ... |
@@ -504,13 +507,6 @@ def main(): |
504 | 507 |
'%s starting up node power agent process' % \ |
505 | 508 |
(getTimeStamp()) |
506 | 509 |
|
507 |
- # last time output JSON file updated |
|
508 |
- lastDataRequestTime = -1 |
|
509 |
- # last time charts generated |
|
510 |
- lastChartUpdateTime = - 1 |
|
511 |
- # last time the rrdtool database updated |
|
512 |
- lastDatabaseUpdateTime = -1 |
|
513 |
- |
|
514 | 510 |
## Get command line arguments. |
515 | 511 |
getCLarguments() |
516 | 512 |
|
... | ... |
@@ -522,7 +518,6 @@ def main(): |
522 | 518 |
exit(1) |
523 | 519 |
|
524 | 520 |
# Create sensor objects. This also initializes each sensor. |
525 |
- dSensors = {} |
|
526 | 521 |
dSensors['power'] = ina260.ina260(_PWR_SENSOR_ADDR, _BUS_NUMBER, |
527 | 522 |
debug=debugMode) |
528 | 523 |
dSensors['battemp'] = tmp102.tmp102(_BAT_TMP_SENSOR_ADDR, _BUS_NUMBER, |
... | ... |
@@ -530,6 +525,18 @@ def main(): |
530 | 525 |
dSensors['ambtemp'] = tmp102.tmp102(_AMB_TMP_SENSOR_ADDR, _BUS_NUMBER, |
531 | 526 |
debug=debugMode) |
532 | 527 |
|
528 |
+ # Enter main loop. |
|
529 |
+ main_loop() |
|
530 |
+## end def |
|
531 |
+ |
|
532 |
+def main_loop(): |
|
533 |
+ # last time output JSON file updated |
|
534 |
+ lastDataRequestTime = -1 |
|
535 |
+ # last time charts generated |
|
536 |
+ lastChartUpdateTime = - 1 |
|
537 |
+ # last time the rrdtool database updated |
|
538 |
+ lastDatabaseUpdateTime = -1 |
|
539 |
+ |
|
533 | 540 |
### MAIN LOOP ### |
534 | 541 |
|
535 | 542 |
while True: |
... | ... |
@@ -543,7 +550,7 @@ def main(): |
543 | 550 |
dData = {} |
544 | 551 |
|
545 | 552 |
# Get the data from the sensors. |
546 |
- result =getSensorData(dSensors, dData) |
|
553 |
+ result =getSensorData(dData) |
|
547 | 554 |
|
548 | 555 |
# If get data successful, write data to data files. |
549 | 556 |
if result: |
... | ... |
@@ -579,7 +586,6 @@ def main(): |
579 | 586 |
if remainingTime > 0.0: |
580 | 587 |
time.sleep(remainingTime) |
581 | 588 |
## end while |
582 |
- return |
|
583 | 589 |
## end def |
584 | 590 |
|
585 | 591 |
if __name__ == '__main__': |