Created
June 6, 2018 10:29
-
-
Save aallan/38346a23e70d3d7b97192ab5ee7ce084 to your computer and use it in GitHub Desktop.
Code snippet to enable WIFI_PROTOCOL_LR in an ESP32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void init_wifi(wifi_mode_t mode) | |
{ | |
const uint8_t protocol = WIFI_PROTOCOL_LR; | |
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(mode) ); | |
wifi_event_group = xEventGroupCreate(); | |
if (mode == WIFI_MODE_STA) { | |
ESP_ERROR_CHECK( esp_wifi_set_protocol(WIFI_IF_STA, protocol) ); | |
wifi_config_t config = { | |
.sta = { | |
.ssid = ap_name, | |
.password = pass, | |
.bssid_set = false | |
} | |
}; | |
ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &config) ); | |
ESP_ERROR_CHECK( esp_wifi_start() ); | |
ESP_ERROR_CHECK( esp_wifi_connect() ); | |
xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, | |
false, true, portMAX_DELAY); | |
ESP_LOGI(TAG, "Connected to AP"); | |
} else { | |
ESP_ERROR_CHECK( esp_wifi_set_protocol(WIFI_IF_AP, protocol) ); | |
wifi_config_t config = { | |
.ap = { | |
.ssid = ap_name, | |
.password = pass, | |
.ssid_len = 0, | |
.authmode = WIFI_AUTH_WPA_WPA2_PSK, | |
.ssid_hidden = false, | |
.max_connection = 3, | |
.beacon_interval = 100, | |
} | |
}; | |
ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_AP, &config) ); | |
ESP_ERROR_CHECK( esp_wifi_start() ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ERROR. PLEASE HELP FIX ISSUE
Hardware:
Board: ESP32 Dev Module
Core Installation version: ?1.0.0? ?1.0.1-rc4? ?1.0.1? ?1.0.1-git? ?1.0.2? ?1.0.3?
IDE name: Arduino IDE
Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Windows 10
Description:
Describe your problem here
I am trying to enable low rate wifi for long range connectivity and I cannot initialize the wifi_config_t object because the GNU complier does not support non-trivial designated initializers
Sketch:
Debug Messages: