Browse code

minor revision

Gandolf authored on 07/12/2021 20:39:47
Showing 1 changed files
... ...
@@ -188,6 +188,8 @@ def getSensorData(dSensors, dData):
188 188
         print("%s sensor error: %s" % (getTimeStamp(), exError))
189 189
         return False
190 190
 
191
+    dData['chartUpdateInterval'] = chartUpdateInterval
192
+
191 193
     return True
192 194
 ## end def
193 195
 
... ...
@@ -212,7 +214,6 @@ def writeOutputFile(dData):
212 214
     try:
213 215
         for key in dData:
214 216
             jsData.update({key:dData[key]})
215
-        jsData.update({"chartUpdateInterval": chartUpdateInterval})
216 217
         sData = "[%s]" % json.dumps(jsData)
217 218
     except Exception as exError:
218 219
         print("%s writeOutputFile: %s" % (getTimeStamp(), exError))
... ...
@@ -253,17 +254,20 @@ def setStatus(updateSuccess):
253 254
         if not deviceOnline:
254 255
             print('%s device online' % getTimeStamp())
255 256
             deviceOnline = True
257
+        return
256 258
     else:
257 259
         # The last attempt failed, so update the failed attempts
258 260
         # count.
259 261
         failedUpdateCount += 1
260 262
 
261
-    if failedUpdateCount >= _MAX_FAILED_DATA_REQUESTS:
263
+    if failedUpdateCount == _MAX_FAILED_DATA_REQUESTS:
262 264
         # Max number of failed data requests, so set
263 265
         # device status to offline.
264 266
         setStatusToOffline()
265 267
 ##end def
266 268
 
269
+    ### DATABASE FUNCTIONS ###
270
+
267 271
 def updateDatabase(dData):
268 272
     """
269 273
     Update the rrdtool database by executing an rrdtool system command.
... ...
@@ -289,12 +293,12 @@ def updateDatabase(dData):
289 293
         subprocess.check_output(strCmd, shell=True, \
290 294
             stderr=subprocess.STDOUT)
291 295
     except subprocess.CalledProcessError as exError:
292
-        print("%s: rrdtool update failed: %s" % \
296
+        print("%s: rrdtool update: %s" % \
293 297
             (getTimeStamp(), exError.output))
294 298
         return False
295 299
 
296 300
     if verboseMode and not debugMode:
297
-        print("database updated")
301
+        print("database update successful")
298 302
 
299 303
     return True
300 304
 ## end def
... ...
@@ -373,7 +377,8 @@ def createGraph(fileName, dataItem, gLabel, gTitle, gStart,
373 377
                      stderr=subprocess.STDOUT,   \
374 378
                      shell=True)
375 379
     except subprocess.CalledProcessError as exError:
376
-        print("rrdtool graph failed: %s" % (exError.output))
380
+        print("%s rrdtool graph: %s" % \
381
+              (getTimeStamp(), exError.output))
377 382
         return False
378 383
 
379 384
     if verboseMode and not debugMode: