@@ -92,7 +92,7 @@ bool ESP8266WiFiSTAClass::_useStaticIp = false;
92
92
* @param channel Optional. Channel of AP
93
93
* @return
94
94
*/
95
- int ESP8266WiFiSTAClass::begin (const char * ssid, const char *passphrase, int32_t channel, const uint8_t * bssid) {
95
+ wl_status_t ESP8266WiFiSTAClass::begin (const char * ssid, const char *passphrase, int32_t channel, const uint8_t * bssid) {
96
96
97
97
if (!WiFi.enableSTA (true )) {
98
98
// enable STA failed
@@ -152,15 +152,15 @@ int ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase, int32_t
152
152
return status ();
153
153
}
154
154
155
- int ESP8266WiFiSTAClass::begin (char * ssid, char *passphrase, int32_t channel, const uint8_t * bssid) {
155
+ wl_status_t ESP8266WiFiSTAClass::begin (char * ssid, char *passphrase, int32_t channel, const uint8_t * bssid) {
156
156
return begin ((const char *) ssid, (const char *) passphrase, channel, bssid);
157
157
}
158
158
159
159
/* *
160
160
* Use to connect to SDK config.
161
161
* @return wl_status_t
162
162
*/
163
- int ESP8266WiFiSTAClass::begin () {
163
+ wl_status_t ESP8266WiFiSTAClass::begin () {
164
164
165
165
if (!WiFi.enableSTA (true )) {
166
166
// enable STA failed
@@ -184,10 +184,10 @@ int ESP8266WiFiSTAClass::begin() {
184
184
* @param gateway Static gateway configuration
185
185
* @param subnet Static Subnet mask
186
186
*/
187
- void ESP8266WiFiSTAClass::config (IPAddress local_ip, IPAddress gateway, IPAddress subnet) {
187
+ bool ESP8266WiFiSTAClass::config (IPAddress local_ip, IPAddress gateway, IPAddress subnet) {
188
188
189
189
if (!WiFi.enableSTA (true )) {
190
- return ;
190
+ return false ;
191
191
}
192
192
193
193
struct ip_info info;
@@ -196,9 +196,11 @@ void ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddres
196
196
info.netmask .addr = static_cast <uint32_t >(subnet);
197
197
198
198
wifi_station_dhcpc_stop ();
199
- wifi_set_ip_info (STATION_IF, &info);
200
-
201
- _useStaticIp = true ;
199
+ if (wifi_set_ip_info (STATION_IF, &info)) {
200
+ _useStaticIp = true ;
201
+ return true ;
202
+ }
203
+ return false ;
202
204
}
203
205
204
206
/* *
@@ -208,21 +210,30 @@ void ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddres
208
210
* @param subnet Static Subnet mask
209
211
* @param dns Static DNS server
210
212
*/
211
- void ESP8266WiFiSTAClass::config (IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns) {
213
+ bool ESP8266WiFiSTAClass::config (IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns) {
214
+
215
+ if (!WiFi.enableSTA (true )) {
216
+ return false ;
217
+ }
218
+
212
219
struct ip_info info;
213
220
info.ip .addr = static_cast <uint32_t >(local_ip);
214
221
info.gw .addr = static_cast <uint32_t >(gateway);
215
222
info.netmask .addr = static_cast <uint32_t >(subnet);
216
223
217
224
wifi_station_dhcpc_stop ();
218
- wifi_set_ip_info (STATION_IF, &info);
225
+ if (wifi_set_ip_info (STATION_IF, &info)) {
226
+ _useStaticIp = true ;
227
+ } else {
228
+ return false ;
229
+ }
219
230
220
231
// Set DNS-Server
221
232
ip_addr_t d;
222
233
d.addr = static_cast <uint32_t >(dns);
223
234
dns_setserver (0 , &d);
224
235
225
- _useStaticIp = true ;
236
+ return true ;
226
237
}
227
238
228
239
/* *
@@ -243,7 +254,8 @@ bool ESP8266WiFiSTAClass::reconnect() {
243
254
* @param wifioff
244
255
* @return one value of wl_status_t enum
245
256
*/
246
- int ESP8266WiFiSTAClass::disconnect (bool wifioff) {
257
+ bool ESP8266WiFiSTAClass::disconnect (bool wifioff) {
258
+ bool ret;
247
259
struct station_config conf;
248
260
*conf.ssid = 0 ;
249
261
*conf.password = 0 ;
@@ -254,15 +266,14 @@ int ESP8266WiFiSTAClass::disconnect(bool wifioff) {
254
266
} else {
255
267
wifi_station_set_config_current (&conf);
256
268
}
257
- wifi_station_disconnect ();
269
+ ret = wifi_station_disconnect ();
258
270
ETS_UART_INTR_ENABLE ();
259
271
260
272
if (wifioff) {
261
273
WiFi.enableSTA (false );
262
274
}
263
275
264
- // TODO return with more meaning ?
265
- return 0 ;
276
+ return ret;
266
277
}
267
278
268
279
/* *
@@ -391,18 +402,20 @@ bool ESP8266WiFiSTAClass::hostname(String aHostname) {
391
402
*
392
403
*/
393
404
wl_status_t ESP8266WiFiSTAClass::status () {
394
- int status = wifi_station_get_connect_status ();
405
+ station_status_t status = wifi_station_get_connect_status ();
395
406
396
- if (status == STATION_GOT_IP) {
397
- return WL_CONNECTED;
398
- } else if (status == STATION_NO_AP_FOUND) {
399
- return WL_NO_SSID_AVAIL;
400
- } else if (status == STATION_CONNECT_FAIL || status == STATION_WRONG_PASSWORD) {
401
- return WL_CONNECT_FAILED;
402
- } else if (status == STATION_IDLE) {
403
- return WL_IDLE_STATUS;
404
- } else {
405
- return WL_DISCONNECTED;
407
+ switch (status) {
408
+ case STATION_GOT_IP:
409
+ return WL_CONNECTED;
410
+ case STATION_NO_AP_FOUND:
411
+ return WL_NO_SSID_AVAIL;
412
+ case STATION_CONNECT_FAIL:
413
+ case STATION_WRONG_PASSWORD:
414
+ return WL_CONNECT_FAILED;
415
+ case STATION_IDLE:
416
+ return WL_IDLE_STATUS;
417
+ default :
418
+ return WL_DISCONNECTED;
406
419
}
407
420
}
408
421
@@ -543,32 +556,38 @@ bool ESP8266WiFiSTAClass::_smartConfigDone = false;
543
556
/* *
544
557
* Start SmartConfig
545
558
*/
546
- void ESP8266WiFiSTAClass::beginSmartConfig () {
547
- if (_smartConfigStarted)
548
- return ;
559
+ bool ESP8266WiFiSTAClass::beginSmartConfig () {
560
+ if (_smartConfigStarted) {
561
+ return false ;
562
+ }
549
563
550
564
if (!WiFi.enableSTA (true )) {
551
565
// enable STA failed
552
- return ;
566
+ return false ;
553
567
}
554
568
555
- _smartConfigStarted = true ;
556
- _smartConfigDone = false ;
557
-
558
- smartconfig_start (reinterpret_cast <sc_callback_t >(&ESP8266WiFiSTAClass::_smartConfigCallback), 1 );
569
+ if (smartconfig_start (reinterpret_cast <sc_callback_t >(&ESP8266WiFiSTAClass::_smartConfigCallback), 1 )) {
570
+ _smartConfigStarted = true ;
571
+ _smartConfigDone = false ;
572
+ return true ;
573
+ }
574
+ return false ;
559
575
}
560
576
561
577
562
578
/* *
563
579
* Stop SmartConfig
564
580
*/
565
- void ESP8266WiFiSTAClass::stopSmartConfig () {
581
+ bool ESP8266WiFiSTAClass::stopSmartConfig () {
566
582
if (!_smartConfigStarted) {
567
- return ;
583
+ return true ;
568
584
}
569
585
570
- smartconfig_stop ();
571
- _smartConfigStarted = false ;
586
+ if (smartconfig_stop ()) {
587
+ _smartConfigStarted = false ;
588
+ return true ;
589
+ }
590
+ return false ;
572
591
}
573
592
574
593
/* *
0 commit comments