Repo for ESP32 Weather Station Development
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.1KB

  1. #include "freertos/FreeRTOS.h"
  2. #include "esp_wifi.h"
  3. #include "esp_system.h"
  4. #include "esp_event.h"
  5. #include "esp_event_loop.h"
  6. #include "nvs_flash.h"
  7. #include "driver/gpio.h"
  8. esp_err_t event_handler(void *ctx, system_event_t *event)
  9. {
  10. return ESP_OK;
  11. }
  12. void app_main(void)
  13. {
  14. nvs_flash_init();
  15. tcpip_adapter_init();
  16. ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
  17. wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  18. ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
  19. ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
  20. ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
  21. wifi_config_t sta_config = {
  22. .sta = {
  23. .ssid = CONFIG_ESP_WIFI_SSID,
  24. .password = CONFIG_ESP_WIFI_PASSWORD,
  25. .bssid_set = false
  26. }
  27. };
  28. ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config) );
  29. ESP_ERROR_CHECK( esp_wifi_start() );
  30. ESP_ERROR_CHECK( esp_wifi_connect() );
  31. gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT);
  32. int level = 0;
  33. while (true) {
  34. gpio_set_level(GPIO_NUM_4, level);
  35. level = !level;
  36. vTaskDelay(300 / portTICK_PERIOD_MS);
  37. }
  38. }