Tried better error handling, result -2 at urequest.post

This commit is contained in:
Milan Toman
2021-03-08 11:13:20 +01:00
parent d309db1c5c
commit 9bd1c54c0c
2 changed files with 17 additions and 5 deletions

View File

@@ -34,10 +34,14 @@ def send_to_influx(host, port, db, user, password, davis_unit_id, wind, measurem
try:
return (True, urequests.post(post, data=data))
except Exception as e:
if e.args[0] == 103:
return (False, b"ERROR sending data to influx: {}".format(e.args))
machine.reset()
else:
return (False, b"ERROR sending data to influx: {}".format(e))
return (False, b"ERROR sending data to influx: {}".format(e.args))
machine.reset()
return (False, b"ERROR - well fuck me, daisy")
def raw_send_to_influx(host, port, db, user, password, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, rssi, lqi):
post = "http://{}:{}/write?db={}".format(host, port, db)
@@ -53,9 +57,12 @@ def raw_send_to_influx(host, port, db, user, password, b0, b1, b2, b3, b4, b5, b
return (True, urequests.post(post, data=data))
except Exception as e:
if e.args[0] == 103:
return (False, b"ERROR sending data to influx: {}".format(e))
machine.reset()
else:
return (False, b"ERROR sending RAW data to influx: {}".format(e))
machine.reset()
return (False, b"ERROR - well fuck me, daisy")
def reverseBits(data):
data = "{:08b}".format(data)
@@ -242,4 +249,3 @@ class davisDecoder(object):
self.name = 'value'
self.tags = {'type': 'rain_bucket_tips'}
self.value = rain

12
main.py
View File

@@ -35,7 +35,7 @@ while True:
try:
data_int = davis.rxPacket()
except Exception as e:
raise e
#raise e
print(b"Rx EXCEPTION: {}".format(e))
continue
if data_int:
@@ -82,8 +82,11 @@ while True:
decoder.value,
decoder.tags)
except Exception as e:
raise e
#raise e
print(b"ERROR: Data send 'urequest': {}".format(e))
machine.reset()
#continue
gc.collect()
try:
(raw_sent_ok, raw_data_sent) = davis_decode.raw_send_to_influx(
wifi_con._INFLUX_HOST,
@@ -103,9 +106,12 @@ while True:
data_int[9],
davis.rssi,
davis.lqi)
gc.collect()
except Exception as e:
raise e
#raise e
print(b"ERROR: Data send 'urequest': {}".format(e))
machine.reset()
#continue
if DEBUG:
if sent_ok: