Skip to content

Commit ec07594

Browse files
flake8 fiddling
1 parent 9d2c692 commit ec07594

File tree

3 files changed

+58
-39
lines changed

3 files changed

+58
-39
lines changed

examples/all-in-one.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,35 +54,41 @@
5454
# The position of the top bar
5555
top_pos = 25
5656

57+
5758
# Displays data and text on the 0.96" LCD
5859
def display_text(variable, data, unit):
5960
# Maintain length of list
6061
values[variable] = values[variable][1:] + [data]
6162
# Scale the values for the variable between 0 and 1
62-
colours = [(v - min(values[variable]) + 1) / (max(values[variable]) - min(values[variable]) + 1) for v in values[variable]]
63+
colours = [(v - min(values[variable]) + 1) / (max(values[variable])
64+
- min(values[variable]) + 1) for v in values[variable]]
6365
# Format the variable name and value
6466
message = "{}: {:.1f} {}".format(variable[:4], data, unit)
6567
print(message)
6668
draw.rectangle((0, 0, WIDTH, HEIGHT), (255, 255, 255))
6769
for i in range(len(colours)):
6870
# Convert the values to colours from red to blue
6971
colour = (1.0 - colours[i]) * 0.6
70-
r, g, b = [int(x * 255.0) for x in colorsys.hsv_to_rgb(colour, 1.0, 1.0)]
72+
r, g, b = [int(x * 255.0) for x in colorsys.hsv_to_rgb(colour,
73+
1.0, 1.0)]
7174
# Draw a 1-pixel wide rectangle of colour
7275
draw.rectangle((i, top_pos, i+1, HEIGHT), (r, g, b))
7376
# Draw a line graph in black
74-
line_y = HEIGHT - (top_pos + (colours[i] * (HEIGHT - top_pos))) + top_pos
77+
line_y = HEIGHT - (top_pos + (colours[i] * (HEIGHT - top_pos)))\
78+
+ top_pos
7579
draw.rectangle((i, line_y, i+1, line_y+1), (0, 0, 0))
7680
# Write the text at the top in black
7781
draw.text((0, 0), message, font=font, fill=(0, 0, 0))
7882
st7735.display(img)
7983

84+
8085
# Get the temperature of the CPU for compensation
8186
def get_cpu_temperature():
8287
process = Popen(['vcgencmd', 'measure_temp'], stdout=PIPE)
8388
output, _error = process.communicate()
8489
return float(output[output.index('=') + 1:output.rindex("'")])
8590

91+
8692
# Tuning factor for compensation. Decrease this number to adjust the
8793
# temperature down, and increase to adjust up
8894
factor = 0.8

examples/compensated-temperature.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
except ImportError:
1010
from smbus import SMBus
1111

