From a43da889d194c57540f0544ac830643443c85ae1 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 9 Jun 2018 19:20:34 +0200 Subject: [PATCH] testing GPS --- README.md | 2 +- platformio.ini | 1 + src/globals.h | 10 +++++----- src/gpsread.cpp | 35 ++++++++++++++++++++++++----------- src/hal/ttgobeam.h | 3 +-- src/lorawan.cpp | 2 -- src/main.cpp | 5 +---- 7 files changed, 33 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 763b8694..3925f72c 100644 --- a/README.md +++ b/README.md @@ -232,7 +232,7 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts. 0x80 get device configuration -device answers with it's current configuration. The configuration is a C structure declared in file [globals.h](src/globals.h#L27-L45) with the following definition: +device answers with it's current configuration. The configuration is a C structure declared in file [globals.h](src/globals.h#L32-L50) with the following definition: byte 1: Lora SF (7..12) byte 2: Lora TXpower (2..15) diff --git a/platformio.ini b/platformio.ini index eb008f51..076c7674 100644 --- a/platformio.ini +++ b/platformio.ini @@ -33,6 +33,7 @@ lib_deps_rgbled = SmartLeds@>=1.1.3 lib_deps_gps = https://github.com/mikalhart/TinyGPSPlus.git +;beware of TinyGPSplus in PlatformIO library manager, it loads old v.092 labeled as 1.0.0 !! build_flags = ; we need build_flag for logging, otherwise we can't use ESP_LOGx in arduino framework ; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- diff --git a/src/globals.h b/src/globals.h index e92e44a6..e9c2fb5b 100644 --- a/src/globals.h +++ b/src/globals.h @@ -51,14 +51,14 @@ typedef struct { #ifdef HAS_GPS typedef struct { - uint32_t latitude; - uint32_t longitude; - uint8_t hdop; + double latitude; + double longitude; + double hdop; uint32_t satellites; - uint16_t altitude; + double altitude; } gpsStatus_t; extern gpsStatus_t gps_status; // struct for storing gps data - extern TinyGPSPlus gps; // Make TinyGPS++ instance globally availabe + extern TinyGPSPlus gps; // Make TinyGPS++ instance globally availabe #endif extern configData_t cfg; diff --git a/src/gpsread.cpp b/src/gpsread.cpp index 752b1d2e..15b5ed50 100644 --- a/src/gpsread.cpp +++ b/src/gpsread.cpp @@ -9,9 +9,9 @@ static const char TAG[] = "main"; void gps_read(){ gps_status.latitude = gps.location.lat(); gps_status.longitude = gps.location.lng(); - gps_status.satellites = (uint8_t) gps.satellites.value(); - gps_status.hdop = (uint8_t) (gps.hdop.value() / 100); - gps_status.altitude = (uint16_t) gps.altitude.meters(); + gps_status.satellites = gps.satellites.value(); + gps_status.hdop = gps.hdop.value(); + gps_status.altitude = gps.altitude.meters(); } /// GPS serial feed FreeRTos Task @@ -19,17 +19,30 @@ void gps_loop(void * pvParameters) { configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check - HardwareSerial GPS_Serial(1); - //GPS_Serial.begin(HAS_GPS); - GPS_Serial.begin(9600, SERIAL_8N1, 12, 15 ); + HardwareSerial GPS_Serial(1); while(1) { - while (GPS_Serial.available()) { - gps.encode(GPS_Serial.read()); + if (cfg.gpsmode) + { + // if GPS function is enabled try serial connect to GPS device + GPS_Serial.begin(HAS_GPS); + + while(cfg.gpsmode) { + // feed GPS decoder with serial NMEA data from GPS device + while (GPS_Serial.available()) { + gps.encode(GPS_Serial.read()); + vTaskDelay(1/portTICK_PERIOD_MS); // reset watchdog + } + } + // after GPS function was disabled, close connect to GPS device + GPS_Serial.end(); } - + vTaskDelay(1/portTICK_PERIOD_MS); // reset watchdog - } -} + + } // end of infinite loop + +} // gps_loop() + #endif // HAS_GPS \ No newline at end of file diff --git a/src/hal/ttgobeam.h b/src/hal/ttgobeam.h index d9e9c5e5..9a05de26 100644 --- a/src/hal/ttgobeam.h +++ b/src/hal/ttgobeam.h @@ -6,8 +6,7 @@ //#define HAS_BUTTON GPIO_NUM_39 // on board button "BOOT" (next to reset button) !! seems not to work!! #define HAS_BATTERY_PROBE ADC1_GPIO35_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7 #define BATT_FACTOR 2 // voltage divider 100k/100k on board -//#define HAS_GPS 9600, SERIAL_8N1, 12, 15 -#define HAS_GPS 1 +#define HAS_GPS 9600, SERIAL_8N1, 12, 15 // re-define pin definitions of pins_arduino.h #define PIN_SPI_SS GPIO_NUM_18 // ESP32 GPIO18 (Pin18) -- HPD13A NSS/SEL (Pin4) SPI Chip Select Input diff --git a/src/lorawan.cpp b/src/lorawan.cpp index b1079c0f..24f7cb1d 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -129,8 +129,6 @@ void do_send(osjob_t* j){ mydata[3] = 0; } - - // Prepare upstream data transmission at the next possible time. LMIC_setTxData2(COUNTERPORT, mydata, sizeof(mydata), (cfg.countermode & 0x02)); ESP_LOGI(TAG, "%d bytes queued to send", sizeof(mydata)); diff --git a/src/main.cpp b/src/main.cpp index 87fe4ffb..4ab492d5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -598,9 +598,6 @@ do_send(&sendjob); void loop() { - HardwareSerial GPS_Serial(1); - GPS_Serial.begin(9600, SERIAL_8N1, 12, 15 ); - while (1) { // simple state machine for controlling uptime, display, LED, button, memory. @@ -629,7 +626,7 @@ void loop() { } if ( (uptime() % 10000) == 0 ) - ESP_LOGI(TAG, "GPS NMEA data passed %d / failed: %d / with fix: %d || Sats: %d / HDOP: %d || m/s: %d / %d", gps.passedChecksum(), gps.failedChecksum(), gps.sentencesWithFix(), gps.satellites.value(), gps.hdop.value(), gps.time.minute(), gps.time.second() ); + ESP_LOGI(TAG, "GPS NMEA data: passed %d / failed: %d / with fix: %d", gps.passedChecksum(), gps.failedChecksum(), gps.sentencesWithFix()); vTaskDelay(1/portTICK_PERIOD_MS); // reset watchdog