Skip to content

Commit

Permalink
Add TLS support.
Browse files Browse the repository at this point in the history
  • Loading branch information
jburhenn committed Feb 16, 2018
1 parent 41df3b5 commit cdc677a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
7 changes: 5 additions & 2 deletions cayenne/client.py
@@ -1,5 +1,6 @@
import paho.mqtt.client as mqtt
import time
from ssl import PROTOCOL_TLSv1_2
import paho.mqtt.client as mqtt
from cayenne import __version__

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

def loop(self):
"""Process Cayenne messages.
Expand Down
3 changes: 2 additions & 1 deletion examples/Example-01-SendData.py
Expand Up @@ -9,8 +9,9 @@


client = cayenne.client.CayenneMQTTClient()

client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)
# For a secure connection use port 8883 when calling client.begin:
# client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID, port=8883)

i=0
timestamp = 0
Expand Down
2 changes: 2 additions & 0 deletions examples/Example-02-ReceiveData.py
Expand Up @@ -15,5 +15,7 @@ def on_message(message):
client = cayenne.client.CayenneMQTTClient()
client.on_message = on_message
client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)
# For a secure connection use port 8883 when calling client.begin:
# client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID, port=8883)
client.loop_forever()

2 changes: 2 additions & 0 deletions examples/Example-03-CayenneClient.py
Expand Up @@ -16,6 +16,8 @@ def on_message(message):
client = cayenne.client.CayenneMQTTClient()
client.on_message = on_message
client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)
# For a secure connection use port 8883 when calling client.begin:
# client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID, port=8883)

i=0
timestamp = 0
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Expand Up @@ -9,7 +9,7 @@
with open(path.join(here, 'README.rst'), encoding='utf-8') as readme:
long_description = readme.read()

classifiers = ['Development Status :: 3 - Alpha',
classifiers = ['Development Status :: 5 - Production/Stable',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
Expand All @@ -36,6 +36,6 @@
classifiers = classifiers,
packages = ['cayenne'],
install_requires = [
'paho-mqtt >= 1.0',
'paho-mqtt >= 1.3.0',
],
)

0 comments on commit cdc677a

Please sign in to comment.