@@ -399,6 +399,9 @@ uint8_t WiFiSTAClass::waitForConnectResult()
399399 */
400400IPAddress WiFiSTAClass::localIP ()
401401{
402+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
403+ return IPAddress ();
404+ }
402405 tcpip_adapter_ip_info_t ip;
403406 tcpip_adapter_get_ip_info (TCPIP_ADAPTER_IF_STA, &ip);
404407 return IPAddress (ip.ip .addr );
@@ -412,7 +415,9 @@ IPAddress WiFiSTAClass::localIP()
412415 */
413416uint8_t * WiFiSTAClass::macAddress (uint8_t * mac)
414417{
415- esp_wifi_get_mac (WIFI_IF_STA, mac);
418+ if (WiFiGenericClass::getMode () != WIFI_MODE_NULL){
419+ esp_wifi_get_mac (WIFI_IF_STA, mac);
420+ }
416421 return mac;
417422}
418423
@@ -424,6 +429,9 @@ String WiFiSTAClass::macAddress(void)
424429{
425430 uint8_t mac[6 ];
426431 char macStr[18 ] = { 0 };
432+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
433+ return String ();
434+ }
427435 esp_wifi_get_mac (WIFI_IF_STA, mac);
428436
429437 sprintf (macStr, " %02X:%02X:%02X:%02X:%02X:%02X" , mac[0 ], mac[1 ], mac[2 ], mac[3 ], mac[4 ], mac[5 ]);
@@ -436,6 +444,9 @@ String WiFiSTAClass::macAddress(void)
436444 */
437445IPAddress WiFiSTAClass::subnetMask ()
438446{
447+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
448+ return IPAddress ();
449+ }
439450 tcpip_adapter_ip_info_t ip;
440451 tcpip_adapter_get_ip_info (TCPIP_ADAPTER_IF_STA, &ip);
441452 return IPAddress (ip.netmask .addr );
@@ -447,6 +458,9 @@ IPAddress WiFiSTAClass::subnetMask()
447458 */
448459IPAddress WiFiSTAClass::gatewayIP ()
449460{
461+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
462+ return IPAddress ();
463+ }
450464 tcpip_adapter_ip_info_t ip;
451465 tcpip_adapter_get_ip_info (TCPIP_ADAPTER_IF_STA, &ip);
452466 return IPAddress (ip.gw .addr );
@@ -459,6 +473,9 @@ IPAddress WiFiSTAClass::gatewayIP()
459473 */
460474IPAddress WiFiSTAClass::dnsIP (uint8_t dns_no)
461475{
476+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
477+ return IPAddress ();
478+ }
462479 ip_addr_t dns_ip = dns_getserver (dns_no);
463480 return IPAddress (dns_ip.u_addr .ip4 .addr );
464481}
@@ -469,6 +486,9 @@ IPAddress WiFiSTAClass::dnsIP(uint8_t dns_no)
469486 */
470487String WiFiSTAClass::SSID () const
471488{
489+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
490+ return String ();
491+ }
472492 wifi_ap_record_t info;
473493 if (!esp_wifi_sta_get_ap_info (&info)) {
474494 return String (reinterpret_cast <char *>(info.ssid ));
@@ -482,6 +502,9 @@ String WiFiSTAClass::SSID() const
482502 */
483503String WiFiSTAClass::psk () const
484504{
505+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
506+ return String ();
507+ }
485508 wifi_config_t conf;
486509 esp_wifi_get_config (WIFI_IF_STA, &conf);
487510 return String (reinterpret_cast <char *>(conf.sta .password ));
@@ -495,6 +518,9 @@ uint8_t* WiFiSTAClass::BSSID(void)
495518{
496519 static uint8_t bssid[6 ];
497520 wifi_ap_record_t info;
521+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
522+ return NULL ;
523+ }
498524 if (!esp_wifi_sta_get_ap_info (&info)) {
499525 memcpy (bssid, info.bssid , 6 );
500526 return reinterpret_cast <uint8_t *>(bssid);
@@ -523,6 +549,9 @@ String WiFiSTAClass::BSSIDstr(void)
523549 */
524550int8_t WiFiSTAClass::RSSI (void )
525551{
552+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
553+ return 0 ;
554+ }
526555 wifi_ap_record_t info;
527556 if (!esp_wifi_sta_get_ap_info (&info)) {
528557 return info.rssi ;
@@ -536,7 +565,10 @@ int8_t WiFiSTAClass::RSSI(void)
536565 */
537566const char * WiFiSTAClass::getHostname ()
538567{
539- const char * hostname;
568+ const char * hostname = NULL ;
569+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
570+ return hostname;
571+ }
540572 if (tcpip_adapter_get_hostname (TCPIP_ADAPTER_IF_STA, &hostname)){
541573 return NULL ;
542574 }
@@ -550,6 +582,9 @@ const char * WiFiSTAClass::getHostname()
550582 */
551583bool WiFiSTAClass::setHostname (const char * hostname)
552584{
585+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
586+ return false ;
587+ }
553588 return tcpip_adapter_set_hostname (TCPIP_ADAPTER_IF_STA, hostname) == 0 ;
554589}
555590
@@ -559,6 +594,9 @@ bool WiFiSTAClass::setHostname(const char * hostname)
559594 */
560595bool WiFiSTAClass::enableIpV6 ()
561596{
597+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
598+ return false ;
599+ }
562600 return tcpip_adapter_create_ip6_linklocal (TCPIP_ADAPTER_IF_STA) == 0 ;
563601}
564602
@@ -569,6 +607,9 @@ bool WiFiSTAClass::enableIpV6()
569607IPv6Address WiFiSTAClass::localIPv6 ()
570608{
571609 static ip6_addr_t addr;
610+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
611+ return IPv6Address ();
612+ }
572613 if (tcpip_adapter_get_ip6_linklocal (TCPIP_ADAPTER_IF_STA, &addr)){
573614 return IPv6Address ();
574615 }
0 commit comments