CRC checks, wifi ECONABORT sorted to machine.reset()
This commit is contained in:
BIN
cc1101_davis.mpy
BIN
cc1101_davis.mpy
Binary file not shown.
@@ -359,7 +359,7 @@ class CC1101(object):
|
||||
if (self.hopIndex > 4): # 5 EU frequencies
|
||||
self.hopIndex = 0
|
||||
present = self.readRegister(self.CC1101_FSCTRL0)
|
||||
print("Present value: {}, WRITING {} TO CC1101_FSCTRL0 / {}".format(present, self.freqComp[self.hopIndex], self.CC1101_FSCTRL0))
|
||||
# DEBUG print("Present value: {}, WRITING {} TO CC1101_FSCTRL0 / {}".format(present, self.freqComp[self.hopIndex], self.CC1101_FSCTRL0))
|
||||
self.writeRegister(self.CC1101_FSCTRL0, self.freqComp[self.hopIndex])
|
||||
self.setFrequency(self.hopIndex) # Set the frequency.
|
||||
|
||||
@@ -370,12 +370,11 @@ class CC1101(object):
|
||||
self.writeRegister(self.CC1101_FREQ0, self.FREQ_0[index])
|
||||
self.flush()
|
||||
|
||||
def calcCrc(self, _buffer, length):
|
||||
def calcCrc(self, _buffer):
|
||||
crc = 0x0000
|
||||
buffer_index = 0
|
||||
for i in range(length, 0, -1):
|
||||
crc = (crc << 8) ^ self.CRC_TABLE[(crc >> 8) ^ (_buffer[buffer_index])]
|
||||
buffer_index += 1
|
||||
for i in range(0, len(_buffer)):
|
||||
crc = ((crc << 8) ^ self.CRC_TABLE[(crc >> 8) ^ (_buffer[i])]) % 65536
|
||||
# DEBUG print("CRC: {}".format(crc))
|
||||
return crc
|
||||
|
||||
def readRssi(self):
|
||||
|
||||
BIN
davis_decode.mpy
BIN
davis_decode.mpy
Binary file not shown.
@@ -1,5 +1,5 @@
|
||||
import urequests
|
||||
|
||||
import machine
|
||||
|
||||
_DEBUG = False
|
||||
|
||||
@@ -32,8 +32,28 @@ 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:
|
||||
return (False, "ERROR sending data to influx: {}".format(e))
|
||||
if e.args[0] == 103:
|
||||
machine.reset()
|
||||
else:
|
||||
return (False, "ERROR sending data to influx: {}".format(e))
|
||||
|
||||
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("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("POST_DATA: {}".format(data))
|
||||
try:
|
||||
return (True, urequests.post(post, data=data))
|
||||
except Exception as e:
|
||||
if e.args[0] == 103:
|
||||
machine.reset()
|
||||
else:
|
||||
return (False, "ERROR sending RAW data to influx: {}".format(e))
|
||||
|
||||
def reverseBits(data):
|
||||
data = "{:08b}".format(data)
|
||||
|
||||
37
main.py
37
main.py
@@ -2,12 +2,13 @@ import cc1101_davis
|
||||
import davis_decode
|
||||
import utime
|
||||
import WiFi
|
||||
import machine
|
||||
gc.collect()
|
||||
|
||||
#_SSID = 'BastArt'
|
||||
#_PASS = '3 litry Kvasaru!'
|
||||
#_TIMEOUT = 15
|
||||
_DEBUG = False
|
||||
_DEBUG = True
|
||||
#
|
||||
#_INFLUX_HOST = '192.168.1.2'
|
||||
#_INFLUX_PORT = '8086'
|
||||
@@ -48,8 +49,9 @@ while True:
|
||||
lqi = davis.readLQI()
|
||||
freqEst = davis.readStatus(davis.CC1101_FREQEST)
|
||||
freqError = davis.calcFreqError(freqEst)
|
||||
print("FERROR: {} (EST: {})".format(freqError, freqEst))
|
||||
print("FCOMP: {}".format(davis.freqComp))
|
||||
if _DEBUG:
|
||||
print("FERROR: {} (EST: {})".format(freqError, freqEst))
|
||||
print("FCOMP: {}".format(davis.freqComp))
|
||||
if davis.freqComp[davis.hopIndex] + freqEst <= 255:
|
||||
davis.freqComp[davis.hopIndex] = davis.freqComp[davis.hopIndex] + freqEst
|
||||
else:
|
||||
@@ -59,6 +61,12 @@ while True:
|
||||
davis.hop()
|
||||
davis.rx()
|
||||
data_int = [davis_decode.reverseBits(int(item)) for item in data]
|
||||
crc = davis.calcCrc(data_int[:8])
|
||||
if crc != 0x0000:
|
||||
print("Corrupt data CRC: {}".format(crc))
|
||||
continue
|
||||
else:
|
||||
print("Data OK, CRC: {}".format(crc))
|
||||
header = decoder.davis_id(data_int[0])
|
||||
decoder.DecodePacket(data_int)
|
||||
data_prn = "{:5} {:5} {:5} {:5} {:5} {:5} {:5} {:5} {:5} {:5}".format(
|
||||
@@ -87,6 +95,7 @@ while True:
|
||||
decoder.tags))
|
||||
sent_ok = False
|
||||
data_sent = None
|
||||
gc.collect()
|
||||
try:
|
||||
(sent_ok, data_sent) = davis_decode.send_to_influx(
|
||||
wifi_con._INFLUX_HOST,
|
||||
@@ -102,6 +111,28 @@ while True:
|
||||
decoder.tags)
|
||||
except Exception as e:
|
||||
print("ERROR: Data send 'urequest': {}".format(e))
|
||||
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],
|
||||
rssi,
|
||||
lqi)
|
||||
except Exception as e:
|
||||
print("ERROR: Data send 'urequest': {}".format(e))
|
||||
|
||||
if _DEBUG:
|
||||
if sent_ok:
|
||||
print("DATA SEND: {}".format(data_sent.status_code))
|
||||
|
||||
Reference in New Issue
Block a user