Skip to content

Commit fcfd8a1

Browse files
Adding delay to avoid rate-limiting by Luftdaten
1 parent a73ee78 commit fcfd8a1

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

examples/luftdaten.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import requests
44
import ST7735
5+
import time
56
from bme280 import BME280
67
from pms5003 import PMS5003, ReadTimeoutError
78
from subprocess import PIPE, Popen, check_output
@@ -165,13 +166,19 @@ def send_to_luftdaten(values, id):
165166
print("Raspberry Pi serial: {}".format(get_serial_number()))
166167
print("Wi-Fi: {}\n".format("connected" if check_wifi() else "disconnected"))
167168

169+
time_since_update = 0
170+
update_time = time.time()
171+
168172
# Main loop to read data, display, and send to Luftdaten
169173
while True:
170174
try:
175+
time_since_update = time.time() - update_time
171176
values = read_values()
172177
print(values)
173-
resp = send_to_luftdaten(values, id)
174-
print("Response: {}\n".format("ok" if resp else "failed"))
178+
if time_since_update > 145:
179+
resp = send_to_luftdaten(values, id)
180+
update_time = time.time()
181+
print("Response: {}\n".format("ok" if resp else "failed"))
175182
display_status()
176183
except Exception as e:
177184
print(e)

0 commit comments

Comments
 (0)