Skip to content
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