2 * Espressif Systems Wireless LAN device driver
4 * Copyright (C) 2015-2020 Espressif Systems (Shanghai) PTE LTD
6 * This software file (the "File") is distributed by Espressif Systems (Shanghai)
7 * PTE LTD under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
23 #include "platform_wrapper.h"
26 #define SSID_LENGTH 32
34 int mode = 0, count = 0, power_save_mode = 0;
35 esp_hosted_ap_config_t ap_config, softap_config;
36 esp_hosted_wifi_scanlist_t* list = NULL;
37 esp_hosted_wifi_connected_stations_list* stations_list = NULL;
39 int ret = wifi_get_mode(&mode);
41 printf("wifi mode is %d \n",mode);
43 printf("Failed to get wifi mode \n");
46 ret = wifi_set_mode(mode);
48 printf("newly set wifi mode %d \n", mode);
50 printf("error in setting mode \n");
52 ret = wifi_get_mac(mode,mac);
54 printf("mac address %s \n", mac);
56 printf("Failed to get MAC address \n");
58 strcpy((char* )&ap_config.ssid ,"xyz");
59 strcpy((char* )&ap_config.pwd ,"xyz123456");
60 strcpy((char* )&ap_config.bssid, "0");
61 ap_config.is_wpa3_supported = false;
62 ap_config.listen_interval = 5;
63 ret = wifi_set_ap_config(ap_config);
65 printf("Connected to AP \n");
67 printf("Failed to connect with AP \n");
69 ret = wifi_get_ap_config(&ap_config);
71 printf("AP's ssid %s \n", ap_config.ssid);
72 printf("AP's bssid i.e. MAC address %s \n", ap_config.bssid);
73 printf("AP's channel number %d \n", ap_config.channel);
74 printf("AP's rssi %d \n", ap_config.rssi);
75 printf("AP's encryption mode %d \n", ap_config.encryption_mode);
77 printf("AP's status %s \n", ap_config.status);
79 ret = wifi_disconnect_ap();
81 printf("Disconnected from AP \n");
83 printf("Failed to disconnect from AP \n");
85 strcpy((char* )&softap_config.ssid, "esp12");
86 strcpy((char* )&softap_config.pwd, "esp123456");
87 softap_config.channel = 1;
88 softap_config.encryption_mode = 3;
89 softap_config.max_connections = 5;
90 softap_config.ssid_hidden = false;
91 softap_config.bandwidth = 2;
92 ret = wifi_set_softap_config(softap_config);
94 printf("esp32 softAP started \n");
96 printf("Failed to set softAP config \n");
98 ret = wifi_get_softap_config(&softap_config);
100 printf("softAP ssid %s \n", softap_config.ssid);
101 printf("softAP pwd %s \n", softap_config.pwd);
102 printf("softAP channel ID %d \n", softap_config.channel);
103 printf("softAP encryption mode %d \n", softap_config.encryption_mode);
104 printf("softAP max connections %d \n", softap_config.max_connections);
105 printf("softAP ssid broadcast status %d \n", softap_config.ssid_hidden);
106 printf("softAP bandwidth mode %d \n", softap_config.bandwidth);
108 printf("Failed to get softAP config \n");
110 ret = wifi_ap_scan_list(&list, &count);
111 if (ret == SUCCESS) {
112 printf("Number of available APs is %d \n", count);
114 for (int i=0; i<count; i++) {
115 printf("%d th AP's ssid \"%s\" bssid \"%s\" rssi \"%d\" channel \"%d\" authentication mode \"%d\" \n",i, list[i].ssid, list[i].bssid, list[i].rssi, list[i].channel, list[i].encryption_mode);
118 printf("No AP found \n");
121 printf("Failed to get scanned AP list \n");
124 esp_hosted_free(list);
128 ret = wifi_connected_stations_list(&stations_list,&count);
129 if (ret == SUCCESS) {
130 printf("number of connected stations is %d \n", count);
132 for (int i=0; i<count; i++) {
133 printf("%d th stations's bssid \"%s\" rssi \"%d\" \n",i, stations_list[i].bssid, stations_list[i].rssi);
136 printf("No AP found \n");
139 printf("Failed to get connected stations list \n");
141 if (stations_list != NULL) {
142 esp_hosted_free(stations_list);
143 stations_list = NULL;
145 mode = WIFI_MODE_STA;
146 strncpy(mac, "1a:11:11:11:11:11", sizeof(mac));
147 ret = wifi_set_mac(mode, mac);
148 if (ret == SUCCESS) {
149 printf("MAC address is set \n");
151 printf("MAC address is not set \n");
153 power_save_mode = WIFI_PS_MIN_MODEM;
154 ret = wifi_set_power_save_mode(power_save_mode);
155 if (ret == SUCCESS) {
156 printf("Power save mode set \n");
158 printf("Power save mode is not set \n");
160 ret = wifi_get_power_save_mode(&power_save_mode);
161 if (ret == SUCCESS) {
162 printf("Power save mode is %d \n", power_save_mode);
164 printf("Failed to get power save mode \n");