diff --git a/adafruit_esp32spi/adafruit_esp32spi.py b/adafruit_esp32spi/adafruit_esp32spi.py index 4c3fc5f..a124323 100644 --- a/adafruit_esp32spi/adafruit_esp32spi.py +++ b/adafruit_esp32spi/adafruit_esp32spi.py @@ -372,12 +372,12 @@ def MAC_address(self): # pylint: disable=invalid-name @property def MAC_address_actual(self): # pylint: disable=invalid-name """A bytearray containing the actual MAC address of the ESP32""" - if self._debug: - print("MAC address") - resp = self._send_command_get_response(_GET_MACADDR_CMD, [b"\xFF"]) - new_resp = bytearray(resp[0]) - new_resp = reversed(new_resp) - return new_resp + return bytearray(reversed(self.MAC_address)) + + @property + def mac_address(self): + """A bytes containing the actual MAC address of the ESP32""" + return bytes(self.MAC_address_actual) def start_scan_networks(self): """Begin a scan of visible access points. Follow up with a call @@ -545,7 +545,7 @@ def ip_address(self): return self.network_data["ip_addr"] @property - def is_connected(self): + def connected(self): """Whether the ESP32 is connected to an access point""" try: return self.status == WL_CONNECTED @@ -553,6 +553,11 @@ def is_connected(self): self.reset() return False + @property + def is_connected(self): + """Whether the ESP32 is connected to an access point""" + return self.connected + @property def ap_listening(self): """Returns if the ESP32 is in access point mode and is listening for connections""" @@ -568,10 +573,17 @@ def disconnect(self): if resp[0][0] != 1: raise OSError("Failed to disconnect") - def connect(self, secrets): - """Connect to an access point using a secrets dictionary - that contains a 'ssid' and 'password' entry""" - self.connect_AP(secrets["ssid"], secrets["password"]) + def connect(self, ssid, password=None, timeout=10): + """Connect to an access point with given name and password. + + **Deprecated functionality:** If the first argument (``ssid``) is a ``dict``, + assume it is a dictionary with entries for keys ``"ssid"`` and, optionally, ``"password"``. + This mimics the previous signature for ``connect()``. + This upward compatbility will be removed in a future release. + """ + if isinstance(ssid, dict): # secrets + ssid, password = ssid["ssid"], ssid.get("password") + self.connect_AP(ssid, password, timeout_s=timeout) def connect_AP(self, ssid, password, timeout_s=10): # pylint: disable=invalid-name """Connect to an access point with given name and password. @@ -647,6 +659,11 @@ def create_AP( raise ConnectionError("Failed to create AP", ssid) raise OSError("Unknown error 0x%02x" % stat) + @property + def ipv4_address(self): + """IP address of the station when connected to an access point.""" + return self.pretty_ip(self.ip_address) + def pretty_ip(self, ip): # pylint: disable=no-self-use, invalid-name """Converts a bytearray IP address to a dotted-quad string for printing""" return "%d.%d.%d.%d" % (ip[0], ip[1], ip[2], ip[3])