本文整理汇总了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)))
示例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)
示例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))
示例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
示例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)))
示例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)))
示例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))
示例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))
示例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))
示例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
示例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
示例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
示例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)