当前位置: 首页>>代码示例>>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;未经允许,请勿转载。