main.c 1008 B

123456789101112131415161718192021222324252627282930313233
  1. #include <stdio.h>
  2. #include "freertos/FreeRTOS.h"
  3. #include "freertos/task.h"
  4. #include "driver/gpio.h"
  5. #include "esp_rom_sys.h"
  6. #include "esp_log.h"
  7. #include "dht22.h"
  8. #include <TinyGPSPlus.h>
  9. #include "GPS_parser.h"
  10. const char *DHT_TAG = "DHT22";
  11. void app_main(void)
  12. {
  13. float temperature;
  14. float humidity;
  15. esp_err_t err = dht_attach_pin();
  16. if (err != ESP_OK) {
  17. ESP_LOGE(DHT_TAG, "Failed to attach DHT pin: %s", esp_err_to_name(err));
  18. vTaskDelay(pdMS_TO_TICKS(5000)); // Wait for 5 seconds before retrying
  19. return;
  20. }
  21. vTaskDelay(pdMS_TO_TICKS(2000)); // Wait for 2 seconds before starting the main loop
  22. while (1) {
  23. if (dht_read(&temperature, &humidity) == ESP_OK) {
  24. ESP_LOGI(DHT_TAG, "Temperature: %.1f°C, Humidity: %.1f%%", temperature, humidity);
  25. } else {
  26. ESP_LOGE(DHT_TAG, "Failed to read from DHT22 sensor");
  27. }
  28. vTaskDelay(pdMS_TO_TICKS(5000)); // Wait for 5 seconds before the next reading
  29. }
  30. }