From db1ee46dc1c72830404c15b197b7b6a25d323f31 Mon Sep 17 00:00:00 2001 From: Thomas Osterried Date: Thu, 24 Aug 2023 19:55:01 +0200 Subject: [PATCH] features: exernal gps, usbserial nmea. changed: aprsis-connect wait time 1. usb-serial: option for output gps nmea sentences I patched taskGPS.cpp this for an om a few months ago. Unexpectedly, I pushed this change to github with my last push a few days ago. -> I needed to implent this feature now, because else gps nmea output was sent uninterruptable. I needed to add a small change to taskGPS.cpp. You can enable this in the webinterface tnc mode now also has the option to enable nmea (like the logging and trace command). 2. Feature for those who attached a GPS to a non-gps-tracker like the lora32 device. - GPS speed for those devices is currently hardcoded accordnig to the need of one OM (the way it was already hardcoded for T-BEAM devices) Perhaps it will become a web-configurable featuee - new compile time option FORCE_ENABLE_GPS for your platform.ini if you use a non-T-BEAM hardware (-> gps_state = true) - in setup_phase2_soft_reconfiguration I removed the condition #else 3. On aprsis-connection setup, we waited up to 25s for login prompt. -> The webinterface is unresponsive for this time. connect_to_aprsis() is a sub sub function from the main loop with many checked conditions like variables and retry times. A better solution would need a major redesign. => the wait time for the prompt is now 5s. 4. removed block if (curr_hdop < bestHdop && curr_sats >= 4) { do_update = 1; } else because bestHdop always <= curr_hdop (assignment above) -> This condition was always false, and it is obsolete (came from a time when experimenting for best values, and where the assignment bestHdop = curr_hdop was done after that block). Signed-off-by: Thomas Osterried --- data_embed/index.html | 8 ++++-- src/TTGO_T-Beam_LoRa_APRS.ino | 52 ++++++++++++++++++++++++----------- src/taskGPS.cpp | 8 ++++-- src/taskWebServer.cpp | 2 +- 4 files changed, 49 insertions(+), 21 deletions(-) diff --git a/data_embed/index.html b/data_embed/index.html index 02fd50d..4bae33d 100644 --- a/data_embed/index.html +++ b/data_embed/index.html @@ -553,8 +553,12 @@ III: Values above are referring to latitude; distance between two latitudes is a - - + + + + + +
diff --git a/src/TTGO_T-Beam_LoRa_APRS.ino b/src/TTGO_T-Beam_LoRa_APRS.ino index 24ad7d9..8ccaee7 100644 --- a/src/TTGO_T-Beam_LoRa_APRS.ino +++ b/src/TTGO_T-Beam_LoRa_APRS.ino @@ -192,7 +192,8 @@ int position_ambiguity = 0; // 0: default, compressed. -1: uncompressed. -2: unc String aprsPresetShown = "P"; //double lastTxdistance = 0; -#if defined(T_BEAM_V1_2) || defined(T_BEAM_V1_0) || defined(T_BEAM_V0_7) +#if defined(T_BEAM_V1_2) || defined(T_BEAM_V1_0) || defined(T_BEAM_V0_7) || defined(FORCE_ENABLE_GPS) + // ^ may used as compile time define boolean gps_state = true; #else boolean gps_state = false; @@ -449,8 +450,10 @@ bool acceptOwnPositionReportsViaKiss = true; // true: Switches off local beacon boolean gps_allow_sleep_while_kiss = true; // user has a kiss device attached via kiss which sends positions with own call, we don't need our gps to be turned on -> We pause sending positions by ourself (neither fixed nor smart beaconing). Except: user has a display attached to this tracker, he'll will be able to see his position because our gps does not go to sleep (-> set this to false). Why sleep? Energy saving boolean wifi_do_fallback_to_mode_AP = true; // Allow fallback to mode AP after once connected successfully connected (after boot) to configured remote AP. Disable for igates, where you don't need your tracker to be a hotspot. You like to enable, if you use your tracker portable and it should automatically be wifi client to your home network, and be AP if you are outside. boolean send_status_message_to_aprsis = true; // Send reboot, wifi- or internet-loss as APPRS-status-message to APRS-IS -uint8_t usb_serial_data_type = 0; // 0: KISS. 1: Display some debug messages on serial port. 2: Display lora-received packets in TNC trace format. 3: 1+2 +uint8_t usb_serial_data_type = 0; // 0: KISS. 1: Display some debug messages on serial port. 2: Display lora-received packets in TNC trace format. 3: 1+2. 4: Send GPS NMEA sentences. // If >0 usb-serial KISS-send and KISS-receive are stoped. + // Unfortunately, 0 was pre-set for kiss. -> There's no real-off. + // Because we test on set bits, number 128 (binary 10000000) means "off". #ifdef KISS_PROTOCOL // do not configure @@ -3374,8 +3377,6 @@ void setup_phase2_soft_reconfiguration(boolean runtime_reconfiguration) { //#elif T_BEAM_V1_2 // axp.enableXXX(); // switch this on if you need it //#endif - #else - gps_state = false; #endif gps_state_before_autochange = false; @@ -4684,6 +4685,7 @@ void handle_usb_serial_input(void) { Serial.println(" save_wifi_cfg (saves running wifi config to /wifi.cfg in filesystem)"); Serial.println(" dir (lists SPIFFS directory)"); #endif + Serial.println(" nmea "); Serial.println(" trace "); Serial.println(" reboot"); #if defined(T_BEAM_V1_0) || defined(T_BEAM_V1_2) @@ -4739,12 +4741,12 @@ void handle_usb_serial_input(void) { if (arg != "") { if (arg_bool) { usb_serial_data_type |= 1; - usb_serial_data_type &= ~4; + usb_serial_data_type &= ~128; } else { // avoid going to kiss mode (!usb_serial_data_type) usb_serial_data_type &= ~1; if (!usb_serial_data_type) - usb_serial_data_type = 4; + usb_serial_data_type = 128; } #ifdef ENABLE_PREFERENCES preferences.putInt(PREF_DEV_USBSERIAL_DATA_TYPE, usb_serial_data_type); @@ -4759,12 +4761,12 @@ void handle_usb_serial_input(void) { if (arg != "") { if (arg_bool) { usb_serial_data_type |= 2; - usb_serial_data_type &= ~4; + usb_serial_data_type &= ~128; } else { // avoid going to kiss mode (!usb_serial_data_type) usb_serial_data_type &= ~2; if (!usb_serial_data_type) - usb_serial_data_type = 4; + usb_serial_data_type = 128; } #ifdef ENABLE_PREFERENCES preferences.putInt(PREF_DEV_USBSERIAL_DATA_TYPE, usb_serial_data_type); @@ -4772,9 +4774,29 @@ void handle_usb_serial_input(void) { if (debug_verbose) syslog_log(LOG_DEBUG, String("FlashWrite preferences: handle_usb_serial_input() 2")); #endif - #endif - } - Serial.println("*** " + cmd + " is " + ((usb_serial_data_type & 2) ? "on" : "off")); + #endif + } + Serial.println("*** " + cmd + " is " + ((usb_serial_data_type & 2) ? "on" : "off")); + } else if (cmd == "nmea") { + if (arg != "") { + if (arg_bool) { + usb_serial_data_type |= 4; + usb_serial_data_type &= ~128; + } else { + // avoid going to kiss mode (!usb_serial_data_type) + usb_serial_data_type &= ~4; + if (!usb_serial_data_type) + usb_serial_data_type = 128; + } + #ifdef ENABLE_PREFERENCES + preferences.putInt(PREF_DEV_USBSERIAL_DATA_TYPE, usb_serial_data_type); + #if defined(ENABLE_SYSLOG) + if (debug_verbose) + syslog_log(LOG_DEBUG, String("FlashWrite preferences: handle_usb_serial_input() 3")); + #endif + #endif + } + Serial.println("*** " + cmd + " is " + ((usb_serial_data_type & 4) ? "on" : "off")); #ifdef ENABLE_WIFI } else if (cmd == "aprsis") { if (arg != "") { @@ -4782,7 +4804,7 @@ void handle_usb_serial_input(void) { preferences.putBool(PREF_APRSIS_EN, arg_bool); #if defined(ENABLE_SYSLOG) if (debug_verbose) - syslog_log(LOG_DEBUG, String("FlashWrite preferences: handle_usb_serial_input() 3")); + syslog_log(LOG_DEBUG, String("FlashWrite preferences: handle_usb_serial_input() 4")); #endif } Serial.println("*** " + cmd + " is " + (aprsis_enabled ? "on" : "off")); @@ -4792,7 +4814,7 @@ void handle_usb_serial_input(void) { preferences.putInt(PREF_WIFI_ENABLE, (arg_bool) ? 0 : 1); #if defined(ENABLE_SYSLOG) if (debug_verbose) - syslog_log(LOG_DEBUG, String("FlashWrite preferences: handle_usb_serial_input() 4")); + syslog_log(LOG_DEBUG, String("FlashWrite preferences: handle_usb_serial_input() 5")); #endif #endif if (arg_bool) { @@ -5018,9 +5040,7 @@ debug_bestHdop = bestHdop; } uint32_t t_elapsed = millis() - t_interval_start; - if (curr_hdop < bestHdop && curr_sats >= 4) { - do_update = 1; - } else if (t_elapsed > 15000L && ((curr_hdop < 1.5 && curr_sats >= 5) || no_gps_position_since_boot)) { + if (t_elapsed > 15000L && ((curr_hdop < 1.5 && curr_sats >= 5) || no_gps_position_since_boot)) { // Approach to avoid gps inaccuracy (we observed bad gps positions in a range of 30m, or more): // Resolution of GPS is +/- 3 to 5m. In 1s at 10m/s (= 36 km/h) we are in 'best' case still // in behalf the resolution of GPS. diff --git a/src/taskGPS.cpp b/src/taskGPS.cpp index 8e6b615..ccc555c 100644 --- a/src/taskGPS.cpp +++ b/src/taskGPS.cpp @@ -17,10 +17,14 @@ extern uint8_t usb_serial_data_type; // Pins for GPS #if defined(T_BEAM_V1_0) || defined(T_BEAM_V1_2) static const int RXPin = 12, TXPin = 34; -#else +#else /* i.e. T_BEAM_V0_7, or lora32-device-with-self-attached-GPS */ static const int RXPin = 15, TXPin = 12; #endif +#ifndef LORA32_21 static const uint32_t GPSBaud = 9600; //GPS +#else /* one user played with self-attached GPS on his LORA32 device. TODO: gps speed choosable in Web-Interface */ +static const uint32_t GPSBaud = 57600; //GPS +#endif HardwareSerial gpsSerial(1); // TTGO has HW serial TinyGPSPlus gps; // The TinyGPS++ object bool gpsInitialized = false; @@ -65,7 +69,7 @@ bool gpsInitialized = false; gpsDataBuffer += String(gpsChar); if (gpsChar == '\n') { - if (usb_serial_data_type == 4) + if ((usb_serial_data_type & 4)) Serial.println(gpsDataBuffer); #ifdef ENABLE_WIFI iterateWifiClients([](WiFiClient *client, int clientIdx, const String *data){ diff --git a/src/taskWebServer.cpp b/src/taskWebServer.cpp index 70bbe52..de64d40 100644 --- a/src/taskWebServer.cpp +++ b/src/taskWebServer.cpp @@ -1597,7 +1597,7 @@ int connect_to_aprsis(void) { aprsis_client.print(String(buffer) + "\r\n"); t_start = millis(); - while (!aprsis_client.available() && (millis()-t_start) < 25000L) { vTaskDelay(100 / portTICK_PERIOD_MS); esp_task_wdt_reset(); } + while (!aprsis_client.available() && (millis()-t_start) < 5000L) { vTaskDelay(100 / portTICK_PERIOD_MS); esp_task_wdt_reset(); } if (aprsis_client.available()) { // check String s = aprsis_client.readStringUntil('\n');