Removed the RAW db data push, Build with upython.14 compatible. Return values from urequests (-2,0) in observation
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import utime
|
||||
import gc
|
||||
import machine
|
||||
_DEBUG = True
|
||||
|
||||
ss = machine.Pin(15,machine.Pin.OUT) # Chip select / HCS
|
||||
so = machine.Pin(12) # HMISO
|
||||
@@ -412,9 +413,9 @@ class CC1101(object):
|
||||
self.lqi = self.readLQI()
|
||||
freqEst = self.readStatus(self.CC1101_FREQEST)
|
||||
freqError = self.calcFreqError(freqEst)
|
||||
if DEBUG:
|
||||
if _DEBUG:
|
||||
print(b"FERROR: {} (EST: {})".format(freqError, freqEst))
|
||||
print(b"FCOMP: {}".format(davis.freqComp))
|
||||
print(b"FCOMP: {}".format(self.freqComp))
|
||||
if self.freqComp[self.hopIndex] + freqEst <= 255:
|
||||
self.freqComp[self.hopIndex] = self.freqComp[self.hopIndex] + freqEst
|
||||
else:
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import urequests
|
||||
import machine
|
||||
|
||||
try:
|
||||
_DEBUG = DEBUG
|
||||
except:
|
||||
_DEBUG = False
|
||||
_DEBUG = True
|
||||
|
||||
def send_to_influx(host, port, db, user, password, davis_unit_id, wind, measurement, name, value, tags):
|
||||
post = "http://{}:{}/write?db={}".format(host, port, db)
|
||||
@@ -34,34 +33,10 @@ 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.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)
|
||||
if _DEBUG:
|
||||
print(b"SENDING TO: {}".format(post))
|
||||
data = "data b0={_b0},b1={_b1},b2={_b2},b3={_b3},b4={_b4},b5={_b5},b6={_b6},b7={_b7},b8={_b8},b9={_b9},rssi={_rssi},lqi={_lqi}".format(
|
||||
_b0=b0, _b1=b1, _b2=b2, _b3=b3,
|
||||
_b4=b4, _b5=b5, _b6=b6, _b7=b7,
|
||||
_b8=b8, _b9=b9, _rssi=rssi, _lqi=lqi)
|
||||
if _DEBUG:
|
||||
print(b"POST_DATA: {}".format(data))
|
||||
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))
|
||||
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):
|
||||
@@ -73,11 +48,10 @@ def reverseBits(data):
|
||||
|
||||
|
||||
class davisDecoder(object):
|
||||
def __init__(self, weather_db, stat_db, raw_db):
|
||||
def __init__(self, weather_db, stat_db):
|
||||
__name__ = 'Davis value decoder class'
|
||||
self.weather_influx_db = weather_db
|
||||
self.stat_influx_db = stat_db
|
||||
self.raw_influx_db = raw_db
|
||||
|
||||
def byte_split(self, data):
|
||||
msb = data >> 4
|
||||
|
||||
37
main.py
37
main.py
@@ -3,6 +3,7 @@ import davis_decode
|
||||
import utime
|
||||
import WiFi
|
||||
import machine
|
||||
import micropython
|
||||
gc.collect()
|
||||
|
||||
DEBUG = True
|
||||
@@ -16,7 +17,6 @@ ips = wifi_con.connectInfra(
|
||||
|
||||
if DEBUG:
|
||||
print("IPCONF: {}".format(ips))
|
||||
|
||||
gc.collect()
|
||||
|
||||
davis = cc1101_davis.CC1101()
|
||||
@@ -24,8 +24,7 @@ davis.setRegisters()
|
||||
davis.setFrequency(davis.hopIndex)
|
||||
decoder = davis_decode.davisDecoder(
|
||||
wifi_con._INF_DB_WEATHER,
|
||||
wifi_con._INF_DB_STATUS,
|
||||
wifi_con._INF_DB_RAW)
|
||||
wifi_con._INF_DB_STATUS)
|
||||
|
||||
gc.collect()
|
||||
|
||||
@@ -83,41 +82,17 @@ while True:
|
||||
decoder.tags)
|
||||
except Exception as e:
|
||||
#raise e
|
||||
print(b"ERROR: Data send 'urequest': {}".format(e))
|
||||
machine.reset()
|
||||
#continue
|
||||
if _DEBUG:
|
||||
print(b"ERROR: Data send 'urequest': {}".format(e))
|
||||
gc.collect()
|
||||
try:
|
||||
(raw_sent_ok, raw_data_sent) = davis_decode.raw_send_to_influx(
|
||||
wifi_con._INFLUX_HOST,
|
||||
wifi_con._INFLUX_PORT,
|
||||
decoder.raw_influx_db,
|
||||
wifi_con._INFLUX_USER,
|
||||
wifi_con._INFLUX_PASS,
|
||||
data_int[0],
|
||||
data_int[1],
|
||||
data_int[2],
|
||||
data_int[3],
|
||||
data_int[4],
|
||||
data_int[5],
|
||||
data_int[6],
|
||||
data_int[7],
|
||||
data_int[8],
|
||||
data_int[9],
|
||||
davis.rssi,
|
||||
davis.lqi)
|
||||
gc.collect()
|
||||
except Exception as e:
|
||||
#raise e
|
||||
print(b"ERROR: Data send 'urequest': {}".format(e))
|
||||
machine.reset()
|
||||
#continue
|
||||
|
||||
if DEBUG:
|
||||
if sent_ok:
|
||||
print(b"DATA SEND: {}".format(data_sent.status_code))
|
||||
else:
|
||||
print(b"DATA SEND FAIL: {}".format(data_sent))
|
||||
if data_sent[0] == -2:
|
||||
machine.reset()
|
||||
interpacket_time = 0
|
||||
else:
|
||||
interpacket_time += 1
|
||||
|
||||
Reference in New Issue
Block a user