本文整理匯總了Python中paho.mqtt.client.MQTT_ERR_NO_CONN屬性的典型用法代碼示例。如果您正苦於以下問題:Python client.MQTT_ERR_NO_CONN屬性的具體用法?Python client.MQTT_ERR_NO_CONN怎麽用?Python client.MQTT_ERR_NO_CONN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類paho.mqtt.client
的用法示例。
在下文中一共展示了client.MQTT_ERR_NO_CONN屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: loop_forever
# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import MQTT_ERR_NO_CONN [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)))
示例2: subscribe
# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import MQTT_ERR_NO_CONN [as 別名]
def subscribe(self, topic):
self.logger.debug("subscribing to topic %s" % topic)
result = self.mqtt.subscribe(topic)
if result[0] == MQTT_ERR_NO_CONN:
self.logger.warning("no connection while trying to subscribe to topic %s" % topic)
return False
return result[0] == MQTT_ERR_SUCCESS
示例3: unsubscribe
# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import MQTT_ERR_NO_CONN [as 別名]
def unsubscribe(self, topic):
self.logger.debug("unsubscribing from topic %s" % topic)
result = self.mqtt.unsubscribe(topic)
if result[0] == MQTT_ERR_NO_CONN:
self.logger.warning("no connection while trying to unsubscribe from topic %s" % topic)
return False
return result[0] == MQTT_ERR_SUCCESS
示例4: _internal_send_message
# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import MQTT_ERR_NO_CONN [as 別名]
def _internal_send_message(self, topic, payload, queue):
self.logger.debug("sending topic %s with value \"%s\"" % (topic, payload))
result = self.mqtt.publish(topic, payload, retain=True)
if result[0] == MQTT_ERR_NO_CONN and queue:
self.logger.debug("no connection, saving message with topic %s to queue" % topic)
self.queue.append([topic, payload])
elif result[0] != MQTT_ERR_SUCCESS:
self.logger.warning("failed sending message %s, mqtt error %s" % (topic, result))
return False
return True
示例5: publish
# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import MQTT_ERR_NO_CONN [as 別名]
def publish(self, message, pubTopic):
"""Called by others to publish a message to the publish topic"""
try:
rval = self.client.publish(pubTopic, message)
if rval[0] == mqtt.MQTT_ERR_NO_CONN:
self.logger.error("Error publishing update: " + message + " to " + pubTopic)
self.comms.reconnect() # try to reconnect again
else:
self.logger.info("Published message " + message + " to " + pubTopic)
except:
print "Unexpected error publishing message:", sys.exc_info()[0]
示例6: publish
# 需要導入模塊: from paho.mqtt import client [as 別名]
# 或者: from paho.mqtt.client import MQTT_ERR_NO_CONN [as 別名]
def publish(self, topic, state):
full_topic = self.config['topic'] + topic
try:
rc = self.mqttclient.publish(full_topic, state)
if rc[0] == mqtt.MQTT_ERR_NO_CONN:
logger.warn("Error during publish: MQTT_ERR_NO_CONN")
else:
logger.info("Sent " + state + " to " + full_topic)
except Exception as e:
logger.error('Unable to send', exc_info=True)