12-
print("""compensated-temperature.py - Use the CPU temperature to compensate temperature
13-
readings from the BME280 sensor. Method adapted from Initial State's Enviro pHAT
14-
review: https://medium.com/@InitialState/tutorial-review-enviro-phat-for-raspberry-pi-4cd6d8c63441
12+
print("""compensated-temperature.py - Use the CPU temperature
13+
to compensate temperature readings from the BME280 sensor.
14+
Method adapted from Initial State's Enviro pHAT review:
15+
https://medium.com/@InitialState/tutorial-review-enviro-phat-for-raspberry-pi-4cd6d8c63441
1516
1617
Press Ctrl+C to exit!
1718
@@ -20,12 +21,14 @@
2021
bus = SMBus(1)
2122
bme280 = BME280(i2c_dev=bus)
2223

24+
2325
# Get the temperature of the CPU for compensation
2426
def get_cpu_temperature():
2527
process = Popen(['vcgencmd', 'measure_temp'], stdout=PIPE)
2628
output, _error = process.communicate()
2729
return float(output[output.index('=') + 1:output.rindex("'")])
2830

31+
2932
# Tuning factor for compensation. Decrease this number to adjust the
3033
# temperature down, and increase to adjust up
3134
factor = 0.8

examples/luftdaten.py

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env python
22

3-
import time
4-
import json
53
import requests
64
import ST7735
75
from bme280 import BME280
@@ -14,12 +12,15 @@
1412
except ImportError:
1513
from smbus import SMBus
1614

17-
print("""luftdaten.py - Reads temperature, pressure, humidity, PM2.5, and PM10 from
18-
Enviro plus and sends data to Luftdaten, the citizen science air quality project.
15+
print("""luftdaten.py - Reads temperature, pressure, humidity,
16+
PM2.5, and PM10 from Enviro plus and sends data to Luftdaten,
17+
the citizen science air quality project.
1918
20-
Note: you'll need to register with Luftdaten at: https://meine.luftdaten.info/ and
21-
enter your Raspberry Pi serial number that's displayed on the Enviro plus LCD
22-
along with the other details before the data appears on the Luftdaten map.
19+
Note: you'll need to register with Luftdaten at:
20+
https://meine.luftdaten.info/ and enter your Raspberry Pi
21+
serial number that's displayed on the Enviro plus LCD along
22+
with the other details before the data appears on the
23+
Luftdaten map.
2324
2425
Press Ctrl+C to exit!
2526
@@ -30,9 +31,6 @@
3031
# Create BME280 instance
3132
bme280 = BME280(i2c_dev=bus)
3233

33-
# Create PMS5003 instance
34-
pms5003 = PMS5003()
35-
3634
# Create LCD instance
3735
disp = ST7735.ST7735(
3836
port=0,
@@ -46,6 +44,10 @@
4644
# Initialize display
4745
disp.begin()
4846

47+
# Create PMS5003 instance
48+
pms5003 = PMS5003()
49+
50+
4951
# Read values from BME280 and PMS5003 and return as dict
5052
def read_values():
5153
values = {}
@@ -66,18 +68,21 @@ def read_values():
6668
values["P1"] = str(pm_values.pm_ug_per_m3(10))
6769
return values
6870

71+
6972
# Get CPU temperature to use for compensation
7073
def get_cpu_temperature():
7174
process = Popen(['vcgencmd', 'measure_temp'], stdout=PIPE)
7275
output, _error = process.communicate()
7376
return float(output[output.index('=') + 1:output.rindex("'")])
7477

78+
7579
# Get Raspberry Pi serial number to use as ID
7680
def get_serial_number():
77-
with open('/proc/cpuinfo','r') as f:
81+
with open('/proc/cpuinfo', 'r') as f:
7882
for line in f:
79-
if line[0:6]=='Serial':
80-
return(line.split(":")[1].strip())
83+
if line[0:6] == 'Serial':
84+
return line.split(":")[1].strip()
85+
8186

8287
# Check for Wi-Fi connection
8388
def check_wifi():
@@ -86,6 +91,7 @@ def check_wifi():
8691
else:
8792
return False
8893

94+
8995
# Display Raspberry Pi serial and Wi-Fi status on LCD
9096
def display_status():
9197
wifi_status = "connected" if check_wifi() else "disconnected"
@@ -102,41 +108,45 @@ def display_status():
102108
draw.text((x, y), message, font=font, fill=text_colour)
103109
disp.display(img)
104110

111+
105112
def send_to_luftdaten(values, id):
106113
pm_values = dict(i for i in values.items() if i[0].startswith("P"))
107114
temp_values = dict(i for i in values.items() if not i[0].startswith("P"))
108115

109116
resp_1 = requests.post("https://api.luftdaten.info/v1/push-sensor-data/",
110-
json={
111-
"software_version": "enviro-plus 0.0.1",
112-
"sensordatavalues": [{"value_type": key, "value": val} for key, val in pm_values.items()]
113-
},
114-
headers={
115-
"X-PIN": "1",
116-
"X-Sensor": id,
117-
"Content-Type": "application/json",
118-
"cache-control": "no-cache"
119-
}
117+
json={
118+
"software_version": "enviro-plus 0.0.1",
119+
"sensordatavalues": [{"value_type": key, "value": val} for
120+
key, val in pm_values.items()]
121+
},
122+
headers={
123+
"X-PIN": "1",
124+
"X-Sensor": id,
125+
"Content-Type": "application/json",
126+
"cache-control": "no-cache"
127+
}
120128
)
121129

122130
resp_2 = requests.post("https://api.luftdaten.info/v1/push-sensor-data/",
123-
json={
124-
"software_version": "enviro-plus 0.0.1",
125-
"sensordatavalues": [{"value_type": key, "value": val} for key, val in temp_values.items()]
126-
},
127-
headers={
128-
"X-PIN": "11",
129-
"X-Sensor": id,
130-
"Content-Type": "application/json",
131-
"cache-control": "no-cache"
132-
}
131+
json={
132+
"software_version": "enviro-plus 0.0.1",
133+
"sensordatavalues": [{"value_type": key, "value": val} for
134+
key, val in temp_values.items()]
135+
},
136+
headers={
137+
"X-PIN": "11",
138+
"X-Sensor": id,
139+
"Content-Type": "application/json",
140+
"cache-control": "no-cache"
141+
}
133142
)
134143

135144
if resp_1.ok and resp_2.ok:
136145
return True
137146
else:
138147
return False
139148

149+
140150
# Compensation factor for temperature
141151
comp_factor = 1.2
142152

0 commit comments

Comments
 (0)