@@ -399,6 +399,9 @@ uint8_t WiFiSTAClass::waitForConnectResult()
399
399
*/
400
400
IPAddress WiFiSTAClass::localIP ()
401
401
{
402
+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
403
+ return IPAddress ();
404
+ }
402
405
tcpip_adapter_ip_info_t ip;
403
406
tcpip_adapter_get_ip_info (TCPIP_ADAPTER_IF_STA, &ip);
404
407
return IPAddress (ip.ip .addr );
@@ -412,7 +415,9 @@ IPAddress WiFiSTAClass::localIP()
412
415
*/
413
416
uint8_t * WiFiSTAClass::macAddress (uint8_t * mac)
414
417
{
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
+ }
416
421
return mac;
417
422
}
418
423
@@ -424,6 +429,9 @@ String WiFiSTAClass::macAddress(void)
424
429
{
425
430
uint8_t mac[6 ];
426
431
char macStr[18 ] = { 0 };
432
+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
433
+ return String ();
434
+ }
427
435
esp_wifi_get_mac (WIFI_IF_STA, mac);
428
436
429
437
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)
436
444
*/
437
445
IPAddress WiFiSTAClass::subnetMask ()
438
446
{
447
+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
448
+ return IPAddress ();
449
+ }
439
450
tcpip_adapter_ip_info_t ip;
440
451
tcpip_adapter_get_ip_info (TCPIP_ADAPTER_IF_STA, &ip);
441
452
return IPAddress (ip.netmask .addr );
@@ -447,6 +458,9 @@ IPAddress WiFiSTAClass::subnetMask()
447
458
*/
448
459
IPAddress WiFiSTAClass::gatewayIP ()
449
460
{
461
+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
462
+ return IPAddress ();
463
+ }
450
464
tcpip_adapter_ip_info_t ip;
451
465
tcpip_adapter_get_ip_info (TCPIP_ADAPTER_IF_STA, &ip);
452
466
return IPAddress (ip.gw .addr );
@@ -459,6 +473,9 @@ IPAddress WiFiSTAClass::gatewayIP()
459
473
*/
460
474
IPAddress WiFiSTAClass::dnsIP (uint8_t dns_no)
461
475
{
476
+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
477
+ return IPAddress ();
478
+ }
462
479
ip_addr_t dns_ip = dns_getserver (dns_no);
463
480
return IPAddress (dns_ip.u_addr .ip4 .addr );
464
481
}
@@ -469,6 +486,9 @@ IPAddress WiFiSTAClass::dnsIP(uint8_t dns_no)
469
486
*/
470
487
String WiFiSTAClass::SSID () const
471
488
{
489
+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
490
+ return String ();
491
+ }
472
492
wifi_ap_record_t info;
473
493
if (!esp_wifi_sta_get_ap_info (&info)) {
474
494
return String (reinterpret_cast <char *>(info.ssid ));
@@ -482,6 +502,9 @@ String WiFiSTAClass::SSID() const
482
502
*/
483
503
String WiFiSTAClass::psk () const
484
504
{
505
+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
506
+ return String ();
507
+ }
485
508
wifi_config_t conf;
486
509
esp_wifi_get_config (WIFI_IF_STA, &conf);
487
510
return String (reinterpret_cast <char *>(conf.sta .password ));
@@ -495,6 +518,9 @@ uint8_t* WiFiSTAClass::BSSID(void)
495
518
{
496
519
static uint8_t bssid[6 ];
497
520
wifi_ap_record_t info;
521
+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
522
+ return NULL ;
523
+ }
498
524
if (!esp_wifi_sta_get_ap_info (&info)) {
499
525
memcpy (bssid, info.bssid , 6 );
500
526
return reinterpret_cast <uint8_t *>(bssid);
@@ -523,6 +549,9 @@ String WiFiSTAClass::BSSIDstr(void)
523
549
*/
524
550
int8_t WiFiSTAClass::RSSI (void )
525
551
{
552
+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
553
+ return 0 ;
554
+ }
526
555
wifi_ap_record_t info;
527
556
if (!esp_wifi_sta_get_ap_info (&info)) {
528
557
return info.rssi ;
@@ -536,7 +565,10 @@ int8_t WiFiSTAClass::RSSI(void)
536
565
*/
537
566
const char * WiFiSTAClass::getHostname ()
538
567
{
539
- const char * hostname;
568
+ const char * hostname = NULL ;
569
+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
570
+ return hostname;
571
+ }
540
572
if (tcpip_adapter_get_hostname (TCPIP_ADAPTER_IF_STA, &hostname)){
541
573
return NULL ;
542
574
}
@@ -550,6 +582,9 @@ const char * WiFiSTAClass::getHostname()
550
582
*/
551
583
bool WiFiSTAClass::setHostname (const char * hostname)
552
584
{
585
+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
586
+ return false ;
587
+ }
553
588
return tcpip_adapter_set_hostname (TCPIP_ADAPTER_IF_STA, hostname) == 0 ;
554
589
}
555
590
@@ -559,6 +594,9 @@ bool WiFiSTAClass::setHostname(const char * hostname)
559
594
*/
560
595
bool WiFiSTAClass::enableIpV6 ()
561
596
{
597
+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
598
+ return false ;
599
+ }
562
600
return tcpip_adapter_create_ip6_linklocal (TCPIP_ADAPTER_IF_STA) == 0 ;
563
601
}
564
602
@@ -569,6 +607,9 @@ bool WiFiSTAClass::enableIpV6()
569
607
IPv6Address WiFiSTAClass::localIPv6 ()
570
608
{
571
609
static ip6_addr_t addr;
610
+ if (WiFiGenericClass::getMode () == WIFI_MODE_NULL){
611
+ return IPv6Address ();
612
+ }
572
613
if (tcpip_adapter_get_ip6_linklocal (TCPIP_ADAPTER_IF_STA, &addr)){
573
614
return IPv6Address ();
574
615
}
0 commit comments