@@ -92,7 +92,7 @@ bool ESP8266WiFiSTAClass::_useStaticIp = false;
9292 * @param channel Optional. Channel of AP
9393 * @return
9494 */
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) {
9696
9797 if (!WiFi.enableSTA (true )) {
9898 // enable STA failed
@@ -152,15 +152,15 @@ int ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase, int32_t
152152 return status ();
153153}
154154
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) {
156156 return begin ((const char *) ssid, (const char *) passphrase, channel, bssid);
157157}
158158
159159/* *
160160 * Use to connect to SDK config.
161161 * @return wl_status_t
162162 */
163- int ESP8266WiFiSTAClass::begin () {
163+ wl_status_t ESP8266WiFiSTAClass::begin () {
164164
165165 if (!WiFi.enableSTA (true )) {
166166 // enable STA failed
@@ -184,10 +184,10 @@ int ESP8266WiFiSTAClass::begin() {
184184 * @param gateway Static gateway configuration
185185 * @param subnet Static Subnet mask
186186 */
187- void ESP8266WiFiSTAClass::config (IPAddress local_ip, IPAddress gateway, IPAddress subnet) {
187+ bool ESP8266WiFiSTAClass::config (IPAddress local_ip, IPAddress gateway, IPAddress subnet) {
188188
189189 if (!WiFi.enableSTA (true )) {
190- return ;
190+ return false ;
191191 }
192192
193193 struct ip_info info;
@@ -196,9 +196,11 @@ void ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddres
196196 info.netmask .addr = static_cast <uint32_t >(subnet);
197197
198198 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 ;
202204}
203205
204206/* *
@@ -208,21 +210,30 @@ void ESP8266WiFiSTAClass::config(IPAddress local_ip, IPAddress gateway, IPAddres
208210 * @param subnet Static Subnet mask
209211 * @param dns Static DNS server
210212 */
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+
212219 struct ip_info info;
213220 info.ip .addr = static_cast <uint32_t >(local_ip);
214221 info.gw .addr = static_cast <uint32_t >(gateway);
215222 info.netmask .addr = static_cast <uint32_t >(subnet);
216223
217224 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+ }
219230
220231 // Set DNS-Server
221232 ip_addr_t d;
222233 d.addr = static_cast <uint32_t >(dns);
223234 dns_setserver (0 , &d);
224235
225- _useStaticIp = true ;
236+ return true ;
226237}
227238
228239/* *
@@ -243,7 +254,8 @@ bool ESP8266WiFiSTAClass::reconnect() {
243254 * @param wifioff
244255 * @return one value of wl_status_t enum
245256 */
246- int ESP8266WiFiSTAClass::disconnect (bool wifioff) {
257+ bool ESP8266WiFiSTAClass::disconnect (bool wifioff) {
258+ bool ret;
247259 struct station_config conf;
248260 *conf.ssid = 0 ;
249261 *conf.password = 0 ;
@@ -254,15 +266,14 @@ int ESP8266WiFiSTAClass::disconnect(bool wifioff) {
254266 } else {
255267 wifi_station_set_config_current (&conf);
256268 }
257- wifi_station_disconnect ();
269+ ret = wifi_station_disconnect ();
258270 ETS_UART_INTR_ENABLE ();
259271
260272 if (wifioff) {
261273 WiFi.enableSTA (false );
262274 }
263275
264- // TODO return with more meaning ?
265- return 0 ;
276+ return ret;
266277}
267278
268279/* *
@@ -391,18 +402,20 @@ bool ESP8266WiFiSTAClass::hostname(String aHostname) {
391402 *
392403 */
393404wl_status_t ESP8266WiFiSTAClass::status () {
394- int status = wifi_station_get_connect_status ();
405+ station_status_t status = wifi_station_get_connect_status ();
395406
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;
406419 }
407420}
408421
@@ -543,32 +556,38 @@ bool ESP8266WiFiSTAClass::_smartConfigDone = false;
543556/* *
544557 * Start SmartConfig
545558 */
546- void ESP8266WiFiSTAClass::beginSmartConfig () {
547- if (_smartConfigStarted)
548- return ;
559+ bool ESP8266WiFiSTAClass::beginSmartConfig () {
560+ if (_smartConfigStarted) {
561+ return false ;
562+ }
549563
550564 if (!WiFi.enableSTA (true )) {
551565 // enable STA failed
552- return ;
566+ return false ;
553567 }
554568
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 ;
559575}
560576
561577
562578/* *
563579 * Stop SmartConfig
564580 */
565- void ESP8266WiFiSTAClass::stopSmartConfig () {
581+ bool ESP8266WiFiSTAClass::stopSmartConfig () {
566582 if (!_smartConfigStarted) {
567- return ;
583+ return true ;
568584 }
569585
570- smartconfig_stop ();
571- _smartConfigStarted = false ;
586+ if (smartconfig_stop ()) {
587+ _smartConfigStarted = false ;
588+ return true ;
589+ }
590+ return false ;
572591}
573592
574593/* *
0 commit comments