Skip to content

Commit e1751ab

Browse files
committed
Fix random STA not getting IP / can't connect
1 parent 241c88a commit e1751ab

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

cmake/dev_tools.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# 2 = Debug
1010
# 1 = Error only
1111
# 0 = Disabled
12-
set(ESP3D_TFT_LOG_LEVEL 3)
12+
set(ESP3D_TFT_LOG_LEVEL 0)
1313
add_compile_options(-DESP3D_TFT_LOG=${ESP3D_TFT_LOG_LEVEL})
1414

1515
# ANSI Color in Logs

main/modules/network/esp3d_network.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,22 @@
3535
#include "esp3d_values.h"
3636
#include "translations/esp3d_translation_service.h"
3737

38+
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_OPEN
39+
#if ESP3D_WIFI_FEATURE
40+
#define WIFI_CONNECTED_BIT BIT0
41+
#define WIFI_FAIL_BIT BIT1
42+
#define WIFI_STA_LOST_IP BIT2
43+
#define MIN_RSSI -78
44+
#define ESP3D_STA_MAXIMUM_RETRY 10
45+
#endif // ESP3D_WIFI_FEATURE
46+
3847
ESP3DNetwork esp3dNetwork;
3948

4049
/* The event group allows multiple bits for each event, but we only care about
4150
* two events:
4251
* - we are connected to the AP with an IP
4352
* - we failed to connect after the maximum amount of retries */
4453
#if ESP3D_WIFI_FEATURE
45-
#define WIFI_CONNECTED_BIT BIT0
46-
#define WIFI_FAIL_BIT BIT1
47-
#define WIFI_STA_LOST_IP BIT2
48-
49-
#define MIN_RSSI -78
50-
#define ESP3D_STA_MAXIMUM_RETRY 10
5154

5255
static void wifi_ap_event_handler(void* arg, esp_event_base_t event_base,
5356
int32_t event_id, void* event_data) {
@@ -365,6 +368,7 @@ bool ESP3DNetwork::startStaMode() {
365368
ipMode == static_cast<uint8_t>(ESP3DIpMode::staticIp) ? "Static"
366369
: "DHCP");
367370
wifi_config_t wifi_config;
371+
memset(&wifi_config, 0, sizeof(wifi_config_t));
368372
strcpy((char*)wifi_config.sta.ssid, ssid_str);
369373
strcpy((char*)wifi_config.sta.password, ssid_pwd_str);
370374
wifi_config.sta.threshold.authmode = WIFI_AUTH_OPEN;
@@ -438,9 +442,10 @@ bool ESP3DNetwork::startStaMode() {
438442
netbiosns_set_name(_hostname.c_str());
439443
ESP_ERROR_CHECK(esp_wifi_start());
440444
_current_radio_mode = ESP3DRadioMode::wifi_sta;
441-
/* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or
442-
* connection failed for the maximum number of re-tries (WIFI_FAIL_BIT). The
443-
* bits are set by event_handler() (see above) */
445+
446+
// Waiting until either the connection is established (WIFI_CONNECTED_BIT) or
447+
// connection failed for the maximum number of re-tries (WIFI_FAIL_BIT). The
448+
// bits are set by event_handler() (see above)
444449
EventBits_t bits = xEventGroupWaitBits(_s_wifi_event_group,
445450
WIFI_CONNECTED_BIT | WIFI_FAIL_BIT,
446451
pdFALSE, pdFALSE, portMAX_DELAY);

0 commit comments

Comments
 (0)