Skip to content

Added option to specifiy transport to connect keyword. #26

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions src/MQTTLibrary/MQTTKeywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def set_username_and_password(self, username, password=None):
self._username = username
self._password = password

def connect(self, broker, port=1883, client_id="", clean_session=True):
def connect(self, broker, port=1883, client_id="", clean_session=True, transport="tcp"):
""" Connect to an MQTT broker. This is a pre-requisite step for publish
and subscribe keywords.

Expand All @@ -53,6 +53,8 @@ def connect(self, broker, port=1883, client_id="", clean_session=True):

`clean_session` specifies the clean session flag for the connection

`tranport` use "websockets" to send MQTT over WebSockets, leave at the default of "tcp" to use raw TCP

Examples:

Connect to a broker with default port and client id
Expand All @@ -64,11 +66,14 @@ def connect(self, broker, port=1883, client_id="", clean_session=True):
Connect to a broker with clean session flag set to false
| Connect | 127.0.0.1 | clean_session=${false} |

Connect to a broker using websockets
| Connect | 127.0.0.1 | transport=websockets

"""
logger.info('Connecting to %s at port %s' % (broker, port))
self._connected = False
self._unexpected_disconnect = False
self._mqttc = mqtt.Client(client_id, clean_session)
self._mqttc = mqtt.Client(client_id, clean_session, transport=transport)

# set callbacks
self._mqttc.on_connect = self._on_connect
Expand Down