app_main.c 859 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // app_main.c
  2. #include "freertos/FreeRTOS.h"
  3. #include "freertos/task.h"
  4. #include "esp_log.h"
  5. #include "nvs_flash.h"
  6. #include "wifi_http.h" // 引入wifi_http.c中的头文件
  7. #include "http_request.h" // 引入http_request.c中的头文件
  8. static const char *TAG = "app_main";
  9. // 主函数
  10. void app_main(void)
  11. {
  12. // 初始化NVS
  13. esp_err_t ret = nvs_flash_init();
  14. if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
  15. ESP_ERROR_CHECK(nvs_flash_erase());
  16. ret = nvs_flash_init();
  17. }
  18. ESP_ERROR_CHECK(ret);
  19. // 初始化Wi-Fi并连接
  20. wifi_init_sta();
  21. // 等待Wi-Fi连接
  22. vTaskDelay(10000 / portTICK_PERIOD_MS);
  23. while (true)
  24. {
  25. /* code */
  26. // 执行HTTP GET请求
  27. http_get_request();
  28. vTaskDelay(4*1000 / portTICK_PERIOD_MS);
  29. }
  30. }