@@ -67,30 +67,11 @@ void WiFiClass::mode(WiFiMode_t m) {
67
67
}
68
68
}
69
69
70
-
71
- /* Start WiFi connection for OPEN networks
72
-
73
- param ssid: Pointer to the SSID string.
74
- */
75
- int WiFiClass::begin (const char * ssid) {
76
- return begin (ssid, nullptr );
77
- }
78
-
79
- int WiFiClass::beginBSSID (const char * ssid, const uint8_t *bssid) {
80
- return begin (ssid, nullptr , bssid);
81
- }
82
-
83
- /* Start WiFi connection with passphrase
84
- the most secure supported mode will be automatically selected
85
-
86
- param ssid: Pointer to the SSID string.
87
- param passphrase: Passphrase. Valid characters in a passphrase
88
- must be between ASCII 32-126 (decimal).
89
- */
90
- int WiFiClass::begin (const char * ssid, const char *passphrase, const uint8_t *bssid) {
70
+ bool WiFiClass::_beginInternal (const char * ssid, const char *passphrase, const uint8_t *bssid) {
91
71
// Simple ESP8266 compatibility hack
92
72
if (_modeESP == WIFI_AP) {
93
- return beginAP (ssid, passphrase);
73
+ // When beginAP was a success, it returns WL_CONNECTED and we return true as success.
74
+ return beginAP (ssid, passphrase) == WL_CONNECTED;
94
75
}
95
76
96
77
end ();
@@ -109,19 +90,69 @@ int WiFiClass::begin(const char* ssid, const char *passphrase, const uint8_t *bs
109
90
_wifi.setTimeout (_timeout);
110
91
_apMode = false ;
111
92
_wifiHWInitted = true ;
112
- uint32_t start = millis (); // The timeout starts from network init, not network link up
93
+
94
+ // Internal wifi.begin returns false when failed, therefore we return false as error
113
95
if (!_wifi.begin ()) {
114
- return WL_IDLE_STATUS ;
96
+ return false ;
115
97
}
116
98
noLowPowerMode ();
117
99
// Enable CYW43 event debugging (make sure Debug Port is set)
118
100
// cyw43_state.trace_flags = 0xffff;
101
+
102
+ return true ;
103
+ }
104
+
105
+
106
+ /* Start WiFi connection for OPEN networks
107
+
108
+ param ssid: Pointer to the SSID string.
109
+ */
110
+ int WiFiClass::begin (const char * ssid) {
111
+ return begin (ssid, nullptr );
112
+ }
113
+
114
+ /* Start WiFi connection for OPEN networks, but non blocking.
115
+
116
+ param ssid: Pointer to the SSID string.
117
+ */
118
+ int WiFiClass::beginNoBlock (const char * ssid) {
119
+ return beginNoBlock (ssid, nullptr );
120
+ }
121
+
122
+
123
+ int WiFiClass::beginBSSID (const char * ssid, const uint8_t *bssid) {
124
+ return begin (ssid, nullptr , bssid);
125
+ }
126
+
127
+ /* Start WiFi connection with passphrase
128
+ the most secure supported mode will be automatically selected
129
+
130
+ param ssid: Pointer to the SSID string.
131
+ param passphrase: Passphrase. Valid characters in a passphrase
132
+ must be between ASCII 32-126 (decimal).
133
+ */
134
+ int WiFiClass::begin (const char * ssid, const char *passphrase, const uint8_t *bssid) {
135
+ uint32_t start = millis (); // The timeout starts from network init, not network link up
136
+
137
+ // Returns WL_IDLE_STATUS on error for compatibility.
138
+ if (!_beginInternal (ssid, passphrase, bssid)) {
139
+ return WL_IDLE_STATUS;
140
+ }
141
+
119
142
while (!_calledESP && ((millis () - start < (uint32_t )2 * _timeout)) && !connected ()) {
120
143
delay (10 );
121
144
}
122
145
return status ();
123
146
}
124
147
148
+ int WiFiClass::beginNoBlock (const char * ssid, const char *passphrase, const uint8_t *bssid) {
149
+ // Returns WL_IDLE_STATUS on error for compatibility.
150
+ if (!_beginInternal (ssid, passphrase, bssid)) {
151
+ return WL_IDLE_STATUS;
152
+ }
153
+ return status ();
154
+ }
155
+
125
156
uint8_t WiFiClass::beginAP (const char *ssid) {
126
157
return beginAP (ssid, nullptr );
127
158
}
0 commit comments