本文整理汇总了Python中Adafruit_IO.MQTTClient.is_connected方法的典型用法代码示例。如果您正苦于以下问题:Python MQTTClient.is_connected方法的具体用法?Python MQTTClient.is_connected怎么用?Python MQTTClient.is_connected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Adafruit_IO.MQTTClient
的用法示例。
在下文中一共展示了MQTTClient.is_connected方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_connect
# 需要导入模块: from Adafruit_IO import MQTTClient [as 别名]
# 或者: from Adafruit_IO.MQTTClient import is_connected [as 别名]
def test_connect(self):
# Create MQTT test client.
client = MQTTClient(self.get_test_username(), self.get_test_key())
# Verify on_connect handler is called and expected client is provided.
def on_connect(mqtt_client):
self.assertEqual(mqtt_client, client)
client.on_connect = on_connect
# Connect and wait until on_connect event is fired.
client.connect()
self.wait_until_connected(client)
# Verify connected.
self.assertTrue(client.is_connected())
示例2: test_disconnect
# 需要导入模块: from Adafruit_IO import MQTTClient [as 别名]
# 或者: from Adafruit_IO.MQTTClient import is_connected [as 别名]
def test_disconnect(self):
# Create MQTT test client.
client = MQTTClient(self.get_test_username(), self.get_test_key())
# Verify on_connect handler is called and expected client is provided.
def on_disconnect(mqtt_client):
self.assertEqual(mqtt_client, client)
client.on_disconnect = on_disconnect
# Connect and wait until on_connect event is fired.
client.connect()
self.wait_until_connected(client)
# Now disconnect and wait until disconnection event occurs.
client.disconnect()
self.wait_until_connected(client, connect_value=False)
# Verify diconnected.
self.assertFalse(client.is_connected())
示例3: test_secure_connect
# 需要导入模块: from Adafruit_IO import MQTTClient [as 别名]
# 或者: from Adafruit_IO.MQTTClient import is_connected [as 别名]
def test_secure_connect(self):
"""Test a secure (port 8883, TLS enabled) AIO connection
"""
# Create MQTT-Secure test client.
client = MQTTClient(self.get_test_username(), self.get_test_key())
# Verify on_connect handler is called and expected client is provided.
def on_connect(mqtt_client):
self.assertEqual(mqtt_client, client)
client.on_connect = on_connect
# Connect and wait until on_connect event is fired.
client.connect()
self.wait_until_connected(client)
# Verify connected.
self.assertTrue(client.is_connected())
self.assertTrue(client._secure)
示例4: test_insecure_connect
# 需要导入模块: from Adafruit_IO import MQTTClient [as 别名]
# 或者: from Adafruit_IO.MQTTClient import is_connected [as 别名]
def test_insecure_connect(self):
"""Test an insecure (port 1883, TLS disabled) AIO connection
"""
# Create MQTT-Insecure (non-SSL) test client.
client = MQTTClient(self.get_test_username(), self.get_test_key(), secure=False)
# Verify on_connect handler is called and expected client is provided.
def on_connect(mqtt_client):
self.assertEqual(mqtt_client, client)
client.on_connect = on_connect
# Connect and wait until on_connect event is fired.
client.connect()
self.wait_until_connected(client)
# Verify connected.
self.assertTrue(client.is_connected())
# Verify insecure connection established
self.assertFalse(client._secure)
示例5: test_create_client
# 需要导入模块: from Adafruit_IO import MQTTClient [as 别名]
# 或者: from Adafruit_IO.MQTTClient import is_connected [as 别名]
def test_create_client(self):
# Create MQTT test client.
client = MQTTClient(self.get_test_username(), self.get_test_key())
# Verify not connected by default.
self.assertFalse(client.is_connected())