|
3 | 3 | * |
4 | 4 | * SPDX-License-Identifier: Unlicense OR CC0-1.0 |
5 | 5 | */ |
6 | | -/* WiFi station Example |
7 | | -
|
8 | | - This example code is in the Public Domain (or CC0 licensed, at your option.) |
9 | | -
|
10 | | - Unless required by applicable law or agreed to in writing, this |
11 | | - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
12 | | - CONDITIONS OF ANY KIND, either express or implied. |
13 | | -*/ |
14 | 6 | #include <string.h> |
15 | 7 | #include "freertos/FreeRTOS.h" |
16 | 8 | #include "freertos/event_groups.h" |
|
19 | 11 | #include "esp_event.h" |
20 | 12 | #include "esp_log.h" |
21 | 13 | #include "nvs_flash.h" |
22 | | -#include "esp_wifi_remote.h" |
23 | 14 | #include "console_ping.h" |
24 | 15 | #include "iperf_cmd.h" |
25 | 16 |
|
|
29 | 20 | #define WIFI_CONNECTED_BIT BIT0 |
30 | 21 | #define WIFI_FAIL_BIT BIT1 |
31 | 22 | #define WIFI_BITS (WIFI_CONNECTED_BIT | WIFI_FAIL_BIT) |
32 | | -#define WIFI_REMOTE_CONNECTED_BIT BIT2 |
33 | | -#define WIFI_REMOTE_FAIL_BIT BIT3 |
34 | | -#define WIFI_REMOTE_BITS (WIFI_REMOTE_CONNECTED_BIT | WIFI_REMOTE_FAIL_BIT) |
35 | 23 | #define EXAMPLE_ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY |
36 | 24 |
|
37 | 25 | static int s_retry_num = 0; |
38 | 26 | static EventGroupHandle_t s_wifi_event_group; |
39 | 27 |
|
| 28 | +#if CONFIG_ESP_WIFI_REMOTE_ENABLE |
| 29 | +/* Remote Wi-Fi is defined in another compilation unit, |
| 30 | + * as wifi_remote API uses the same type names as local WiFi |
| 31 | + * and since the types might be slightly different for different |
| 32 | + * targets, we cannot combine both in a single compilation unit |
| 33 | + */ |
| 34 | +void wifi_init_remote_sta(void); |
| 35 | +#endif |
| 36 | + |
40 | 37 | #if CONFIG_ESP_WIFI_LOCAL_ENABLE |
41 | 38 | static const char *TAG_local = "two_stations_local"; |
42 | 39 |
|
@@ -67,32 +64,6 @@ static void event_handler(void* arg, esp_event_base_t event_base, |
67 | 64 | } |
68 | 65 | #endif |
69 | 66 |
|
70 | | -#if CONFIG_ESP_WIFI_REMOTE_ENABLE |
71 | | -static const char *TAG_remote = "two_stations_remote"; |
72 | | - |
73 | | -static void event_handler_remote(void* arg, esp_event_base_t event_base, |
74 | | - int32_t event_id, void* event_data) |
75 | | -{ |
76 | | - if (event_base == WIFI_REMOTE_EVENT && event_id == WIFI_EVENT_STA_START) { |
77 | | - esp_wifi_remote_connect(); |
78 | | - } else if (event_base == WIFI_REMOTE_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { |
79 | | - if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) { |
80 | | - esp_wifi_remote_connect(); |
81 | | - s_retry_num++; |
82 | | - ESP_LOGI(TAG_remote, "retry to connect to the AP"); |
83 | | - } else { |
84 | | - xEventGroupSetBits(s_wifi_event_group, WIFI_REMOTE_FAIL_BIT); |
85 | | - } |
86 | | - ESP_LOGI(TAG_remote,"connect to the AP fail"); |
87 | | - } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { |
88 | | - ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; |
89 | | - ESP_LOGI(TAG_remote, "Remote Wi-Fi got IP:" IPSTR, IP2STR(&event->ip_info.ip)); |
90 | | - s_retry_num = 0; |
91 | | - xEventGroupSetBits(s_wifi_event_group, WIFI_REMOTE_CONNECTED_BIT); |
92 | | - } |
93 | | -} |
94 | | -#endif |
95 | | - |
96 | 67 | static void init_system_components(void) |
97 | 68 | { |
98 | 69 | s_wifi_event_group = xEventGroupCreate(); |
@@ -137,42 +108,6 @@ static void wifi_init_sta(void) |
137 | 108 | } |
138 | 109 | #endif |
139 | 110 |
|
140 | | -#if CONFIG_ESP_WIFI_REMOTE_ENABLE |
141 | | -static void wifi_init_remote_sta(void) |
142 | | -{ |
143 | | - esp_wifi_remote_create_default_sta(); |
144 | | - |
145 | | - wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); |
146 | | - ESP_ERROR_CHECK(esp_wifi_remote_init(&cfg)); |
147 | | - |
148 | | - ESP_ERROR_CHECK(esp_event_handler_register(WIFI_REMOTE_EVENT, ESP_EVENT_ANY_ID, event_handler_remote, NULL)); |
149 | | - ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, event_handler_remote, NULL)); |
150 | | - |
151 | | - wifi_config_t wifi_config = { |
152 | | - .sta = { |
153 | | - .ssid = CONFIG_ESP_WIFI_REMOTE_SSID, |
154 | | - .password = CONFIG_ESP_WIFI_REMOTE_PASSWORD, |
155 | | - }, |
156 | | - }; |
157 | | - ESP_ERROR_CHECK(esp_wifi_remote_set_mode(WIFI_MODE_STA)); |
158 | | - ESP_ERROR_CHECK(esp_wifi_remote_set_config(WIFI_IF_STA, &wifi_config)); |
159 | | - ESP_ERROR_CHECK(esp_wifi_remote_start()); |
160 | | - |
161 | | - ESP_LOGI(TAG_remote, "wifi_init_remote_sta finished."); |
162 | | - |
163 | | - /* Waiting until either the connection is established the same way for REMOTE wifi */ |
164 | | - EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group, WIFI_REMOTE_BITS, pdFALSE, pdFALSE, portMAX_DELAY); |
165 | | - |
166 | | - if (bits & WIFI_REMOTE_CONNECTED_BIT) { |
167 | | - ESP_LOGI(TAG_remote, "connected to ap SSID:%s", CONFIG_ESP_WIFI_REMOTE_SSID); |
168 | | - } else if (bits & WIFI_REMOTE_FAIL_BIT) { |
169 | | - ESP_LOGW(TAG_remote, "Failed to connect to SSID:%s", CONFIG_ESP_WIFI_REMOTE_SSID); |
170 | | - } else { |
171 | | - ESP_LOGE(TAG_remote, "UNEXPECTED EVENT"); |
172 | | - } |
173 | | -} |
174 | | -#endif |
175 | | - |
176 | 111 | void app_main(void) |
177 | 112 | { |
178 | 113 | esp_log_level_set("*", ESP_LOG_INFO); |
|
0 commit comments