Skip to content

Commit cdc677a

Browse files
committed
Add TLS support.
1 parent 41df3b5 commit cdc677a

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

cayenne/client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import paho.mqtt.client as mqtt
21
import time
2+
from ssl import PROTOCOL_TLSv1_2
3+
import paho.mqtt.client as mqtt
34
from cayenne import __version__
45

56
# Data types
@@ -140,8 +141,10 @@ def begin(self, username, password, clientid, hostname='mqtt.mydevices.com', por
140141
self.client.on_disconnect = on_disconnect
141142
self.client.on_message = on_message
142143
self.client.username_pw_set(username, password)
144+
if port == 8883:
145+
self.client.tls_set(tls_version=PROTOCOL_TLSv1_2)
143146
self.client.connect(hostname, port, 60)
144-
print("Connecting to %s..." % hostname)
147+
print("Connecting to {}:{}".format(hostname, port))
145148

146149
def loop(self):
147150
"""Process Cayenne messages.

examples/Example-01-SendData.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010

1111
client = cayenne.client.CayenneMQTTClient()
12-
1312
client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)
13+
# For a secure connection use port 8883 when calling client.begin:
14+
# client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID, port=8883)
1415

1516
i=0
1617
timestamp = 0

examples/Example-02-ReceiveData.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@ def on_message(message):
1515
client = cayenne.client.CayenneMQTTClient()
1616
client.on_message = on_message
1717
client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)
18+
# For a secure connection use port 8883 when calling client.begin:
19+
# client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID, port=8883)
1820
client.loop_forever()
1921

examples/Example-03-CayenneClient.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def on_message(message):
1616
client = cayenne.client.CayenneMQTTClient()
1717
client.on_message = on_message
1818
client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)
19+
# For a secure connection use port 8883 when calling client.begin:
20+
# client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID, port=8883)
1921

2022
i=0
2123
timestamp = 0

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
with open(path.join(here, 'README.rst'), encoding='utf-8') as readme:
1010
long_description = readme.read()
1111

12-
classifiers = ['Development Status :: 3 - Alpha',
12+
classifiers = ['Development Status :: 5 - Production/Stable',
1313
'Operating System :: MacOS :: MacOS X',
1414
'Operating System :: Microsoft :: Windows',
1515
'Operating System :: POSIX',
@@ -36,6 +36,6 @@
3636
classifiers = classifiers,
3737
packages = ['cayenne'],
3838
install_requires = [
39-
'paho-mqtt >= 1.0',
39+
'paho-mqtt >= 1.3.0',
4040
],
4141
)

0 commit comments

Comments
 (0)