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


Python client.error_string方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import error_string [as 別名]
def __init__(self, args_):
        self._args = args_
        self.write2sql_thread = None
        self.pool_sqlconnections = BoundedSemaphore(value=self._args.sql_max_connection)
        self.userdata = {
            'haveresponse' : False,
            'starttime'    : time.time()
        }
        self.mqttc, ret = self.mqtt_connect(
            host=self._args.mqtt_host,
            port=self._args.mqtt_port,
            username=self._args.mqtt_username,
            password=self._args.mqtt_password,
            keepalive=self._args.mqtt_keepalive,
            cafile=self._args.mqtt_cafile,
            certfile=self._args.mqtt_certfile,
            keyfile=self._args.mqtt_keyfile,
            insecure=self._args.mqtt_insecure,
            userdata=self.userdata
            )
        if ret != ExitCode.OK:
            SignalHandler.exitus(ret, '{}:{} failed - [{}] {}'.format(self._args.mqtt_host, self._args.mqtt_port, ret, mqtt.error_string(ret))) 
開發者ID:curzon01,項目名稱:mqtt2sql,代碼行數:24,代碼來源:mqtt2sql.py

示例2: on_connect

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import error_string [as 別名]
def on_connect(self, client, userdata, message, return_code):
        """
        Called when the broker responds to our connection request.

        @param client:
            the client instance for this callback
        @param userdata:
            the private user data as set in Client() or userdata_set()
        @param message:
            response message sent by the broker
        @param return_code:
            the connection result
        """
        debuglog(1, "MQTT on_connect({},{},{},{}): {}".format(client, userdata, message, return_code, mqtt.error_string(return_code)))
        for topic in self._args.mqtt_topic:
            debuglog(1, "subscribe to topic {}".format(topic))
            client.subscribe(topic, 0) 
開發者ID:curzon01,項目名稱:mqtt2sql,代碼行數:19,代碼來源:mqtt2sql.py

示例3: do_publish

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import error_string [as 別名]
def do_publish(self, topic_name='', payload='', qos=1, retain=False, is_shadow=False):
        """
        向服務器發送消息
        :param topic_name: Topic名稱
        :param payload:
        :param qos:f
        :param retain:
        :param is_shadow  是否是影子設備
        :return:
        """
        self._logger.info('發布MQTT消息:'+payload)
        topic = self._topic.get_topic_name(topic_name, type='publish', is_shadow=is_shadow)

        result = self.mqttc.publish(topic=topic, payload=payload, qos=qos, retain=retain)
        if result.is_published() is not True:
            self._logger.error('Content %s send to topic "%s" publish failed.', payload, topic)
            self._logger.info('Error string:%s', error_string(result.rc)) 
開發者ID:tenstone,項目名稱:kim-voice-assistant,代碼行數:19,代碼來源:iot_mqtt_client.py

示例4: publish

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import error_string [as 別名]
def publish(self, topic, payload=None, qos=None, retain=None):
        """publish message using paho library
        """
        self._wait_for_subscriptions()

        logger.debug("Publishing on '%s'", topic)

        kwargs = {}
        if qos is not None:
            kwargs["qos"] = qos
        if retain is not None:
            kwargs["retain"] = retain
        msg = self._client.publish(topic, payload, **kwargs)

        if not msg.is_published:
            raise exceptions.MQTTError(
                "err {:s}: {:s}".format(
                    _err_vals.get(msg.rc, "unknown"), paho.error_string(msg.rc)
                )
            )

        return msg 
開發者ID:taverntesting,項目名稱:tavern,代碼行數:24,代碼來源:client.py

示例5: loop_forever

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import error_string [as 別名]
def loop_forever(self):
        """
        Main MQTT to SQL loop
        does not return until an error occurs
        """
        global EXIT_CODE    # pylint: disable=global-statement

        while True:
            # Main loop as long as no error occurs
            ret = mqtt.MQTT_ERR_SUCCESS
            while not self.userdata['haveresponse'] and ret == mqtt.MQTT_ERR_SUCCESS:
                try:
                    ret = self.mqttc.loop()
                except Exception as err:    # pylint: disable=broad-except
                    log(0, 'ERROR: loop() - {}'.format(err))
                    time.sleep(0.1)
                if EXIT_CODE != ExitCode.OK:
                    sys.exit(EXIT_CODE)
            if ret not in (
                    mqtt.MQTT_ERR_AGAIN,
                    mqtt.MQTT_ERR_PROTOCOL,
                    mqtt.MQTT_ERR_INVAL,
                    mqtt.MQTT_ERR_NO_CONN,
                    mqtt.MQTT_ERR_CONN_REFUSED,
                    mqtt.MQTT_ERR_NOT_FOUND,
                    mqtt.MQTT_ERR_TLS,
                    mqtt.MQTT_ERR_PAYLOAD_SIZE,
                    mqtt.MQTT_ERR_NOT_SUPPORTED,
                    mqtt.MQTT_ERR_AUTH,
                    mqtt.MQTT_ERR_ERRNO):
                # disconnect from server
                log(0, 'Remote disconnected from MQTT - [{}] {})'.format(ret, mqtt.error_string(ret)))
                try:
                    ret = self.mqttc.reconnect()
                    log(0, 'MQTT reconnected - [{}] {})'.format(ret, mqtt.error_string(ret)))
                except Exception as err:    # pylint: disable=broad-except
                    SignalHandler.exitus(ExitCode.MQTT_CONNECTION_ERROR, '{}:{} failed - [{}] {}'.format(self._args.mqtt_host, self._args.mqtt_port, ret, mqtt.error_string(err)))
            else:
                SignalHandler.exitus(ExitCode.MQTT_CONNECTION_ERROR, '{}:{} failed: - [{}] {}'.format(self._args.mqtt_host, self._args.mqtt_port, ret, mqtt.error_string(ret))) 
