当前位置: 首页>>代码示例>>Python>>正文


Python MQTTClient.disconnect方法代码示例

本文整理汇总了Python中Adafruit_IO.MQTTClient.disconnect方法的典型用法代码示例。如果您正苦于以下问题:Python MQTTClient.disconnect方法的具体用法?Python MQTTClient.disconnect怎么用?Python MQTTClient.disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Adafruit_IO.MQTTClient的用法示例。


在下文中一共展示了MQTTClient.disconnect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_disconnect

# 需要导入模块: from Adafruit_IO import MQTTClient [as 别名]
# 或者: from Adafruit_IO.MQTTClient import disconnect [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())
开发者ID:adafruit,项目名称:io-client-python,代码行数:17,代码来源:test_mqtt_client.py

示例2: AdafruitNotifier

# 需要导入模块: from Adafruit_IO import MQTTClient [as 别名]
# 或者: from Adafruit_IO.MQTTClient import disconnect [as 别名]
class AdafruitNotifier(Notifier):
    # TODO: consider supporting this directly in thingamon and not using
    # the adafruit package. both have the same paho mqtt connection logic.
    # adafruit does not lock the connected state variable, thingamon does
    # not sure which is right yet
    def __init__(self, username=None, api_key=None, host='io.adafruit.com',
                 port=1883):
        """
        Create an Adafruit MQTT notifier

        Args:
            host (str): host name of Adafruit MQTT broker
            port (int): port of Adafruit MQTT broker
            username (str): Adafruit IO username
            api_key (str): Adafruit IO API key
        """
        self.log = logging.getLogger('thingpin')
        self.username = username
        self.api_key = api_key
        self.host = host
        self.port = port
        self.client = None

    def initialize(self):
        self.client = MQTTClient(self.username, self.api_key,
                                 service_host=self.host,
                                 service_port=self.port)

        def on_disconnect(client):
            if client.disconnect_reason != 0:
                self.log.info('client disconnected, exiting')
                os._exit(1)

        self.client.on_disconnect = on_disconnect

        self.client.connect()
        self.log.info('connected to Adafruit')
        self.client.loop_background()

    def cleanup(self):
        self.client.disconnect()

    def notify(self, name, value):
        self.log.info('Adafruit IO: publish({}={})'.format(name, value))
        self.client.publish(name, value['state'])
开发者ID:dmreiland,项目名称:thingpin,代码行数:47,代码来源:notifiers.py

示例3: print

# 需要导入模块: from Adafruit_IO import MQTTClient [as 别名]
# 或者: from Adafruit_IO.MQTTClient import disconnect [as 别名]
    print(msg.topic+" "+str(msg.payload))

def on_publish(client, userdata, mid):
    print("data sent")

def on_disconnect(client, userdata, rc):
    print("disconnect")

client = MQTTClient(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY,service_port=8883)
client.on_connect = on_connect
client.on_message = on_message
client.on_publish = on_publish
client.on_disconnect = on_disconnect
client.tls_set("/home/pi/adafruitio-temperature/certs/geotrust.pem")
client.connect()
#client.loop_background()

# Get temperature from sensor
#byte1 = 29
#byte2 = 0x00
#temperature = ((byte1 << 8) + byte2) >> 4
#if (temperature & 0x800):
#    temperature = (temperature & 0x7FF) - 0x800
#temperature = temperature * 0.0625
#temperature = 30
temperature = tempSensor.readTemperature()
print("temperature "+str(temperature))
client.publish("bedroom",temperature)

client.disconnect()
开发者ID:vorasilp,项目名称:adafruitio-temperature,代码行数:32,代码来源:adafruitio_ssl.py


注:本文中的Adafruit_IO.MQTTClient.disconnect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。