Skip to content

Commit 0456541

Browse files
committed
Improvements for #28
1 parent 56fa663 commit 0456541

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

examples/all-in-one-no-pm.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
from bme280 import BME280
1616
from enviroplus import gas
17-
from subprocess import PIPE, Popen
1817
from PIL import Image
1918
from PIL import ImageDraw
2019
from PIL import ImageFont
@@ -91,9 +90,10 @@ def display_text(variable, data, unit):
9190

9291
# Get the temperature of the CPU for compensation
9392
def get_cpu_temperature():
94-
process = Popen(['vcgencmd', 'measure_temp'], stdout=PIPE, universal_newlines=True)
95-
output, _error = process.communicate()
96-
return float(output[output.index('=') + 1:output.rindex("'")])
93+
with open("/sys/class/thermal/thermal_zone0/temp", "r") as f:
94+
temp = f.read()
95+
temp = int(temp) / 1000.0
96+
return temp
9797

9898

9999
# Tuning factor for compensation. Decrease this number to adjust the

examples/all-in-one.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from bme280 import BME280
1616
from pms5003 import PMS5003, ReadTimeoutError as pmsReadTimeoutError
1717
from enviroplus import gas
18-
from subprocess import PIPE, Popen
1918
from PIL import Image
2019
from PIL import ImageDraw
2120
from PIL import ImageFont
@@ -96,9 +95,10 @@ def display_text(variable, data, unit):
9695

9796
# Get the temperature of the CPU for compensation
9897
def get_cpu_temperature():
99-
process = Popen(['vcgencmd', 'measure_temp'], stdout=PIPE, universal_newlines=True)
100-
output, _error = process.communicate()
101-
return float(output[output.index('=') + 1:output.rindex("'")])
98+
with open("/sys/class/thermal/thermal_zone0/temp", "r") as f:
99+
temp = f.read()
100+
temp = int(temp) / 1000.0
101+
return temp
102102

103103

104104
# Tuning factor for compensation. Decrease this number to adjust the

examples/luftdaten.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ def read_values():
7171
return values
7272

7373

74-
# Get CPU temperature to use for compensation
74+
# Get the temperature of the CPU for compensation
7575
def get_cpu_temperature():
76-
process = Popen(['vcgencmd', 'measure_temp'], stdout=PIPE, universal_newlines=True)
77-
output, _error = process.communicate()
78-
return float(output[output.index('=') + 1:output.rindex("'")])
76+
with open("/sys/class/thermal/thermal_zone0/temp", "r") as f:
77+
temp = f.read()
78+
temp = int(temp) / 1000.0
79+
return temp
7980

8081

8182
# Get Raspberry Pi serial number to use as ID

0 commit comments

Comments
 (0)