From 82db61c91fa28a535db0158969a1f3dc1b89f976 Mon Sep 17 00:00:00 2001 From: "Hansi, dl9rdz" Date: Thu, 31 Dec 2020 00:10:15 +0100 Subject: [PATCH] some reorg, gps factory def, ftp bugfix --- .travis.yml | 1 - README.md | 30 +++++++++------- RX_FSK/RX_FSK.ino | 35 ++++++++++++++++--- RX_FSK/version.h | 2 +- libraries/SondeLib/DFM.cpp | 2 +- libraries/SondeLib/Display.cpp | 10 +++--- libraries/SondeLib/M10M20.cpp | 3 +- .../{SX1278FSK => SondeLib}/SX1278FSK.cpp | 4 +-- libraries/{SX1278FSK => SondeLib}/SX1278FSK.h | 0 .../{ => SondeLib}/fonts/FreeMono12pt7b.h | 0 .../{ => SondeLib}/fonts/FreeMono9pt7b.h | 0 .../{ => SondeLib}/fonts/FreeSans12pt7b.h | 0 .../{ => SondeLib}/fonts/FreeSans9pt7b.h | 0 libraries/{ => SondeLib}/fonts/Picopixel.h | 0 libraries/SondeLib/geteph.cpp | 10 ++++-- platformio.ini | 6 ++-- 16 files changed, 68 insertions(+), 35 deletions(-) rename libraries/{SX1278FSK => SondeLib}/SX1278FSK.cpp (99%) rename libraries/{SX1278FSK => SondeLib}/SX1278FSK.h (100%) rename libraries/{ => SondeLib}/fonts/FreeMono12pt7b.h (100%) rename libraries/{ => SondeLib}/fonts/FreeMono9pt7b.h (100%) rename libraries/{ => SondeLib}/fonts/FreeSans12pt7b.h (100%) rename libraries/{ => SondeLib}/fonts/FreeSans9pt7b.h (100%) rename libraries/{ => SondeLib}/fonts/Picopixel.h (100%) diff --git a/.travis.yml b/.travis.yml index 1334483..a4f08be 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,7 +47,6 @@ install: - arduino --pref "build.path=$PWD/build" --save-prefs - arduino --install-boards esp32:esp32 --save-prefs - ln -s $PWD/libraries/SondeLib /usr/local/share/arduino/libraries/SondeLib - - ln -s $PWD/libraries/SX1278FSK /usr/local/share/arduino/libraries/SX1278FSK - arduino --install-library "U8g2" - arduino --install-library "MicroNMEA" script: diff --git a/README.md b/README.md index 2666c61..e1fe3f2 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,14 @@ RDZ_TTGO_SONDE ============== -This a simple, experimental, not (well) tested, and incomplete decoder for -radiosonde RS41 and DFM06/09 on a TTGO LoRa ESP32 with OLED display board. +This a simple, experimental decoder for radiosonde RS41, RS92, DFM06/09/17 and M10/M20 on +a TTGO LoRa ESP32 board with either a OLED or extern TFT display. -There have been made some additions for TTGO LoRa ESP32 with only RST button. -Please check also your OLED port settings, both versions use different ports. -You can setup the depending ports in config.txt, OLED Setup is depending on hardware of LoRa board -- TTGO v1: SDA=4 SCL=15, RST=16 -- TTGO v2: SDA=21 SCL=22, RST=16 +Please consult the Wiki at https://github.com/dl9rdz/rdz_ttgo_sonde/wiki/Supported-boards +for details on supported boardsi, and additional setup instructions. ## Button commands + You can use the button on the board (not the reset button, the second one) to issue some commands. The software distinguishes between several inputs: @@ -19,6 +17,10 @@ issue some commands. The software distinguishes between several inputs: - MID Medium-length button press (2-4 seconds) - LONG Long button press (>5 seconds) +You can optionally use a second button, which you have to add manually to your board. +See https://github.com/dl9rdz/rdz_ttgo_sonde/wiki/Hardware-configuration for details. + + ## Wireless configuration On startup, as well as after a LONG button press, the WiFI configuration will @@ -32,19 +34,23 @@ bottom line. Then the board will switch to scanning mode. ## Scanning mode In the scanning mode, the board will iterate over all channels configured in -channels.txt, trying to decode a radio sonde on each channel for about 1 second -for RS41, a bit less for DMF06/09. If a valid signal is found, the board switches -to receiving mode on that channel. a SHORT buttong press will also switch to -receiving mode. +channels.txt, trying to decode a radio sonde on each channel for about 1 second. +If a valid signal is found, the board switches to receiving mode on that channel. +A SHORT buttong press will also switch to receiving mode. ## Receiving mode In receiving mode, a single frequency will be decoded, and sonde info (ID, GPS coordinates, RSSI) will be displayed. The bar above the IP address indicates, -for the last 18 frames, if reception was successfull (|) or failed (.) +for the last 18 frames, if reception was successfull (|) or failed (.), or had +some errors (E), e.g., CRC check failed. + A DOUBLE press will switch to scanning mode. + A SHORT press will switch to the next channel in channels.txt +A SHORT press on the second button will switch to a different display screen. + ## Spectrum mode A medium press will active scan the whole band (400..406 MHz) and display a diff --git a/RX_FSK/RX_FSK.ino b/RX_FSK/RX_FSK.ino index 4f49bc7..ca7883c 100644 --- a/RX_FSK/RX_FSK.ino +++ b/RX_FSK/RX_FSK.ino @@ -79,6 +79,10 @@ static int currentDisplay = 1; // timestamp when spectrum display was activated static unsigned long specTimer; +void enterMode(int mode); +void WiFiEvent(WiFiEvent_t event); + + // Read line from file, independent of line termination (LF or CR LF) String readLine(Stream &stream) { String s = stream.readStringUntil('\n'); @@ -1134,6 +1138,7 @@ void unkHandler(T nmea) { Serial.printf("Course update: %d\n", lastCourse); } } +//#define DEBUG_GPS 1 void gpsTask(void *parameter) { nmea.setUnknownSentenceHandler(unkHandler); @@ -1142,7 +1147,8 @@ void gpsTask(void *parameter) { char c = Serial2.read(); //Serial.print(c); if (nmea.process(c)) { - //Serial.println(nmea.getSentence()); +#ifdef DEBUG_GPS + Serial.print(nmea.getSentence()); long lat = nmea.getLatitude(); long lon = nmea.getLongitude(); long alt = -1; @@ -1150,17 +1156,38 @@ void gpsTask(void *parameter) { bool valid = nmea.isValid(); int course = nmea.getCourse() / 1000; uint8_t hdop = nmea.getHDOP(); - //Serial.printf("\nDecode: valid: %d N %ld E %ld alt %ld (%d) course:%d dop:%d", valid ? 1 : 0, lat, lon, alt, b, c, hdop); + Serial.printf(" =>: valid: %d N %ld E %ld alt %ld (%d) course:%d dop:%d\n", valid ? 1 : 0, lat, lon, alt, b, c, hdop); +#endif } } delay(50); } } +#define UBX_SYNCH_1 0xB5 +#define UBX_SYNCH_2 0x62 +uint8_t ubx_set9k6[]={UBX_SYNCH_1, UBX_SYNCH_2, 0x06, 0x00, 0x14, 0x00, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x08, 0x00, 0x00, 0x80, 0x25, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8D, 0x8F}; +uint8_t ubx_factorydef[]={UBX_SYNCH_1, UBX_SYNCH_2, 0x06, 0x09, 13, 0, 0xff, 0xff, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0x17, 0x8A }; + void initGPS() { if (sonde.config.gps_rxd < 0) return; // GPS disabled - Serial2.begin(9600, SERIAL_8N1, sonde.config.gps_rxd, sonde.config.gps_txd); - + if (sonde.config.gps_txd >= 0) { // TX enable, thus try setting baud to 9600 and do a factory reset + Serial.println("Trying to reset GPS..."); + Serial2.begin(115200, SERIAL_8N1, sonde.config.gps_rxd, sonde.config.gps_txd); + Serial2.write(ubx_set9k6, sizeof(ubx_set9k6)); + delay(100); + Serial2.begin(38400, SERIAL_8N1, sonde.config.gps_rxd, sonde.config.gps_txd); + Serial2.write(ubx_set9k6, sizeof(ubx_set9k6)); + delay(100); + Serial2.begin(19200, SERIAL_8N1, sonde.config.gps_rxd, sonde.config.gps_txd); + Serial2.write(ubx_set9k6, sizeof(ubx_set9k6)); + delay(100); + Serial2.begin(9600, SERIAL_8N1, sonde.config.gps_rxd, sonde.config.gps_txd); + Serial2.write(ubx_factorydef, sizeof(ubx_factorydef)); + delay(1000); + } else { + Serial2.begin(9600, SERIAL_8N1, sonde.config.gps_rxd, sonde.config.gps_txd); + } xTaskCreate( gpsTask, "gpsTask", 5000, /* stack size */ NULL, /* paramter */ diff --git a/RX_FSK/version.h b/RX_FSK/version.h index 31d7487..311a1e6 100644 --- a/RX_FSK/version.h +++ b/RX_FSK/version.h @@ -1,4 +1,4 @@ const char *version_name = "rdzTTGOsonde"; -const char *version_id = "devel20201230"; +const char *version_id = "devel20201230b"; const int SPIFFS_MAJOR=2; const int SPIFFS_MINOR=8; diff --git a/libraries/SondeLib/DFM.cpp b/libraries/SondeLib/DFM.cpp index 93c47be..5c34975 100644 --- a/libraries/SondeLib/DFM.cpp +++ b/libraries/SondeLib/DFM.cpp @@ -591,7 +591,7 @@ int DFM::receiveOld() { for(int i=0; i<2; i++) { sx1278.setPayloadLength(33); // Expect 33 bytes (7+13+13 bytes) sx1278.writeRegister(REG_OP_MODE, FSK_RX_MODE); - int t = millis(); + //int t = millis(); int e = sx1278.receivePacketTimeout(1000, data); //Serial.printf("rxPTO done after %d ms", (int)(millis()-t)); if(e) { return RX_TIMEOUT; } //if timeout... return 1 diff --git a/libraries/SondeLib/Display.cpp b/libraries/SondeLib/Display.cpp index c8524f4..ea53154 100644 --- a/libraries/SondeLib/Display.cpp +++ b/libraries/SondeLib/Display.cpp @@ -11,11 +11,11 @@ int readLine(Stream &stream, char *buffer, int maxlen); extern const char *version_name; extern const char *version_id; -#include <../fonts/FreeMono9pt7b.h> -#include <../fonts/FreeMono12pt7b.h> -#include <../fonts/FreeSans9pt7b.h> -#include <../fonts/FreeSans12pt7b.h> -#include <../fonts/Picopixel.h> +#include +#include +#include +#include +#include extern Sonde sonde; diff --git a/libraries/SondeLib/M10M20.cpp b/libraries/SondeLib/M10M20.cpp index d6aa9cb..0b2c38f 100644 --- a/libraries/SondeLib/M10M20.cpp +++ b/libraries/SondeLib/M10M20.cpp @@ -23,7 +23,7 @@ static uint8_t rxbitc; static uint16_t rxbyte; static int rxp=0; static int haveNewFrame = 0; -static int lastFrame = 0; +//static int lastFrame = 0; static int headerDetected = 0; int M10M20::setup(float frequency) @@ -195,7 +195,6 @@ static uint16_t crc_M10M20(int len, uint8_t *msg) { return cs; } static bool checkM10M20crc(int crcpos, uint8_t *msg) { - int i; uint16_t cs, cs1; cs = crc_M10M20(crcpos, msg); cs1 = (msg[crcpos] << 8) | msg[crcpos+1]; diff --git a/libraries/SX1278FSK/SX1278FSK.cpp b/libraries/SondeLib/SX1278FSK.cpp similarity index 99% rename from libraries/SX1278FSK/SX1278FSK.cpp rename to libraries/SondeLib/SX1278FSK.cpp index 4fb90a5..ecb7fdc 100644 --- a/libraries/SX1278FSK/SX1278FSK.cpp +++ b/libraries/SondeLib/SX1278FSK.cpp @@ -164,8 +164,8 @@ void SX1278FSK::writeRegister(byte address, byte data) */ void SX1278FSK::clearIRQFlags() { - byte st0; #if 0 + byte st0; // Save the previous status st0 = readRegister(REG_OP_MODE); // Stdby mode to write in registers @@ -197,7 +197,7 @@ uint8_t SX1278FSK::setFSK() { uint8_t state = 2; byte st0; - byte config1; + //byte config1; #if (SX1278FSK_debug_mode > 1) Serial.println(); diff --git a/libraries/SX1278FSK/SX1278FSK.h b/libraries/SondeLib/SX1278FSK.h similarity index 100% rename from libraries/SX1278FSK/SX1278FSK.h rename to libraries/SondeLib/SX1278FSK.h diff --git a/libraries/fonts/FreeMono12pt7b.h b/libraries/SondeLib/fonts/FreeMono12pt7b.h similarity index 100% rename from libraries/fonts/FreeMono12pt7b.h rename to libraries/SondeLib/fonts/FreeMono12pt7b.h diff --git a/libraries/fonts/FreeMono9pt7b.h b/libraries/SondeLib/fonts/FreeMono9pt7b.h similarity index 100% rename from libraries/fonts/FreeMono9pt7b.h rename to libraries/SondeLib/fonts/FreeMono9pt7b.h diff --git a/libraries/fonts/FreeSans12pt7b.h b/libraries/SondeLib/fonts/FreeSans12pt7b.h similarity index 100% rename from libraries/fonts/FreeSans12pt7b.h rename to libraries/SondeLib/fonts/FreeSans12pt7b.h diff --git a/libraries/fonts/FreeSans9pt7b.h b/libraries/SondeLib/fonts/FreeSans9pt7b.h similarity index 100% rename from libraries/fonts/FreeSans9pt7b.h rename to libraries/SondeLib/fonts/FreeSans9pt7b.h diff --git a/libraries/fonts/Picopixel.h b/libraries/SondeLib/fonts/Picopixel.h similarity index 100% rename from libraries/fonts/Picopixel.h rename to libraries/SondeLib/fonts/Picopixel.h diff --git a/libraries/SondeLib/geteph.cpp b/libraries/SondeLib/geteph.cpp index ba78522..9f86273 100644 --- a/libraries/SondeLib/geteph.cpp +++ b/libraries/SondeLib/geteph.cpp @@ -136,9 +136,13 @@ void geteph() { int len=0; while(dclient.connected()) { while(dclient.available()) { - char c = dclient.read(); - fh.write(c); - len++; + int c = dclient.read(); + if(c==-1) { + Serial.println("dclient.read() returned -1 inspite of available() being true?!"); + } else { + fh.write(c); + len++; + } } } Serial.printf("fetched %d bytes\n", len); diff --git a/platformio.ini b/platformio.ini index 9fdd1cc..c36dff3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -16,13 +16,11 @@ data_dir = RX_FSK/data [extra] lib_deps_builtin = SondeLib - SX1278FSK - fonts lib_deps_external = olikraus/U8g2 @ ^2.28.8 AXP202X_Library - stevemarple/MicroNMEA @ ^2.0.3 - nkawu/TFT 22 ILI9225 @ ^1.4.4 + stevemarple/MicroNMEA @ ^2.0.5 +; nkawu/TFT 22 ILI9225 @ ^1.4.4 me-no-dev/ESP Async WebServer @ ^1.2.3 https://github.com/dx168b/async-mqtt-client