本文整理汇总了Python中paho.mqtt.client.error_string函数的典型用法代码示例。如果您正苦于以下问题:Python error_string函数的具体用法?Python error_string怎么用?Python error_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了error_string函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __reconnect
def __reconnect(self):
"""
Tries to connect to the MQTT server
"""
# Cancel the timer, if any
self.__stop_timer()
try:
# Try to reconnect the server
result_code = self.__mqtt.reconnect()
if result_code:
# Something wrong happened
message = "Error connecting the MQTT server: {0} ({1})" \
.format(result_code, paho.error_string(result_code))
_logger.error(message)
raise ValueError(message)
except Exception as ex:
# Something went wrong: log it
_logger.error("Exception connecting server: %s", ex)
finally:
# Prepare a reconnection timer. It will be cancelled by the
# on_connect callback
self.__start_timer(10)
开发者ID:isandlaTech,项目名称:cohorte-3rdparty,代码行数:25,代码来源:mqtt_client.py
示例2: send
def send(self, val):
ts = val['ts'];
comp = val['name'];
data = str(val['val']);
topic = "server/metric/%s/%s" % (self._accountID, self._deviceID);
packet = {
'accountId': self._accountID,
'did': self._deviceID,
'on': ts,
'count': 1,
'data': [{'on': ts, 'value': data, 'cid': comp}]
};
pr.Dbg("EnableIoT - MQTT: Sending packet to topic '%s': %s" % (str(topic), json.dumps(packet)));
(succ, mid) = self._mqtt.publish(topic, json.dumps(packet), qos=self._qos);
pr.Dbg("EnableIoT - MQTT: Published Message %d (Err: '%s')" % (mid, mqtt.error_string(succ)));
start = time.time();
while (time.time() < (start + self._messageTimeout)):
self._gotMessagesLock.acquire();
if (mid in self._gotMessages):
self._gotMessages.remove(mid);
self._gotMessagesLock.release();
pr.Dbg("EnableIoT - MQTT: Success!");
return True;
self._gotMessagesLock.release();
time.sleep(0.5);
pr.Dbg("EnableIoT - MQTT: Fail....");
return False;
开发者ID:djdunc,项目名称:pyot,代码行数:31,代码来源:IntelIoTAnalytics.py
示例3: _raise_on_error
def _raise_on_error(result_code: int) -> None:
"""Raise error if error result."""
if result_code != 0:
import paho.mqtt.client as mqtt
raise HomeAssistantError(
'Error talking to MQTT: {}'.format(mqtt.error_string(result_code)))
开发者ID:simpss,项目名称:home-assistant,代码行数:7,代码来源:__init__.py
示例4: run
def run(self):
self.client = mqtt.Client()
self.client.on_connect = self.on_connect
self.client.on_disconnect = self.on_disconnect
self.client.on_subscribe = self.on_subscribe
self.client.on_message = self.on_message
self.client.on_log = self.on_log
while not self.app.is_exit_signaled():
while not self.connected:
try:
self.client.connect(self.app.mqtt_broker, self.app.mqtt_port, 60)
self.connected = True
except:
self.app.log.error("Failed to connect to MQTT broker: %s:%s (rc=%d, %s)", self.app.mqtt_broker, self.app.mqtt_port, rc, mqtt.error_string(rc))
time.sleep(3)
rc = self.client.loop()
if rc != mqtt.MQTT_ERR_SUCCESS:
self.app.log.warning("MQTT loop returned code %d (%s)", rc, mqtt.error_string(rc))
if self.connected:
self.client.disconnect()
self.app.log.debug("MQTT thread stopped")
开发者ID:mce35,项目名称:agocontrol,代码行数:26,代码来源:agomqtt.py
示例5: loop
def loop(self):
"""Run network activities.
This function needs to be called frequently to keep the network
traffic alive, if not using threaded networking.
It will block until a message is received, or until
the self.timeout value.
If not connected to the broker, it will try to connect once.
Do not use this function when running threaded networking.
"""
if self._use_threaded_networking:
self.logger.warning("You must should not use the loop() method when running a threaded networking interface.")
return
try:
errorcode = self.mqttclient.loop(self.timeout)
except AttributeError:
raise ValueError("You must call start() before loop().")
if not errorcode:
return
if errorcode == mqtt.MQTT_ERR_UNKNOWN:
self.logger.warning("Probably keyboard interrupt, quitting (MQTT error message: '{}')".format(
mqtt.error_string(errorcode)))
self.stop()
sys.exit()
if errorcode == mqtt.MQTT_ERR_CONN_LOST:
self.logger.info("MQTT connection error, trying to reconnect. Error message: '{}'".format(
mqtt.error_string(errorcode)))
elif errorcode in [mqtt.MQTT_ERR_NO_CONN, mqtt.MQTT_ERR_CONN_REFUSED]:
self.logger.warning("MQTT connection error, trying to reconnect. Error message: '{}'".format(
mqtt.error_string(errorcode)))
else:
self.logger.warning("MQTT error. Error message: '{}'".format(mqtt.error_string(errorcode)))
return
try:
self.mqttclient.reconnect()
except Exception:
self.logger.warning("Failed to connect to the MQTT broker. Host: {}, Port: {}".format(self.host, self.port))
self._set_broker_connectionstatus(False)
time.sleep(1)
开发者ID:caran,项目名称:SecureGateway,代码行数:46,代码来源:framework.py
示例6: store_raw
def store_raw(self, message):
# TODO: Wrap in JSON packet
# Publish with QoS=2
# http://www.hivemq.com/blog/mqtt-essentials-part-6-mqtt-quality-of-service-levels
(result, mid) = self.mqtt_client.publish(topic=self.PUBLISH_TOPIC, payload=message, qos=self.QOS_LEVEL)
print "store(): %s" % error_string(result)
开发者ID:gebart,项目名称:byteport-api,代码行数:8,代码来源:mqtt_client.py
示例7: publish
def publish(self, topic, payload, qos, retain):
try:
(rc, mid) = self._iot_mqtt_client_handler.publish(topic, payload, qos, retain)
except BaseException as e:
send_output(self.wrapper_debug, self.wrapper_Tx, "P F " + e.message)
return
send_output(self.wrapper_debug, self.wrapper_Tx, "P " + str(rc) + " " + mqtt.error_string(rc))
return rc
开发者ID:Novice1,项目名称:aws-iot-device-sdk-arduino-yun,代码行数:8,代码来源:aws_iot_mqtt_client.py
示例8: on_connect
def on_connect(self, client, userdata, flags, rc):
print('on_connect: %s' % error_string(rc))
if rc != 0:
raise ByteportConnectException("Error while connecting to MQTT Broker: " + error_string(rc))
# Subscribing in on_connect() means that if we lose the connection and
# reconnect then subscriptions will be renewed.
self.mqtt_client.subscribe(self.self_topic_name, qos=self.QOS_LEVEL)
# For testing pub/subscribe via. RabbitMQ -> Exchange -> Queue
self.mqtt_client.subscribe(self.PUBLISH_TOPIC, qos=self.QOS_LEVEL)
开发者ID:iGW,项目名称:byteport-api,代码行数:12,代码来源:mqtt_client.py
示例9: __on_connect
def __on_connect(self, client, userdata, flags, rc):
if rc == mqtt.CONNACK_ACCEPTED:
# connection successful
self.connected = True
for topic in self.subscriptions.keys():
(res, mid) = self.client.subscribe(topic)
self.log.debug("subscribing to '%s' => mid: '%s' == '%s'" % (topic, mid, res))
self.subscriptions[topic]['mid'] = mid
self.subscriptions[topic]['subscription_result'] = res
else:
msg = mqtt.error_string(rc)
self.log.error("MQTT connection error: %s" % msg)
self.__sender_id = None
开发者ID:peuter,项目名称:gosa,代码行数:13,代码来源:mqtt_client.py
示例10: subscribe
def subscribe(self, topic, qos, ino_id):
try:
(rc, mid) = self._iot_mqtt_client_handler.subscribe(topic, qos)
if ino_id == None:
raise ValueError("None ino_id")
self.idMap_lock.acquire()
self.idMap.setdefault(topic, ino_id)
self.idMap_lock.release()
except BaseException as e:
send_output(self.wrapper_debug, self.wrapper_Tx, "S F " + e.message)
return
send_output(self.wrapper_debug, self.wrapper_Tx, "S " + str(rc) + " " + mqtt.error_string(rc))
return rc
开发者ID:Pillar1989,项目名称:AWS_Arduino_SDK,代码行数:13,代码来源:aws_iot_mqtt_client.py
示例11: async_connect
def async_connect(self):
"""Connect to the host. Does not process messages yet.
This method must be run in the event loop and returns a coroutine.
"""
result = yield from self.hass.loop.run_in_executor(
None, self._mqttc.connect, self.broker, self.port, self.keepalive)
if result != 0:
import paho.mqtt.client as mqtt
_LOGGER.error('Failed to connect: %s', mqtt.error_string(result))
return not result
开发者ID:danieljkemp,项目名称:home-assistant,代码行数:13,代码来源:__init__.py
示例12: emit_record
def emit_record(topic, rec):
global client
if client== None:
client = get_connected_client()
p = 11
tries = 0
while p > 10:
p = 0
plock.acquire()
p = len(pending)
plock.release()
if p > 10:
tries += 1
if tries > 10:
LOG.info("restarting mqtt connection")
try:
if (client.connect(MQHOST, MQPORT, 60) != mqtt.MQTT_ERR_SUCCESS):
LOG.error("Failed to connect to MQTT server.")
return None
except ConnectionRefusedError:
LOG.error("MQTT server connection refused at {}:{} check the server.".format(MQHOST, MQPORT))
tries = 0
else:
LOG.info("wait for pending messages before queuing more [{}]".format(p))
time.sleep(1)
# make it serializable
d = rec['Datetime']
rec['Datetime'] = rec['Datetime'].isoformat()
result, mid = client.publish(topic,json.dumps(rec), qos=2)
if result != mqtt.MQTT_ERR_SUCCESS:
LOG.warn("MQTT publish failed with {}, restarting connection.".format(mqtt.error_string(result)))
try:
shutdown_client()
except:
pass
else:
LOG.info("emit [{}] to {}: {}".format(mid, topic, rec))
plock.acquire()
pending[mid] = datetime.datetime.now()
plock.release()
rec['Datetime'] = d
开发者ID:amm042,项目名称:cr_logger,代码行数:49,代码来源:cr_to_mqtt.py
示例13: async_connect
def async_connect(self):
"""Connect to the host. Does process messages yet.
This method is a coroutine.
"""
result = yield from self.hass.async_add_job(
self._mqttc.connect, self.broker, self.port, self.keepalive)
if result != 0:
import paho.mqtt.client as mqtt
_LOGGER.error('Failed to connect: %s', mqtt.error_string(result))
else:
self._mqttc.loop_start()
return not result
开发者ID:ozzpy,项目名称:home-assistant,代码行数:15,代码来源:__init__.py
示例14: subscribe
def subscribe(self, topic, qos, ino_id, is_delta):
try:
(rc, mid) = self._iot_mqtt_client_handler.subscribe(topic, qos)
if ino_id == None:
raise ValueError("None ino_id")
self.idMap_lock.acquire()
new_key = idMap_key(topic, None) # no clientToken since it is a normal sub
new_entry = idMap_info(ino_id, False, is_delta!=0) # This is not a ThingShadow-related topic
self.idMap[new_key] = new_entry
self.idMap_lock.release()
except BaseException as e:
send_output(self.wrapper_debug, self.wrapper_Tx, "S F " + e.message)
return
send_output(self.wrapper_debug, self.wrapper_Tx, "S " + str(rc) + " " + mqtt.error_string(rc))
return rc
开发者ID:koltegirish,项目名称:aws-iot-device-sdk-arduino-yun,代码行数:15,代码来源:aws_iot_mqtt_client.py
示例15: publish_file
def publish_file(file_name, file_path):
global mqtt_client
log.debug('publish_file({})'.format(file_path))
try:
with open(file_path) as fh:
file_contents = fh.read()
ret_obj = mqtt_client.publish(topic=file_name, payload=file_contents, qos=0)
if ret_obj.rc == mqtt.MQTT_ERR_SUCCESS:
log.debug('MQTT published file: {}'.format(file_path))
else:
log.warning('MQTT failed to publish file: {}'.format(file_path))
log.warning('MQTT failed to publish file. error: {}'.format(mqtt.error_string(ret_obj.rc)))
except Exception as ex:
log.error('Exception in publish_file(). ex: {}'.format(ex))
开发者ID:cradlepoint,项目名称:sdk-samples,代码行数:16,代码来源:mqtt_app.py
示例16: async_connect
async def async_connect(self) -> bool:
"""Connect to the host. Does process messages yet.
This method is a coroutine.
"""
result = None # type: int
try:
result = await self.hass.async_add_job(
self._mqttc.connect, self.broker, self.port, self.keepalive)
except OSError as err:
_LOGGER.error("Failed to connect due to exception: %s", err)
return False
if result != 0:
import paho.mqtt.client as mqtt
_LOGGER.error("Failed to connect: %s", mqtt.error_string(result))
return False
self._mqttc.loop_start()
return True
开发者ID:boced66,项目名称:home-assistant,代码行数:20,代码来源:__init__.py
示例17: __on_connect
def __on_connect(self, client, userdata, flags, rc):
if rc == mqtt.CONNACK_ACCEPTED:
# connection successful
self.log.info("%s: MQTT successfully connected" % self.get_identifier())
self._set_connected(True)
self.__retried = 0
for topic in self.subscriptions.keys():
(res, mid) = self.client.subscribe(topic)
self.log.debug("%s: subscribing to '%s' => mid: '%s' == '%s'" % (self.get_identifier(), topic, mid, res))
self.subscriptions[topic]['mid'] = mid
self.subscriptions[topic]['subscription_result'] = res
else:
self._set_connected(False)
self.__connection_error_counter += 1
if self.__connection_error_counter >= self.__switch_threshold:
self.switch_to_host(blacklist_current=True)
return
msg = mqtt.error_string(rc)
self.log.error("%s: MQTT connection error: %s" % (self.get_identifier(), msg))
self.__reconnect()
开发者ID:gonicus,项目名称:gosa,代码行数:21,代码来源:mqtt_client.py
示例18: __init__
def __init__(self, namespace, device_uid, username, password,
broker_host=DEFAULT_BROKER_HOST, loop_forever=False, explicit_vhost=None):
self.namespace = str(namespace)
self.device_uid = device_uid
self.guid = '%s.%s' % (namespace, device_uid)
self.self_topic_name = self.guid
if explicit_vhost:
vhost = explicit_vhost
else:
vhost = namespace
if vhost:
username = '%s:%s' % (vhost, username)
self.mqtt_client = mqtt.Client(client_id=self.guid, clean_session=False, protocol=MQTTv311)
self.mqtt_client.username_pw_set(username, password)
self.mqtt_client.on_connect = self.on_connect
self.mqtt_client.on_message = self.on_message
print "Connecting to %s" % broker_host
rc = self.mqtt_client.connect(broker_host, 1883, 60)
print('connect(): %s' % error_string(rc))
# Blocking call that processes network traffic, dispatches callbacks and
# handles reconnecting.
# Other loop*() functions are available that give a threaded interface and a
# manual interface.
if loop_forever:
self.mqtt_client.loop_forever()
开发者ID:gebart,项目名称:byteport-api,代码行数:36,代码来源:mqtt_client.py
示例19: on_disconnect
def on_disconnect(self, client, obj, rc):
self.app.log.info("Disconnected from MQTT broker (rc=%d, %s)", rc, mqtt.error_string(rc))
self.connected = False
开发者ID:mce35,项目名称:agocontrol,代码行数:3,代码来源:agomqtt.py
示例20: unsubscribe
def unsubscribe(self, topic):
self.idMap_lock.acquire()
try:
(rc, mid) = self._iot_mqtt_client_handler.unsubscribe(topic)
new_key = idMap_key(topic, None)
ino_id = self.idMap[new_key].get_ino_id()
del self.idMap[new_key]
except BaseException as e:
send_output(self.wrapper_debug, self.wrapper_Tx, "U F " + str(e.message))
return
finally:
self.idMap_lock.release()
send_output(self.wrapper_debug, self.wrapper_Tx, "U " + str(rc) + " " + str(ino_id) + " " + mqtt.error_string(rc))
# send back the return value along with the ino_id for C side reference to free the subgroup slot (important)
return rc
开发者ID:Novice1,项目名称:aws-iot-device-sdk-arduino-yun,代码行数:15,代码来源:aws_iot_mqtt_client.py
注:本文中的paho.mqtt.client.error_string函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论