dacowars 3 недель назад
Родитель
Сommit
a43ef74800
3 измененных файлов с 70 добавлено и 2 удалено
  1. 3 0
      .gitignore
  2. 1 1
      main/idf_component.yml
  3. 66 1
      main/main.c

+ 3 - 0
.gitignore

@@ -76,3 +76,6 @@ Desktop.ini
 *.workspace # General workspace files, can be from various tools
 *.suo       # Visual Studio Solution User Options
 *.sln.docstates # Visual Studio
+
+dependencies.lock
+.gitignore

+ 1 - 1
main/idf_component.yml

@@ -18,5 +18,5 @@ dependencies:
     git: https://dacogogs.duckdns.org/dacowars/libreria_dht22.git
     version: '*'
   GPS_parser:
-    git: https://dacogogs.duckdns.org/dacowars/libreria_GPS_parser.git
+    git: https://dacogogs.duckdns.org/dacowars/libreria_GPSparser.git
     version: '*'

+ 66 - 1
main/main.c

@@ -5,14 +5,30 @@
 #include "esp_rom_sys.h"
 #include "esp_log.h"
 #include "dht22.h"
-#include <TinyGPSPlus.h>
 #include "GPS_parser.h"
+#include "driver/uart.h"
 
 
 const char *DHT_TAG = "DHT22";
+const char *GPS_TAG = "GPS_PARSER";
+
+const int uart_buffer_size = (1024 * 2);
+int length = 0;
+
+uint8_t data;
+
+static gps_parser_t gps;
+
+void read_uart_char();
+
+void uart_configurator();
+
+
 
 void app_main(void)
 {
+    // Initialize DHT22 sensor
+    /*
     float temperature;
     float humidity;
     esp_err_t err = dht_attach_pin();
@@ -30,4 +46,53 @@ void app_main(void)
         }
         vTaskDelay(pdMS_TO_TICKS(5000)); // Wait for 5 seconds before the next reading
     }
+    */
+    // Initialize GPS parser
+    uart_configurator();
+    double latitude, longitude;
+    gps_parser_init(&gps);
+    while(1){
+        while (uart_read_bytes(UART_NUM_2, &data, 1, 0)){
+            gps_parser_encode(&gps, data);
+        }
+        if (gps_location_is_valid(&gps.location)) {
+            double lat = gps_location_lat(&gps.location);
+            double lng = gps_location_lng(&gps.location);
+            ESP_LOGI(GPS_TAG, "Lat: %.8f, Lng: %.8f", lat, lng);
+        }
+
+        if (gps_date_is_valid(&gps.date) && gps_time_is_valid(&gps.time)) {
+            ESP_LOGI(GPS_TAG, "Fecha: %02u/%02u/%04u Hora: %02u:%02u:%02u\n",
+                    gps_date_day(&gps.date),
+                    gps_date_month(&gps.date),
+                    gps_date_year(&gps.date),
+                    gps_time_hour(&gps.time),
+                    gps_time_minute(&gps.time),
+                    gps_time_second(&gps.time));
+        }
+        vTaskDelay(pdMS_TO_TICKS(2000)); // Wait for 1 second before the next reading
+    }
+
+}
+
+
+void uart_configurator() {
+    // Configure UART parameters
+    uart_config_t uart_config = {
+        .baud_rate = 115200,
+        .data_bits = UART_DATA_8_BITS,
+        .parity = UART_PARITY_DISABLE,
+        .stop_bits = UART_STOP_BITS_1,
+        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE
+    };
+    QueueHandle_t uart_queue;
+    // Install UART driver using an event queue here
+    ESP_ERROR_CHECK(uart_driver_install(UART_NUM_2, uart_buffer_size, uart_buffer_size, 10, &uart_queue, 0));
+    ESP_ERROR_CHECK(uart_param_config(UART_NUM_2, &uart_config));
+    ESP_ERROR_CHECK(uart_set_pin(UART_NUM_2, GPIO_NUM_17, GPIO_NUM_16, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
+}
+
+void read_uart_char() {
+    ESP_ERROR_CHECK(uart_get_buffered_data_len(UART_NUM_2, (size_t*)&length));
+     // Read one byte from UART
 }