Skip to content

Commit 4230bdc

Browse files
author
brentru
committed
added strict error checking for params
1 parent 9d41966 commit 4230bdc

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

Adafruit_IO/mqtt_client.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,29 @@ class MQTTClient(object):
3535
using the MQTT protocol.
3636
"""
3737

38-
def __init__(self, username, key, service_host='io.adafruit.com', service_port=8883):
38+
def __init__(self, username, key, service_host='io.adafruit.com', secure=True):
3939
"""Create instance of MQTT client.
4040
41-
Required parameters:
42-
- username: The Adafruit.IO username for your account (found on the
43-
accounts site https://accounts.adafruit.com/).
44-
- key: The Adafruit.IO access key for your account.
41+
:param username: Adafruit.IO Username for your account.
42+
:param key: Adafruit IO access key (AIO Key) for your account.
43+
:param secure: (optional, boolean) Switches secure/insecure connections
4544
"""
4645
self._username = username
4746
self._service_host = service_host
48-
self._service_port = service_port
47+
if secure:
48+
self._service_port = 8883
49+
elif not secure:
50+
self._service_port = 1883
4951
# Initialize event callbacks to be None so they don't fire.
5052
self.on_connect = None
5153
self.on_disconnect = None
5254
self.on_message = None
5355
# Initialize MQTT client.
5456
self._client = mqtt.Client()
55-
self._client.tls_set_context() # mqqts
57+
if secure:
58+
self._client.tls_set_context()
59+
elif not secure:
60+
print('**THIS CONNECTION IS INSECURE** SSL/TLS not supported for this platform')
5661
self._client.username_pw_set(username, key)
5762
self._client.on_connect = self._mqtt_connect
5863
self._client.on_disconnect = self._mqtt_disconnect

0 commit comments

Comments
 (0)