Skip to content

Expose WiFi Attribute #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions adafruit_minimqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ def __init__(self, socket, broker, port=None, username=None,
self._socket = socket
network_manager_type = str(type(network_manager))
if 'ESPSPI_WiFiManager' in network_manager_type:
self._wifi = network_manager
self.wifi = network_manager
else:
raise TypeError("This library requires a NetworkManager object.")
# broker
try: # set broker IP
self.broker = self._wifi.esp.unpretty_ip(broker)
self.broker = self.wifi.esp.unpretty_ip(broker)
except ValueError: # set broker URL
self.broker = broker
# port/ssl
Expand Down Expand Up @@ -543,15 +543,15 @@ def unsubscribe(self, topic):
def is_wifi_connected(self):
"""Returns if the ESP module is connected to
an access point, resets module if False"""
if self._wifi:
return self._wifi.esp.is_connected
if self.wifi:
return self.wifi.esp.is_connected
raise MMQTTException("MiniMQTT Client does not use a WiFi NetworkManager.")

# pylint: disable=line-too-long, protected-access
@property
def is_sock_connected(self):
"""Returns if the socket is connected."""
return self.is_wifi_connected and self._sock and self._wifi.esp.socket_connected(self._sock._socknum)
return self.is_wifi_connected and self._sock and self.wifi.esp.socket_connected(self._sock._socknum)

def reconnect_socket(self):
"""Re-establishes the socket's connection with the MQTT broker.
Expand All @@ -573,7 +573,7 @@ def reconnect_wifi(self):
try:
if self.logger is not None:
self.logger.debug('Connecting to WiFi AP...')
self._wifi.connect()
self.wifi.connect()
except (RuntimeError, ValueError):
if self.logger is not None:
self.logger.debug('Failed to reset WiFi module, retrying...')
Expand Down Expand Up @@ -611,7 +611,7 @@ def loop_forever(self):
try:
self.loop()
except (RuntimeError, ValueError):
if self._wifi:
if self.wifi:
# Reconnect the WiFi module and the socket
self.reconnect_wifi()
continue
Expand Down Expand Up @@ -721,8 +721,8 @@ def _set_interface(self):
The network hardware must be set in init
prior to calling this method.
"""
if self._wifi:
self._socket.set_interface(self._wifi.esp)
if self.wifi:
self._socket.set_interface(self.wifi.esp)
else:
raise TypeError('Network Manager Required.')

Expand Down