Skip to content

Commit f6ee18b

Browse files
Update Luftdaten examples to Sensor.Community
Co-authored-by: Phil Howard <phil@gadgetoid.com>
1 parent 2cfed37 commit f6ee18b

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

examples/luftdaten.py renamed to examples/sensorcommunity.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
level=logging.INFO,
1818
datefmt="%Y-%m-%d %H:%M:%S")
1919

20-
logging.info("""luftdaten.py - Reads temperature, pressure, humidity,
21-
PM2.5, and PM10 from Enviro plus and sends data to Luftdaten,
20+
logging.info("""sensorcommunity.py - Reads temperature, pressure, humidity,
21+
PM2.5, and PM10 from Enviro plus and sends data to Sensor.Community,
2222
the citizen science air quality project.
2323
24-
Note: you'll need to register with Luftdaten at:
25-
https://meine.luftdaten.info/ and enter your Raspberry Pi
24+
Note: you'll need to register with Sensor.Community at:
25+
https://devices.sensor.community/ and enter your Raspberry Pi
2626
serial number that's displayed on the Enviro plus LCD along
2727
with the other details before the data appears on the
28-
Luftdaten map.
28+
Sensor.Community map.
2929
3030
Press Ctrl+C to exit!
3131
@@ -118,7 +118,7 @@ def display_status():
118118
disp.display(img)
119119

120120

121-
def send_to_luftdaten(values, id):
121+
def send_to_sensorcommunity(values, id):
122122
pm_values = dict(i for i in values.items() if i[0].startswith("P"))
123123
temp_values = dict(i for i in values.items() if not i[0].startswith("P"))
124124

@@ -132,7 +132,7 @@ def send_to_luftdaten(values, id):
132132
resp_pm = requests.post(
133133
"https://api.sensor.community/v1/push-sensor-data/",
134134
json={
135-
"software_version": "enviro-plus 0.0.1",
135+
"software_version": "enviro-plus 1.0.0",
136136
"sensordatavalues": pm_values_json
137137
},
138138
headers={
@@ -144,17 +144,17 @@ def send_to_luftdaten(values, id):
144144
timeout=5
145145
)
146146
except requests.exceptions.ConnectionError as e:
147-
logging.warning(f"Sensor.Community (Luftdaten) PM Connection Error: {e}")
147+
logging.warning(f"Sensor.Community PM Connection Error: {e}")
148148
except requests.exceptions.Timeout as e:
149-
logging.warning(f"Sensor.Community (Luftdaten) PM Timeout Error: {e}")
149+
logging.warning(f"Sensor.Community PM Timeout Error: {e}")
150150
except requests.exceptions.RequestException as e:
151-
logging.warning(f"Sensor.Community (Luftdaten) PM Request Error: {e}")
151+
logging.warning(f"Sensor.Community PM Request Error: {e}")
152152

153153
try:
154154
resp_bmp = requests.post(
155155
"https://api.sensor.community/v1/push-sensor-data/",
156156
json={
157-
"software_version": "enviro-plus 0.0.1",
157+
"software_version": "enviro-plus 1.0.0",
158158
"sensordatavalues": temp_values_json
159159
},
160160
headers={
@@ -166,17 +166,17 @@ def send_to_luftdaten(values, id):
166166
timeout=5
167167
)
168168
except requests.exceptions.ConnectionError as e:
169-
logging.warning(f"Sensor.Community (Luftdaten) Climate Connection Error: {e}")
169+
logging.warning(f"Sensor.Community Climate Connection Error: {e}")
170170
except requests.exceptions.Timeout as e:
171-
logging.warning(f"Sensor.Community (Luftdaten) Climate Timeout Error: {e}")
171+
logging.warning(f"Sensor.Community Climate Timeout Error: {e}")
172172
except requests.exceptions.RequestException as e:
173-
logging.warning(f"Sensor.Community (Luftdaten) Climate Request Error: {e}")
173+
logging.warning(f"Sensor.Community Climate Request Error: {e}")
174174

175175
if resp_pm is not None and resp_bmp is not None:
176176
if resp_pm.ok and resp_bmp.ok:
177177
return True
178178
else:
179-
logging.warning(f"Luftdaten Error. PM: {resp_pm.reason}, Climate: {resp_bmp.reason}")
179+
logging.warning(f"Sensor.Community Error. PM: {resp_pm.reason}, Climate: {resp_bmp.reason}")
180180
return False
181181
else:
182182
return False
@@ -185,7 +185,7 @@ def send_to_luftdaten(values, id):
185185
# Compensation factor for temperature
186186
comp_factor = 2.25
187187

188-
# Raspberry Pi ID to send to Luftdaten
188+
# Raspberry Pi ID to send to Sensor.Community
189189
id = "raspi-" + get_serial_number()
190190

191191
# Width and height to calculate text position
@@ -204,18 +204,18 @@ def send_to_luftdaten(values, id):
204204
time_since_update = 0
205205
update_time = time.time()
206206

207-
# Main loop to read data, display, and send to Luftdaten
207+
# Main loop to read data, display, and send to Sensor.Community
208208
while True:
209209
try:
210210
values = read_values()
211211
time_since_update = time.time() - update_time
212212
if time_since_update > 145:
213213
logging.info(values)
214214
update_time = time.time()
215-
if send_to_luftdaten(values, id):
216-
logging.info("Luftdaten Response: OK")
215+
if send_to_sensorcommunity(values, id):
216+
logging.info("Sensor.Community Response: OK")
217217
else:
218-
logging.warning("Luftdaten Response: Failed")
218+
logging.warning("Sensor.Community Response: Failed")
219219
display_status()
220220
except Exception as e:
221221
logging.warning(f"Main Loop Exception: {e}")

examples/luftdaten_combined.py renamed to examples/sensorcommunity_combined.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@
2020
except ImportError:
2121
import ltr559
2222

23-
print("""luftdaten_combined.py - This combines the functionality of luftdaten.py and combined.py
23+
print("""sensorcommunity_combined.py - This combines the functionality of sensorcommunity.py and combined.py
2424
================================================================================================
25-
Luftdaten INFO
25+
Sensor.Community INFO
2626
Reads temperature, pressure, humidity,
27-
PM2.5, and PM10 from Enviro plus and sends data to Luftdaten,
27+
PM2.5, and PM10 from Enviro plus and sends data to Sensor.Community,
2828
the citizen science air quality project.
2929
30-
Note: you'll need to register with Luftdaten at:
31-
https://meine.luftdaten.info/ and enter your Raspberry Pi
30+
Note: you'll need to register with Sensor.Community at:
31+
https://devices.sensor.community/ and enter your Raspberry Pi
3232
serial number that's displayed on the Enviro plus LCD along
3333
with the other details before the data appears on the
34-
Luftdaten map.
34+
Sensor.Community map.
3535
3636
Press Ctrl+C to exit!
3737
@@ -242,7 +242,7 @@ def display_everything():
242242
st7735.display(img)
243243

244244

245-
def send_to_luftdaten(values, id):
245+
def send_to_sensorcommunity(values, id):
246246
pm_values = dict(i for i in values.items() if i[0].startswith("P"))
247247
temp_values = dict(i for i in values.items() if not i[0].startswith("P"))
248248

@@ -252,9 +252,9 @@ def send_to_luftdaten(values, id):
252252
for key, val in temp_values.items()]
253253

254254
resp_1 = requests.post(
255-
"https://api.luftdaten.info/v1/push-sensor-data/",
255+
"https://api.sensor.community/v1/push-sensor-data/",
256256
json={
257-
"software_version": "enviro-plus 0.0.1",
257+
"software_version": "enviro-plus 1.0.0",
258258
"sensordatavalues": pm_values_json
259259
},
260260
headers={
@@ -266,9 +266,9 @@ def send_to_luftdaten(values, id):
266266
)
267267

268268
resp_2 = requests.post(
269-
"https://api.luftdaten.info/v1/push-sensor-data/",
269+
"https://api.sensor.community/v1/push-sensor-data/",
270270
json={
271-
"software_version": "enviro-plus 0.0.1",
271+
"software_version": "enviro-plus 1.0.0",
272272
"sensordatavalues": temp_values_json
273273
},
274274
headers={
@@ -288,7 +288,7 @@ def send_to_luftdaten(values, id):
288288
# Compensation factor for temperature
289289
comp_factor = 1
290290

291-
# Raspberry Pi ID to send to Luftdaten
291+
# Raspberry Pi ID to send to Sensor.Community
292292
id = "raspi-" + get_serial_number()
293293

294294

@@ -317,7 +317,7 @@ def send_to_luftdaten(values, id):
317317
update_time = time.time()
318318
cpu_temps_len = float(len(cpu_temps))
319319

320-
# Main loop to read data, display, and send to Luftdaten
320+
# Main loop to read data, display, and send to Sensor.Community
321321
while True:
322322
try:
323323
curtime = time.time()
@@ -346,7 +346,7 @@ def send_to_luftdaten(values, id):
346346
if time_since_update > 145:
347347
values = read_values(comp_temp, raw_press*100,
348348
raw_humid, raw_pm25, raw_pm10)
349-
resp = send_to_luftdaten(values, id)
349+
resp = send_to_sensorcommunity(values, id)
350350
update_time = curtime
351351
status = "ok" if resp else "failed"
352352
print(f"Response: {status}\n")

0 commit comments

Comments
 (0)