Skip to content

Commit e5bf0d8

Browse files
committed
Added temperature display to DS18B20 and several small other fixes
1 parent 133b54d commit e5bf0d8

File tree

3 files changed

+65
-11
lines changed

3 files changed

+65
-11
lines changed

probe.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
print e
4646
#sys.exit()
4747

48-
4948
def main():
5049
"""
5150
Main routine for MiniProbe (Python)

sensors/ds18b20.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,23 @@ def get_sensordef():
5353
"help": "Returns the temperature measured by an attached DS18B20 temperature sensor on pin 4",
5454
"tag": "mpds18b20sensor",
5555
"groups": [
56+
{
57+
"name":"Group",
58+
"caption":"Temperature settings",
59+
"fields":[
60+
{
61+
"type":"radio",
62+
"name":"celfar",
63+
"caption":"Choose between Celsius or Fahrenheit display",
64+
"help":"Choose wether you want to return the value in Celsius or Fahrenheit",
65+
"options":{
66+
"C":"Celsius",
67+
"F":"Fahrenheit"
68+
},
69+
"default":"C"
70+
},
71+
]
72+
}
5673
]
5774
}
5875
return sensordefinition
@@ -62,7 +79,7 @@ def get_data(data):
6279
temperature = DS18B20()
6380
logging.info("Running sensor: %s" % temperature.get_kind())
6481
try:
65-
temp = temperature.read_temp()
82+
temp = temperature.read_temp(data)
6683
except Exception as e:
6784
logging.error("Ooops Something went wrong with '%s' sensor %s. Error: %s" % (temperature.get_kind(),
6885
data['sensorid'], e))
@@ -86,7 +103,7 @@ def get_data(data):
86103
return data
87104

88105
@staticmethod
89-
def read_temp():
106+
def read_temp(config):
90107
data = []
91108
sens = []
92109
chandata = []
@@ -101,16 +118,20 @@ def read_temp():
101118
equals_pos = lines[1].find('t=')
102119
if equals_pos != -1:
103120
temp_string = lines[1][equals_pos+2:]
104-
logging.debug("DS18B20 Debug message: Temperature from file: %s" % temp_string)
121+
logging.debug("DS18B20 Debug message: Temperature from file: %s %s" % temp_string, config['celfar'])
105122
temp_c = float(temp_string) / 1000.0
106-
logging.debug("DS18B20 Debug message: Temperature after calculations:: %s" % temp_c)
107-
data.append(temp_c)
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'])
125+
if config['celfar'] == "C":
126+
data.append(temp_c)
127+
else:
128+
data.append(temp_f)
108129
temp.close()
109130
for i in range(len(data)):
110131
chandata.append({"name": "Sensor: " + sens[i],
111132
"mode": "float",
112133
"unit": "Custom",
113-
"customunit": "C",
134+
"customunit": config['celfar'],
114135
"LimitMode": 1,
115136
"LimitMaxError": 40,
116137
"LimitMaxWarning": 35,

sensors/probehealth.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def get_data(data):
5858
mem = probehealth.read_memory('/proc/meminfo')
5959
cpu = probehealth.read_cpu('/proc/loadavg')
6060
temperature = probehealth.read_temp()
61+
disk = probehealth.read_disk()
6162
logging.info("Running sensor: %s" % probehealth.get_kind())
6263
except Exception as e:
6364
logging.error("Ooops Something went wrong with '%s' sensor %s. Error: %s" % (probehealth.get_kind(),
@@ -76,6 +77,8 @@ def get_data(data):
7677
probedata.append(element)
7778
for element in cpu:
7879
probedata.append(element)
80+
for element in disk:
81+
probedata.append(element)
7982
data = {
8083
"sensorid": int(data['sensorid']),
8184
"message": "OK",
@@ -134,11 +137,42 @@ def read_cpu(self, path):
134137

135138
def read_disk(self):
136139
disks = []
137-
tmp = []
138-
for line in os.popen("df -h"):
140+
channel_list = []
141+
for line in os.popen("df -k"):
139142
if line.startswith("/"):
140-
tmp.append(line.rstrip())
141-
print disks
143+
disks.append(line.rstrip().split())
144+
for line in disks:
145+
channel1 = {"name": "Total Bytes " + str(line[0]),
146+
"mode": "integer",
147+
"kind": "BytesDisk",
148+
"value": int(line[1]) * 1024}
149+
channel2 = {"name": "Used Bytes" + str(line[0]),
150+
"mode": "integer",
151+
"kind": "BytesDisk",
152+
"value": int(line[2]) * 1024}
153+
channel3 = {"name": "Free Bytes " + str(line[0]),
154+
"mode": "integer",
155+
"kind": "BytesDisk",
156+
"value": int(line[3]) * 1024}
157+
total = float(line[2]) + float(line[3])
158+
used = float(line[2]) / total
159+
free = float(line[3]) / total
160+
161+
channel4 = {"name": "Free Space " + str(line[0]),
162+
"mode": "float",
163+
"kind": "Percent",
164+
"value": free * 100}
165+
channel5 = {"name": "Used Space" + str(line[0]),
166+
"mode": "float",
167+
"kind": "Percent",
168+
"value": used * 100}
169+
channel_list.append(channel1)
170+
channel_list.append(channel2)
171+
channel_list.append(channel3)
172+
channel_list.append(channel4)
173+
channel_list.append(channel5)
174+
return channel_list
175+
142176

143177
def read_temp(self):
144178
data = []

0 commit comments

Comments
 (0)