@@ -35,24 +35,29 @@ class MQTTClient(object):
35
35
using the MQTT protocol.
36
36
"""
37
37
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 ):
39
39
"""Create instance of MQTT client.
40
40
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
45
44
"""
46
45
self ._username = username
47
46
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
49
51
# Initialize event callbacks to be None so they don't fire.
50
52
self .on_connect = None
51
53
self .on_disconnect = None
52
54
self .on_message = None
53
55
# Initialize MQTT client.
54
56
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' )
56
61
self ._client .username_pw_set (username , key )
57
62
self ._client .on_connect = self ._mqtt_connect
58
63
self ._client .on_disconnect = self ._mqtt_disconnect
0 commit comments