Skip to content

Commit 97b70f1

Browse files
committed
DS18B20 fahrenheit display fix
1 parent e5bf0d8 commit 97b70f1

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

probe_installer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def add_sensor_to_load_list(sensors):
128128
f.write("# Announce modules available in this package\n")
129129
f.write("# Just extend this list for your modules and they will be automatically imported during runtime and\n")
130130
f.write("# are announced to the PRTG Core\n")
131-
f.write("__all__ = [\"Ping\", \"HTTP\", \"Port\", \"SNMPCustom\", \"CPULoad\", \"Memory\", \"Diskspace\", \"SNMPTraffic\", \"DS18B20\", \"CPUTemp\"]\n")
131+
f.write("__all__ = [\"Ping\", \"HTTP\", \"Port\", \"SNMPCustom\", \"CPULoad\", \"Memory\", \"Diskspace\", \"SNMPTraffic\", \"DS18B20\", \"CPUTemp\", \"Probehealth\"]\n")
132132
f.write("DS18B20_sensors = [" + str(sensors) + "]\n")
133133
f.close()
134134

sensors/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
# Announce modules available in this package
2222
# Just extend this list for your modules and they will be automatically imported during runtime and
2323
# are announced to the PRTG Core
24-
__all__ = ["Ping", "HTTP", "Port", "SNMPCustom", "CPULoad", "Memory", "Diskspace", "SNMPTraffic", "DS18B20", "CPUTemp", "Probehealth"]
24+
__all__ = ["Ping", "HTTP", "Port", "SNMPCustom", "CPULoad", "Memory", "Diskspace", "SNMPTraffic", "DS18B20", "CPUTemp"]
2525
DS18B20_sensors = ["000006ad5c3f"]

sensors/cputemp.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,23 @@ def get_sensordef():
4949
"help": "Returns the CPU temperature",
5050
"tag": "mpcputempsensor",
5151
"groups": [
52+
{
53+
"name":"Group",
54+
"caption":"Temperature settings",
55+
"fields":[
56+
{
57+
"type":"radio",
58+
"name":"celfar",
59+
"caption":"Choose between Celsius or Fahrenheit display",
60+
"help":"Choose wether you want to return the value in Celsius or Fahrenheit",
61+
"options":{
62+
"C":"Celsius",
63+
"F":"Fahrenheit"
64+
},
65+
"default":"C"
66+
},
67+
]
68+
}
5269
]
5370
}
5471
return sensordefinition
@@ -58,7 +75,7 @@ def get_data(data):
5875
temperature = CPUTemp()
5976
logging.info("Running sensor: %s" % temperature.get_kind())
6077
try:
61-
temp = temperature.read_temp()
78+
temp = temperature.read_temp(data)
6279
except Exception as e:
6380
logging.error("Ooops Something went wrong with '%s' sensor %s. Error: %s" % (temperature.get_kind(),
6481
data['sensorid'], e))
@@ -82,7 +99,7 @@ def get_data(data):
8299
return data
83100

84101
@staticmethod
85-
def read_temp():
102+
def read_temp(config):
86103
data = []
87104
chandata = []
88105
temp = open("/sys/class/thermal/thermal_zone0/temp", "r")
@@ -91,13 +108,18 @@ def read_temp():
91108
temp_string = lines[0]
92109
logging.debug("CPUTemp Debug message: Temperature from file: %s" % temp_string)
93110
temp_c = float(temp_string) / 1000.0
111+
temp_f = temp_c * 9.0 / 5.0 + 32.0
94112
logging.debug("CPUTemp Debug message: Temperature after calculations:: %s" % temp_c)
95-
data.append(temp_c)
113+
if config['celfar'] == "C":
114+
data.append(temp_c)
115+
else:
116+
data.append(temp_f)
117+
# data.append(temp_c)
96118
for i in range(len(data)):
97119
chandata.append({"name": "CPU Temperature",
98120
"mode": "float",
99121
"unit": "Custom",
100-
"customunit": "C",
122+
"customunit": config['celfar'],
101123
"LimitMode": 1,
102124
"LimitMaxError": 40,
103125
"LimitMaxWarning": 35,

sensors/ds18b20.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,15 @@ def read_temp(config):
118118
equals_pos = lines[1].find('t=')
119119
if equals_pos != -1:
120120
temp_string = lines[1][equals_pos+2:]
121-
logging.debug("DS18B20 Debug message: Temperature from file: %s %s" % temp_string, config['celfar'])
121+
logging.debug("DS18B20 Debug message: Temperature from file: %s" % temp_string)
122122
temp_c = float(temp_string) / 1000.0
123-
temp_f = temp_c * 9.0 / 5.0 + 32.0
124-
logging.debug("DS18B20 Debug message: Temperature after calculations:: %s" % temp_c, config['celfar'])
123+
temp_f = 1.8 * temp_c + 32.0
125124
if config['celfar'] == "C":
126125
data.append(temp_c)
126+
logging.debug("DS18B20 Debug message: Temperature after calculations:: %s %s" % (temp_c, config['celfar']))
127127
else:
128128
data.append(temp_f)
129+
logging.debug("DS18B20 Debug message: Temperature after calculations:: %s %s" % (temp_f, config['celfar']))
129130
temp.close()
130131
for i in range(len(data)):
131132
chandata.append({"name": "Sensor: " + sens[i],

0 commit comments

Comments
 (0)