當前位置: 首頁>>代碼示例>>Python>>正文


Python client.connack_string方法代碼示例

本文整理匯總了Python中paho.mqtt.client.connack_string方法的典型用法代碼示例。如果您正苦於以下問題:Python client.connack_string方法的具體用法?Python client.connack_string怎麽用?Python client.connack_string使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在paho.mqtt.client的用法示例。


在下文中一共展示了client.connack_string方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _start_client

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import connack_string [as 別名]
def _start_client(self):
        self.mqtt_client = mqtt.Client(self.config.mqtt_client_id)
        if self.config.mqtt_user is not None:
            self.mqtt_client.username_pw_set(self.config.mqtt_user, self.config.mqtt_password)
        if self.config.mqtt_ca_cert is not None:
            self.mqtt_client.tls_set(self.config.mqtt_ca_cert, cert_reqs=mqtt.ssl.CERT_REQUIRED)

        def _on_connect(client, _, flags, return_code):
            self.connected = True
            logging.info("MQTT connection returned result: %s", mqtt.connack_string(return_code))
        self.mqtt_client.on_connect = _on_connect

        self.mqtt_client.connect(self.config.mqtt_server, self.config.mqtt_port, 60)
        self.mqtt_client.loop_start() 
開發者ID:ChristianKuehnel,項目名稱:plantgateway,代碼行數:16,代碼來源:plantgw.py

示例2: _on_connect

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import connack_string [as 別名]
def _on_connect(self, client, userdata, flags, rc):
        """
        Callback function called on connect
        """
        self._connect_result = mqtt.connack_string(rc)

        if rc == 0:
            self.logger.info("Connection returned result '{}' (userdata={}) ".format(mqtt.connack_string(rc), userdata))
            self._connected = True

            self._subscribe_broker_infos()

            # subscribe to topics to listen for items
            for topic in self._subscribed_topics:
                item = self._subscribed_topics[topic]
                self._client.subscribe(topic, qos=self._get_qos_forTopic(item) )
                self.logger.info("Listening on topic '{}' for item '{}'".format( topic, item.id() ))

            self.logger.info("self._subscribed_topics = {}".format(self._subscribed_topics))

            return

        msg = "Connection returned result '{}': {} (client={}, userdata={}, self._client={})".format( str(rc), mqtt.connack_string(rc), client, userdata, self._client )
        if rc == 5:
            self.logger.error(msg)
            self._disconnect_from_broker()
        else:
            self.logger.warning(msg) 
開發者ID:smarthomeNG,項目名稱:smarthome,代碼行數:30,代碼來源:__init__.py

示例3: _create_error_from_connack_rc_code

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import connack_string [as 別名]
def _create_error_from_connack_rc_code(rc):
    """
    Given a paho CONNACK rc code, return an Exception that can be raised
    """
    message = mqtt.connack_string(rc)
    if rc in paho_connack_rc_to_error:
        return paho_connack_rc_to_error[rc](message)
    else:
        return exceptions.ProtocolClientError("Unknown CONNACK rc={}".format(rc)) 
開發者ID:Azure,項目名稱:azure-iot-sdk-python,代碼行數:11,代碼來源:mqtt_transport.py

示例4: on_connect

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import connack_string [as 別名]
def on_connect(client, userdata, rc):
    print "Connected with result code: %s" % mqtt.connack_string(rc)
    for config in CONFIG['doors']:
        command_topic = config['command_topic']
        print "Listening for commands on %s" % command_topic
        client.subscribe(command_topic)

# Execute the specified command for a door 
開發者ID:Jerrkawz,項目名稱:GarageQTPi,代碼行數:10,代碼來源:main.py

示例5: _create_error_from_conack_rc_code

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import connack_string [as 別名]
def _create_error_from_conack_rc_code(rc):
    """
    Given a paho CONACK rc code, return an Exception that can be raised
    """
    message = mqtt.connack_string(rc)
    if rc in paho_conack_rc_to_error:
        return paho_conack_rc_to_error[rc](message)
    else:
        return errors.ProtocolClientError("Unknown CONACK rc={}".format(rc)) 
開發者ID:Azure,項目名稱:azure-iot-sdk-python-preview,代碼行數:11,代碼來源:mqtt_transport.py

示例6: on_connect

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import connack_string [as 別名]
def on_connect(unused_client, unused_userdata, unused_flags, rc):
    """Callback for when a device connects."""
    print('on_connect', mqtt.connack_string(rc))

    # After a successful connect, reset backoff time and stop backing off.
    global should_backoff
    global minimum_backoff_time
    should_backoff = False
    minimum_backoff_time = 1 
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:11,代碼來源:cloudiot_mqtt_example.py

