From 095fbf52f5a23c17acada04f77d9d50e6107c71f Mon Sep 17 00:00:00 2001 From: Milan Ventil Toman Date: Tue, 2 Jun 2020 14:54:54 +0200 Subject: [PATCH] freq comp added --- cc1101_davis.mpy | Bin 7979 -> 8147 bytes cc1101_davis.py | 8 ++++++++ main.py | 31 ++++++++++++++++++++++++++++--- readme.md | 24 ++++++++++++------------ 4 files changed, 48 insertions(+), 15 deletions(-) diff --git a/cc1101_davis.mpy b/cc1101_davis.mpy index 384f59a96e24619aeabb63b1b75a16107dfd542e..e2c622fd603ceb59084fdcf262ab2a6cf8f8f0a1 100644 GIT binary patch delta 390 zcmZ2&ciDczR%Q=|fQdU~IXGL{TRB=eQzzcJq+lc{CY79+lk8TMTIgC-lwTB>%pi0) zqO+kvpoNV=P<8TN#uJQ&o7V%o+#n*jL6{jR0unT10`g6Pd^5(#z+^@ShR$M>fTGmm)Vvafvc#OyR4aw*S{;S( zAkPp_KX)KoT_MC@0o6_geV}-ggOM0B?}R*cLqkJ`4I;*q@5rVqaHZvx7H60-0F7n< z8qE;Xm=G<&2lBpiQL^ZS(#bJ$QCzj!8af&tKt1Y{&&c_Bw*groruVHI q5 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)) self.writeRegister(self.CC1101_FSCTRL0, self.freqComp[self.hopIndex]) self.setFrequency(self.hopIndex) # Set the frequency. @@ -388,3 +390,9 @@ class CC1101(object): def readLQI(self): return self.readRegister(self.CC1101_RXFIFO) & 0x7F + def calcFreqError(self, value): + if value >= 128: + error = (value - 256) >> 1 + else: + error = value >> 1 + return error diff --git a/main.py b/main.py index a091243..328f5c0 100644 --- a/main.py +++ b/main.py @@ -4,7 +4,20 @@ import utime import WiFi gc.collect() +#_SSID = 'BastArt' +#_PASS = '3 litry Kvasaru!' +#_TIMEOUT = 15 _DEBUG = False +# +#_INFLUX_HOST = '192.168.1.2' +#_INFLUX_PORT = '8086' +#_INFLUX_USER = 'ventil' +#_INFLUX_PASS = '3 litry Kvasaru!' +# +#_INF_DB_WEATHER = 'weather' +#_INF_DB_STATUS = 'status' +#_INF_DB_RAW = 'raw' + wifi_con = WiFi.NetSet('infra') wifi_con.readNetworkConfig() @@ -25,6 +38,7 @@ decoder = davis_decode.davisDecoder( wifi_con._INF_DB_RAW) # Main receive loop +interpacket_time = 0 while True: data_length = davis.readRegister(davis.CC1101_RXBYTES) data = "" @@ -32,6 +46,14 @@ while True: data = davis.readBurst(davis.CC1101_RXFIFO, 10) rssi = davis.readRssi() 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 davis.freqComp[davis.hopIndex] + freqEst <= 255: + davis.freqComp[davis.hopIndex] = davis.freqComp[davis.hopIndex] + freqEst + else: + davis.freqComp[davis.hopIndex] = 255 hop = davis.hopIndex davis.flush() davis.hop() @@ -49,12 +71,13 @@ while True: data_int[6], data_int[7], data_int[8], - data_int[8],) - print("{_data:60} HOP: {_hop:<5} RSSI: {_rssi:<5} LQI: {_lqi:<5}".format( + data_int[9]) + print("{_data:60} HOP: {_hop:<5} RSSI: {_rssi:<5} LQI: {_lqi:<5} {_last}s since".format( _rssi=rssi, _hop=hop, _data=data_prn, - _lqi=lqi)) + _lqi=lqi, + _last=interpacket_time / 10)) if _DEBUG: print("Header: {} Wind: {}".format(header, decoder.wind)) print("{}: {}/{} ({})".format( @@ -84,6 +107,8 @@ while True: print("DATA SEND: {}".format(data_sent.status_code)) else: print("DATA SEND FAIL: {}".format(data_sent)) + interpacket_time = 0 else: + interpacket_time += 1 utime.sleep_ms(100) gc.collect() diff --git a/readme.md b/readme.md index dc1b8bb..b0f3a3a 100644 --- a/readme.md +++ b/readme.md @@ -1,11 +1,11 @@ -#ESP8266 + CC1101 Davis weather station wifi logger +# ESP8266 + CC1101 Davis weather station wifi logger The intention is to gather data from a Weather station made by Davis. In this case a Vantage Vue (integrated all sensors in one package) and push them directly to an InfluxDB instance via WiFi. -##Prerequisites: +## Prerequisites: - WiFi available, plus access to it. (WPA2 PSK preferred) - Running INfluxDB instance on the same network - ESP8266 microcontroller (NodeMCU 8266 preferred) @@ -16,8 +16,8 @@ push them directly to an InfluxDB instance via WiFi. - a couple wires, need to solder those tiny CC1101 pins and wires. - 5V / 3.3V source, depending on what version of ESP you get. A stable 3.3V is preferred -##Quick setup of HW: -###1. Interconnect these pins: +## Quick setup of HW: +### 1. Interconnect these pins: The pins are marked on the NodeMcu ESP8266, on the CC1101 module, pins are counted from left, if you face the chip towards you. ESP8266 | ESP8266 description | CC1101 | CC1101 description | @@ -34,13 +34,13 @@ ESP8266 | ESP8266 description | CC1101 | CC1101 description | IO pin GDO0, currently configured as interrupt, when new packet is received (i.e. goes HIGH). This currently just to lights up a led, interrupt based receive is not implemented, though sounds cool. -###2. Clone this repo, get Micropython +### 2. Clone this repo, get Micropython ``` git clone https://bastart.spoton.cz/git/Ventil/esp8266_CC1101_davis_vantage_vue.git cd esp8266_CC1101_davis_vantage_vue wget https://micropython.org/resources/firmware/esp8266-20191220-v1.12.bin -P /tmp ``` -###3. Upload Micropython, check +### 3. Upload Micropython, check Need to delete the flash first, then write the custom firmware. You need to determine which device is the one to write to. If you have only one ESP8266, you are probably safe to use the ttyUSB0, @@ -121,7 +121,7 @@ Terminal ready ``` Exit from the console with Ctrl + A + X or ampy will not be able to list files on the esp8266 -###4. Freeze modules, or just upload the .mpy files +### 4. Freeze modules, or just upload the .mpy files You can simply upload all the modules in question. If you modify anything in the .py files, you need to freeze them again with mpy-cross ``` @@ -138,9 +138,9 @@ WiFi.mpy <-- the newly compiled (frozen) module WiFi.py ``` -###5. Modify inet.conf +### 5. Modify inet.conf Before uploading the inte.conf, please change it to your desired values. -###6, Upload files +### 6, Upload files ``` /usr/bin/ampy -p /dev/ttyUSB1 put boot.py /usr/bin/ampy -p /dev/ttyUSB1 put main.py @@ -155,7 +155,7 @@ Before uploading the inte.conf, please change it to your desired values. /main.py ``` -###7. If you haven't already, create 2 DBs in inclux +### 7. If you haven't already, create 2 DBs in inclux I am tempted to push the raw, undecoded data to a DB as well, but influx is not siutd for this. You can ignore the last DB creation ``` ssh 192.168.1.2 @@ -164,7 +164,7 @@ create database weather create database status create database raw ``` -###8. Restart esp8266, check data on serial +### 8. Restart esp8266, check data on serial ``` picocom -b 115200 /dev/ttyUSB1 picocom v3.1 @@ -310,7 +310,7 @@ If you are interested in the packet format, please: 224 13 3 17 3 3 32 253 255 255 HOP: 1 RSSI: -68.5 LQI: 127 ``` -###9, explore data in Influx +### 9, explore data in Influx You're all set, let's look at the data ``` ssh 192.168.1.2