当前位置: 首页>>代码示例>>Python>>正文


Python client.MQTT_ERR_NO_CONN属性代码示例

本文整理汇总了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))) 
开发者ID:curzon01,项目名称:mqtt2sql,代码行数:41,代码来源:mqtt2sql.py

示例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 
开发者ID:nohum,项目名称:chromecast-mqtt-connector,代码行数:11,代码来源:mqtt.py

示例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 
开发者ID:nohum,项目名称:chromecast-mqtt-connector,代码行数:11,代码来源:mqtt.py

示例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 
开发者ID:nohum,项目名称:chromecast-mqtt-connector,代码行数:14,代码来源:mqtt.py

示例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] 
开发者ID:rkoshak,项目名称:sensorReporter,代码行数:14,代码来源:mqttConn.py

示例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) 
开发者ID:magcode,项目名称:mopidy-mqtt,代码行数:12,代码来源:frontend.py


注:本文中的paho.mqtt.client.MQTT_ERR_NO_CONN属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。