@@ -124,10 +124,12 @@ def send_to_luftdaten(values, id):
124124
125125 pm_values_json = [{"value_type" : key , "value" : val } for key , val in pm_values .items ()]
126126 temp_values_json = [{"value_type" : key , "value" : val } for key , val in temp_values .items ()]
127- resp1_exception = False
128- resp2_exception = False
127+
128+ resp_pm = None
129+ resp_bmp = None
130+
129131 try :
130- resp_1 = requests .post (
132+ resp_pm = requests .post (
131133 "https://api.luftdaten.info/v1/push-sensor-data/" ,
132134 json = {
133135 "software_version" : "enviro-plus 0.0.1" ,
@@ -142,17 +144,14 @@ def send_to_luftdaten(values, id):
142144 timeout = 5
143145 )
144146 except requests .exceptions .ConnectionError as e :
145- resp1_exception = True
146- logging .info ('Luftdaten PM Connection Error: ' + str (e ))
147+ logging .warning ('Luftdaten PM Connection Error: {}' .format (e ))
147148 except requests .exceptions .Timeout as e :
148- resp1_exception = True
149- logging .info ('Luftdaten PM Timeout Error: ' + str (e ))
149+ logging .warning ('Luftdaten PM Timeout Error: {}' .format (e ))
150150 except requests .exceptions .RequestException as e :
151- resp1_exception = True
152- logging .info ('Luftdaten PM Request Error: ' + str (e ))
151+ logging .warning ('Luftdaten PM Request Error: {}' .format (e ))
153152
154153 try :
155- resp_2 = requests .post (
154+ resp_bmp = requests .post (
156155 "https://api.luftdaten.info/v1/push-sensor-data/" ,
157156 json = {
158157 "software_version" : "enviro-plus 0.0.1" ,
@@ -167,19 +166,17 @@ def send_to_luftdaten(values, id):
167166 timeout = 5
168167 )
169168 except requests .exceptions .ConnectionError as e :
170- resp2_exception = True
171- logging .info ('Luftdaten Climate Connection Error: ' + str (e ))
169+ logging .warning ('Luftdaten Climate Connection Error: {}' .format (e ))
172170 except requests .exceptions .Timeout as e :
173- resp2_exception = True
174- logging .info ('Luftdaten Climate Timeout Error: ' + str (e ))
171+ logging .warning ('Luftdaten Climate Timeout Error: {}' .format (e ))
175172 except requests .exceptions .RequestException as e :
176- resp2_exception = True
177- logging .info ('Luftdaten Climate Request Error: ' + str (e ))
173+ logging .warning ('Luftdaten Climate Request Error: {}' .format (e ))
178174
179- if not resp1_exception and not resp2_exception :
180- if resp_1 .ok and resp_2 .ok :
175+ if resp_pm is not None and resp_bmp is not None :
176+ if resp_pm .ok and resp_bmp .ok :
181177 return True
182178 else :
179+ logging .warning ('Luftdaten Error. PM: {}, Climate: {}' .format (resp_pm .reason , resp_bmp .reason ))
183180 return False
184181 else :
185182 return False
@@ -210,12 +207,14 @@ def send_to_luftdaten(values, id):
210207while True :
211208 try :
212209 values = read_values ()
213- logging .info (values )
214210 time_since_update = time .time () - update_time
215211 if time_since_update > 145 :
216- resp = send_to_luftdaten (values , id )
212+ logging . info (values )
217213 update_time = time .time ()
218- logging .info ("Luftdaten Response: {}\n " .format ("ok" if resp else "failed" ))
214+ if send_to_luftdaten (values , id ):
215+ logging .info ("Luftdaten Response: OK" )
216+ else :
217+ logging .warning ("Luftdaten Response: Failed" )
219218 display_status ()
220219 except Exception as e :
221- logging .info ( " Main Loop Exception: " + str (e ))
220+ logging .warning ( ' Main Loop Exception: {}' . format (e ))
0 commit comments