@@ -91,9 +91,10 @@ bool ESP8266WiFiSTAClass::_useStaticIp = false;
91
91
* @param passphrase const char * Optional. Passphrase. Valid characters in a passphrase must be between ASCII 32-126 (decimal).
92
92
* @param bssid uint8_t[6] Optional. BSSID / MAC of AP
93
93
* @param channel Optional. Channel of AP
94
+ * @param connect Optional. call connect
94
95
* @return
95
96
*/
96
- wl_status_t ESP8266WiFiSTAClass::begin (const char * ssid, const char *passphrase, int32_t channel, const uint8_t * bssid) {
97
+ wl_status_t ESP8266WiFiSTAClass::begin (const char * ssid, const char *passphrase, int32_t channel, const uint8_t * bssid, bool connect ) {
97
98
98
99
if (!WiFi.enableSTA (true )) {
99
100
// enable STA failed
@@ -134,12 +135,17 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase,
134
135
}
135
136
136
137
ETS_UART_INTR_DISABLE ();
138
+
137
139
if (WiFi._persistent ) {
138
140
wifi_station_set_config (&conf);
139
141
} else {
140
142
wifi_station_set_config_current (&conf);
141
143
}
142
- wifi_station_connect ();
144
+
145
+ if (connect) {
146
+ wifi_station_connect ();
147
+ }
148
+
143
149
ETS_UART_INTR_ENABLE ();
144
150
145
151
if (channel > 0 && channel <= 13 ) {
@@ -153,8 +159,8 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase,
153
159
return status ();
154
160
}
155
161
156
- wl_status_t ESP8266WiFiSTAClass::begin (char * ssid, char *passphrase, int32_t channel, const uint8_t * bssid) {
157
- return begin ((const char *) ssid, (const char *) passphrase, channel, bssid);
162
+ wl_status_t ESP8266WiFiSTAClass::begin (char * ssid, char *passphrase, int32_t channel, const uint8_t * bssid, bool connect ) {
163
+ return begin ((const char *) ssid, (const char *) passphrase, channel, bssid, connect );
158
164
}
159
165
160
166
/* *
@@ -261,6 +267,38 @@ bool ESP8266WiFiSTAClass::disconnect(bool wifioff) {
261
267
return ret;
262
268
}
263
269
270
+ /* *
271
+ * Setting the ESP8266 station to connect to the AP (which is recorded)
272
+ * automatically or not when powered on. Enable auto-connect by default.
273
+ * @param autoConnect bool
274
+ * @return if saved
275
+ */
276
+ bool ESP8266WiFiSTAClass::setAutoConnect (bool autoConnect) {
277
+ bool ret;
278
+ ETS_UART_INTR_DISABLE ();
279
+ ret = wifi_station_set_auto_connect (autoConnect);
280
+ ETS_UART_INTR_ENABLE ();
281
+ return ret;
282
+ }
283
+
284
+ /* *
285
+ * Checks if ESP8266 station mode will connect to AP
286
+ * automatically or not when it is powered on.
287
+ * @return auto connect
288
+ */
289
+ bool ESP8266WiFiSTAClass::getAutoConnect () {
290
+ return (wifi_station_get_auto_connect () != 0 );
291
+ }
292
+
293
+ /* *
294
+ * Set whether reconnect or not when the ESP8266 station is disconnected from AP.
295
+ * @param autoReconnect
296
+ * @return
297
+ */
298
+ bool ESP8266WiFiSTAClass::setAutoReconnect (bool autoReconnect) {
299
+ return wifi_station_set_reconnect_policy (autoReconnect);
300
+ }
301
+
264
302
/* *
265
303
* Wait for WiFi connection to reach a result
266
304
* returns the status reached or disconnect if STA is off
0 commit comments