From 78be578210afeba60e19a3c18ee886005f330634 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Mon, 27 Mar 2017 18:21:54 +0200 Subject: [PATCH] Add new file https://github.com/espressif/esp-idf-template https://github.com/espressif/esp-idf/tree/master/examples --- main/main.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 main/main.c diff --git a/main/main.c b/main/main.c new file mode 100644 index 0000000..911c913 --- /dev/null +++ b/main/main.c @@ -0,0 +1,41 @@ +#include "freertos/FreeRTOS.h" +#include "esp_wifi.h" +#include "esp_system.h" +#include "esp_event.h" +#include "esp_event_loop.h" +#include "nvs_flash.h" +#include "driver/gpio.h" + +esp_err_t event_handler(void *ctx, system_event_t *event) +{ + return ESP_OK; +} + +void app_main(void) +{ + nvs_flash_init(); + tcpip_adapter_init(); + ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) ); + wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); + ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); + ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) ); + ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) ); + wifi_config_t sta_config = { + .sta = { + .ssid = "access_point_name", + .password = "password", + .bssid_set = false + } + }; + ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config) ); + ESP_ERROR_CHECK( esp_wifi_start() ); + ESP_ERROR_CHECK( esp_wifi_connect() ); + + gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT); + int level = 0; + while (true) { + gpio_set_level(GPIO_NUM_4, level); + level = !level; + vTaskDelay(300 / portTICK_PERIOD_MS); + } +} \ No newline at end of file