示例7: on_connect

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import connack_string [as 別名]
def on_connect(client, unused_userdata, unused_flags, rc):
    """Callback for when a device connects."""
    print('on_connect', mqtt.connack_string(rc))

    gateway_state.connected = True

    # Subscribe to the config topic.
    client.subscribe(gateway_state.mqtt_config_topic, qos=1) 
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:10,代碼來源:gateway.py

示例8: locust_on_connect

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import connack_string [as 別名]
def locust_on_connect(self, client, flags_dict, userdata, rc):
        #print("Connection returned result: "+mqtt.connack_string(rc))        
        fire_locust_success(
            request_type=REQUEST_TYPE,
            name='connect',
            response_time=0,
            response_length=0
            ) 
開發者ID:concurrencylabs,項目名稱:mqtt-locust,代碼行數:10,代碼來源:mqtt_locust.py

示例9: on_connect

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import connack_string [as 別名]
def on_connect(client, userdata, flags, rc):
    print("Result from connect: {}".format(
        mqtt.connack_string(rc)))
    # Check whether the result form connect is the CONNACK_ACCEPTED connack code
    if rc != mqtt.CONNACK_ACCEPTED:
        raise IOError("I couldn't establish a connection with the MQTT server") 
開發者ID:PacktPublishing,項目名稱:Hands-On-MQTT-Programming-with-Python,代碼行數:8,代碼來源:surfboard_sensors_emulator.py

示例10: on_connect_mosquitto

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import connack_string [as 別名]
def on_connect_mosquitto(client, userdata, flags, rc):
    print("Result from Mosquitto connect: {}".format(
        mqtt.connack_string(rc)))
    # Check whether the result form connect is the CONNACK_ACCEPTED connack code
    if rc == mqtt.CONNACK_ACCEPTED:
        # Subscribe to a topic filter that provides all the sensors
        sensors_topic_filter = topic_format.format(
            surfboard_name,
            "+")
        client.subscribe(sensors_topic_filter, qos=0) 
開發者ID:PacktPublishing,項目名稱:Hands-On-MQTT-Programming-with-Python,代碼行數:12,代碼來源:surfboard_monitor.py

示例11: on_connect_pubnub

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import connack_string [as 別名]
def on_connect_pubnub(client, userdata, flags, rc):
    print("Result from PubNub connect: {}".format(
        mqtt.connack_string(rc)))
    # Check whether the result form connect is the CONNACK_ACCEPTED connack code
    if rc == mqtt.CONNACK_ACCEPTED:
        Surfboard.active_instance.is_pubnub_connected = True 
開發者ID:PacktPublishing,項目名稱:Hands-On-MQTT-Programming-with-Python,代碼行數:8,代碼來源:surfboard_monitor.py

示例12: on_connect

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import connack_string [as 別名]
def on_connect(client, userdata, flags, rc):
    print("Result from connect: {}".format(
        mqtt.connack_string(rc)))
    # Subscribe to the vehicles/vehiclepi01/tests topic filter
    client.subscribe("vehicles/vehiclepi01/tests", qos=2) 
開發者ID:PacktPublishing,項目名稱:Hands-On-MQTT-Programming-with-Python,代碼行數:7,代碼來源:subscribe_with_paho.py

示例13: on_connect

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import connack_string [as 別名]
def on_connect(client, userdata, flags, rc):
        print("Result from connect: {}".format(
            mqtt.connack_string(rc)))
        # Check whether the result form connect is the CONNACK_ACCEPTED connack code
        if rc == mqtt.CONNACK_ACCEPTED:
            # Subscribe to the commands topic filter
            client.subscribe(
                VehicleCommandProcessor.commands_topic, 
                qos=2) 
開發者ID:PacktPublishing,項目名稱:Hands-On-MQTT-Programming-with-Python,代碼行數:11,代碼來源:vehicle_mqtt_client.py

示例14: on_connect

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import connack_string [as 別名]
def on_connect(client, userdata, flags, rc):
    print("Result from connect: {}".format(
        mqtt.connack_string(rc)))
    # Check whether the result form connect is the CONNACK_ACCEPTED connack code
    if rc == mqtt.CONNACK_ACCEPTED:
        # Subscribe to the commands topic filter
        client.subscribe(
            processed_commands_topic, 
            qos=2) 
開發者ID:PacktPublishing,項目名稱:Hands-On-MQTT-Programming-with-Python,代碼行數:11,代碼來源:vehicle_mqtt_remote_control.py

示例15: _on_connect

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import connack_string [as 別名]
def _on_connect(client, userdata, flags, rc):
    """Internal callback"""
    if rc != 0:
        raise mqtt.MQTTException(paho.connack_string(rc))

    if isinstance(userdata['topics'], list):
        for topic in userdata['topics']:
            client.subscribe(topic, userdata['qos'])
    else:
        client.subscribe(userdata['topics'], userdata['qos']) 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:12,代碼來源:subscribe.py


注:本文中的paho.mqtt.client.connack_string方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。