@@ -372,12 +372,12 @@ def MAC_address(self): # pylint: disable=invalid-name
372
372
@property
373
373
def MAC_address_actual (self ): # pylint: disable=invalid-name
374
374
"""A bytearray containing the actual MAC address of the ESP32"""
375
- if self ._debug :
376
- print ( "MAC address" )
377
- resp = self . _send_command_get_response ( _GET_MACADDR_CMD , [ b" \xFF " ])
378
- new_resp = bytearray ( resp [ 0 ])
379
- new_resp = reversed ( new_resp )
380
- return new_resp
375
+ return bytearray ( reversed ( self .MAC_address ))
376
+
377
+ @ property
378
+ def mac_address ( self ):
379
+ """A bytes containing the actual MAC address of the ESP32"""
380
+ return bytes ( self . MAC_address_actual )
381
381
382
382
def start_scan_networks (self ):
383
383
"""Begin a scan of visible access points. Follow up with a call
@@ -545,14 +545,19 @@ def ip_address(self):
545
545
return self .network_data ["ip_addr" ]
546
546
547
547
@property
548
- def is_connected (self ):
548
+ def connected (self ):
549
549
"""Whether the ESP32 is connected to an access point"""
550
550
try :
551
551
return self .status == WL_CONNECTED
552
552
except OSError :
553
553
self .reset ()
554
554
return False
555
555
556
+ @property
557
+ def is_connected (self ):
558
+ """Whether the ESP32 is connected to an access point"""
559
+ return self .connected
560
+
556
561
@property
557
562
def ap_listening (self ):
558
563
"""Returns if the ESP32 is in access point mode and is listening for connections"""
@@ -568,10 +573,17 @@ def disconnect(self):
568
573
if resp [0 ][0 ] != 1 :
569
574
raise OSError ("Failed to disconnect" )
570
575
571
- def connect (self , secrets ):
572
- """Connect to an access point using a secrets dictionary
573
- that contains a 'ssid' and 'password' entry"""
574
- self .connect_AP (secrets ["ssid" ], secrets ["password" ])
576
+ def connect (self , ssid , password = None , timeout = 10 ):
577
+ """Connect to an access point with given name and password.
578
+
579
+ **Deprecated functionality:** If the first argument (``ssid``) is a ``dict``,
580
+ assume it is a dictionary with entries for keys ``"ssid"`` and, optionally, ``"password"``.
581
+ This mimics the previous signature for ``connect()``.
582
+ This upward compatbility will be removed in a future release.
583
+ """
584
+ if isinstance (ssid , dict ): # secrets
585
+ ssid , password = ssid ["ssid" ], ssid .get ("password" )
586
+ self .connect_AP (ssid , password , timeout_s = timeout )
575
587
576
588
def connect_AP (self , ssid , password , timeout_s = 10 ): # pylint: disable=invalid-name
577
589
"""Connect to an access point with given name and password.
@@ -647,6 +659,11 @@ def create_AP(
647
659
raise ConnectionError ("Failed to create AP" , ssid )
648
660
raise OSError ("Unknown error 0x%02x" % stat )
649
661
662
+ @property
663
+ def ipv4_address (self ):
664
+ """IP address of the station when connected to an access point."""
665
+ return self .pretty_ip (self .ip_address )
666
+
650
667
def pretty_ip (self , ip ): # pylint: disable=no-self-use, invalid-name
651
668
"""Converts a bytearray IP address to a dotted-quad string for printing"""
652
669
return "%d.%d.%d.%d" % (ip [0 ], ip [1 ], ip [2 ], ip [3 ])
0 commit comments