開發者ID:curzon01,項目名稱:mqtt2sql,代碼行數:41,代碼來源:mqtt2sql.py

示例6: _publish_message

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import error_string [as 別名]
def _publish_message(self, payload, topic):
        (rc, mid) = self._client.publish(topic, payload, MQTT_QOS_LEVEL)
        if not rc == mqtt.MQTT_ERR_SUCCESS:
            self.logger.info('Code %d while sending message %d: %s' %
                             (rc, mid, mqtt.error_string(rc))) 
開發者ID:OpenMTC,項目名稱:OpenMTC,代碼行數:7,代碼來源:mqtt.py

示例7: _create_error_from_rc_code

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import error_string [as 別名]
def _create_error_from_rc_code(rc):
    """
    Given a paho rc code, return an Exception that can be raised
    """
    if rc == 1:
        # Paho returns rc=1 to mean "something went wrong.  stop".  We manually translate this to a ConnectionDroppedError.
        return exceptions.ConnectionDroppedError("Paho returned rc==1")
    elif rc in paho_rc_to_error:
        message = mqtt.error_string(rc)
        return paho_rc_to_error[rc](message)
    else:
        return exceptions.ProtocolClientError("Unknown CONNACK rc=={}".format(rc)) 
開發者ID:Azure,項目名稱:azure-iot-sdk-python,代碼行數:14,代碼來源:mqtt_transport.py

示例8: _create_error_from_rc_code

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import error_string [as 別名]
def _create_error_from_rc_code(rc):
    """
    Given a paho rc code, return an Exception that can be raised
    """
    message = mqtt.error_string(rc)
    if rc in paho_rc_to_error:
        return paho_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

示例9: error_str

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import error_string [as 別名]
def error_str(rc):
    """Convert a Paho error to a human readable string."""
    return '{}: {}'.format(rc, mqtt.error_string(rc)) 
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:5,代碼來源:cloudiot_pubsub_example_mqtt_device.py

示例10: error_str

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import error_string [as 別名]
def error_str(rc):
  """Convert a Paho error to a human readable string."""
  return '{}: {}'.format(rc, mqtt.error_string(rc)) 
開發者ID:ARM-software,項目名稱:Cloud-IoT-Core-Kit-Examples,代碼行數:5,代碼來源:pubsub_stick.py

示例11: on_disconnect

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import error_string [as 別名]
def on_disconnect(client: mqtt.Client, ref_self: IotManager, return_code: int) -> None:
    """Callback for when a device disconnects from mqtt broker."""
    error = "{}: {}".format(return_code, mqtt.error_string(return_code))
    ref_self.logger.error(error)
    ref_self.logger.debug(
        "Trying mqtt port: {}".format(str(ref_self.pubsub.next_port()))
    )
    ref_self.is_connected = False
    ref_self.mode = modes.DISCONNECTED 
開發者ID:OpenAgricultureFoundation,項目名稱:openag-device-software,代碼行數:11,代碼來源:manager.py

示例12: on_disconnect

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import error_string [as 別名]
def on_disconnect(client: mqtt.Client, ref_self: IotManager, return_code: int) -> None:
    """Callback for when a device disconnects from mqtt broker."""
    error = "{}: {}".format(return_code, mqtt.error_string(return_code))
    ref_self.is_connected = False 
開發者ID:OpenAgricultureFoundation,項目名稱:openag-device-software,代碼行數:6,代碼來源:test_pubsub.py

示例13: on_disconnect

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import error_string [as 別名]
def on_disconnect(self, client, userdata, rc):
        self.is_connected = False
        Log.info("[Exiting] Disconnected: %s", mqtt.error_string(rc))
        self.client.loop_stop()
        sys.exit(-1)

    # The callback for when the client receives a CONNACK response from the server.
    #@staticmethod 
開發者ID:mayaculpa,項目名稱:hapi,代碼行數:10,代碼來源:communicator.py

示例14: on_connect

# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import error_string [as 別名]
def on_connect(client, data, flags, rc):
    logger.info("Connection status: %s", mqtt.error_string(rc))
    client.subscribe(MQTT_SETTINGS.topic_req, qos=1) 
開發者ID:declension,項目名稱:squeeze-alexa,代碼行數:5,代碼來源:mqtt_squeeze.py


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