9
9
import os .path
10
10
from os import path
11
11
12
-
12
+ import glob
13
13
import sys
14
14
import flask
15
15
import subprocess
@@ -32,7 +32,7 @@ def __init__(self):
32
32
self .customHistory = {}
33
33
34
34
# List of cpu temp methods found
35
- self .cpuTemps = {}
35
+ self .tempCmds = {}
36
36
37
37
self .psutilCPUHasRun = False
38
38
@@ -198,14 +198,14 @@ def on_settings_initialized(self):
198
198
# # type can be cmd, gcIn, gcOut
199
199
# self.defaultsCustom = {'cmd':'','name':'','interval': 25, 'type':'cmd', 'isTemp' : True}
200
200
201
- for key in self .cpuTemps :
202
- if self .cpuTemps [key ][1 ] != False :
201
+ for key in self .tempCmds :
202
+ if self .tempCmds [key ][1 ] != False :
203
203
self .debugOut ("Adding default CPU temp" )
204
204
# Make template
205
205
temp = self ._merge_dictionaries (self .tempTemplate .copy (),self .defaultsCustom .copy ())
206
206
# Assign
207
207
newCust = {'cu0' :temp }
208
- newCust ['cu0' ]['cmd' ] = self .cpuTemps [key ][0 ]
208
+ newCust ['cu0' ]['cmd' ] = self .tempCmds [key ][0 ]
209
209
newCust ['cu0' ]['name' ] = 'CPU temperature'
210
210
newCust ['cu0' ]['type' ] = 'cmd'
211
211
newCust ['cu0' ]['isTemp' ] = True
@@ -412,13 +412,13 @@ def buildPsuUtil(self):
412
412
# check the available methods for finding CPU temp on the hw platform
413
413
# ----------------------------------------------------------------------------------------------------------------
414
414
def checkCpuTempMethods (self ):
415
- self .cpuTemps = {}
415
+ self .tempCmds = {}
416
416
417
417
self .debugOut ("Building cpu methods!" )
418
418
419
419
# build list for linux
420
420
if sys .platform .startswith ("linux" ):
421
- self .cpuTemps = {
421
+ self .tempCmds = {
422
422
'/opt/vc/bin/vcgencmd' :
423
423
[
424
424
'/opt/vc/bin/vcgencmd measure_temp|cut -d "=" -f2|cut -d"\' " -f1' ,
@@ -442,24 +442,37 @@ def checkCpuTempMethods(self):
442
442
# try and find thermal class by looking cpu-thermal temp
443
443
code , out , err = self .runcommand ("for i in /sys/class/thermal/thermal_zone*; do if grep -qi cpu-thermal $i/type && test -f $i/temp ; then echo $i/temp;exit 0; fi; done; exit 1" )
444
444
if not code and not err :
445
- self .cpuTemps [out ] = ["awk '{print $0/1000}' " + out ,'CPU thermal zone' ,None ]
445
+ self .tempCmds [out ] = ["awk '{print $0/1000}' " + out ,'CPU thermal zone' ,None ]
446
+
447
+ # look for DS18B20 devices
448
+ DS18B20s = glob .glob ('/sys/bus/w1/devices/28-*' )
449
+ if DS18B20s :
450
+ for DS18B20 in DS18B20s :
451
+ #check slave is present /w1_slave
452
+ dsslave = os .path .join (DS18B20 ,'w1_slave' )
453
+ if os .path .isfile (dsslave ):
454
+ dsbase = os .path .basename (DS18B20 )
455
+ # check for crc
456
+ code , out , err = self .runcommand ("grep -iqP \" crc=(.*)YES\" " + dsslave )
457
+ if not code and not err :
458
+ self .tempCmds [DS18B20 ] = ["awk -F'[ =]' '$10==\" t\" {printf(\" %.2f\\ n\" ,$11/1000)}' " + dsslave ,'DS18B20 sensor (' + dsbase + ')' ,None ]
446
459
447
460
# check all methods found
448
- for key in self .cpuTemps :
461
+ for key in self .tempCmds :
449
462
if (path .exists (key )):
450
- self ._logger .debug (self .cpuTemps [key ])
451
- code , out , err = self .runcommand (self .cpuTemps [key ][0 ])
463
+ # self._logger.debug(self.tempCmds [key])
464
+ code , out , err = self .runcommand (self .tempCmds [key ][0 ])
452
465
out = out .rstrip ("\n " )
453
466
if code or err :
467
+ #self._logger.debug("ERROR 1:-------------------------------------------------------------%s %s",err,code)
454
468
pass
455
- #self._logger.debug("ERROR 1:-------------------------------------------------------------%s %s",err,code)
456
469
else :
457
470
if out .replace ('.' ,'' ,1 ).isdigit ():
458
- self .cpuTemps [ key ][ 2 ] = float ( out )
459
- # self._logger.debug("OK-------------------------------------------------------------%s", out)
471
+ # self._logger.debug("OK-------------------------------------------------------------%s", out)
472
+ self .tempCmds [ key ][ 2 ] = float ( out )
460
473
else :
474
+ # self._logger.debug("ERROR 2:-------------------------------------------------------------%s",out)
461
475
pass
462
- #self._logger.debug("ERROR 2:-------------------------------------------------------------%s",out)
463
476
else :
464
477
self ._logger .debug ("Not found:-------------------------------------------------------------%s" ,key )
465
478
@@ -712,7 +725,7 @@ def on_api_command(self, command, data):
712
725
self .buildPsuUtil ()
713
726
714
727
self .debugOut ("Sending options" )
715
- return flask .jsonify ({'cmds' : self .cpuTemps ,'psutil' : self .psutilList })
728
+ return flask .jsonify ({'cmds' : self .tempCmds ,'psutil' : self .psutilList })
716
729
717
730
# Get history data
718
731
if command == "getCustomHistory" :
0 commit comments