@@ -91,9 +91,10 @@ bool ESP8266WiFiSTAClass::_useStaticIp = false;
9191 * @param passphrase const char * Optional. Passphrase. Valid characters in a passphrase must be between ASCII 32-126 (decimal).
9292 * @param bssid uint8_t[6] Optional. BSSID / MAC of AP
9393 * @param channel Optional. Channel of AP
94+ * @param connect Optional. call connect
9495 * @return
9596 */
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 ) {
9798
9899 if (!WiFi.enableSTA (true )) {
99100 // enable STA failed
@@ -134,12 +135,17 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase,
134135 }
135136
136137 ETS_UART_INTR_DISABLE ();
138+
137139 if (WiFi._persistent ) {
138140 wifi_station_set_config (&conf);
139141 } else {
140142 wifi_station_set_config_current (&conf);
141143 }
142- wifi_station_connect ();
144+
145+ if (connect) {
146+ wifi_station_connect ();
147+ }
148+
143149 ETS_UART_INTR_ENABLE ();
144150
145151 if (channel > 0 && channel <= 13 ) {
@@ -153,8 +159,8 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase,
153159 return status ();
154160}
155161
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 );
158164}
159165
160166/* *
@@ -261,6 +267,38 @@ bool ESP8266WiFiSTAClass::disconnect(bool wifioff) {
261267 return ret;
262268}
263269
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+
264302/* *
265303 * Wait for WiFi connection to reach a result
266304 * returns the status reached or disconnect if STA is off
0 commit comments