Skip to content

do not hard-code TLS port value #139

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

Merged
merged 2 commits into from
Jan 9, 2023
Merged
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
7 changes: 4 additions & 3 deletions adafruit_minimqtt/adafruit_minimqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ class MQTT:
"""MQTT Client for CircuitPython.

:param str broker: MQTT Broker URL or IP Address.
:param int port: Optional port definition, defaults to 8883.
:param int port: Optional port definition, defaults to MQTT_TLS_PORT if is_ssl is True,
MQTT_TCP_PORT otherwise.
:param str username: Username for broker authentication.
:param str password: Password for broker authentication.
:param network_manager: NetworkManager object, such as WiFiManager from ESPSPI_WiFiManager.
Expand Down Expand Up @@ -252,7 +253,7 @@ def _get_connect_socket(self, host, port, *, timeout=1):
if not isinstance(port, int):
raise RuntimeError("Port must be an integer")

if port == 8883 and not self._ssl_context:
if port == MQTT_TLS_PORT and not self._ssl_context:
raise RuntimeError(
"ssl_context must be set before using adafruit_mqtt for secure MQTT."
)
Expand Down Expand Up @@ -282,7 +283,7 @@ def _get_connect_socket(self, host, port, *, timeout=1):
continue

connect_host = addr_info[-1][0]
if port == 8883:
if port == MQTT_TLS_PORT:
sock = self._ssl_context.wrap_socket(sock, server_hostname=host)
connect_host = host
sock.settimeout(timeout)
Expand Down