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


Python client.MQTT_ERR_SUCCESS属性代码示例

本文整理汇总了Python中paho.mqtt.client.MQTT_ERR_SUCCESS属性的典型用法代码示例。如果您正苦于以下问题:Python client.MQTT_ERR_SUCCESS属性的具体用法?Python client.MQTT_ERR_SUCCESS怎么用?Python client.MQTT_ERR_SUCCESS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在paho.mqtt.client的用法示例。


在下文中一共展示了client.MQTT_ERR_SUCCESS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _onDisconnect

# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import MQTT_ERR_SUCCESS [as 别名]
def _onDisconnect(self, mqttc, obj, rc):
        """
        Called when the client disconnects from IBM Watson IoT Platform.
        
        See [paho.mqtt.python#on_disconnect](https://github.com/eclipse/paho.mqtt.python#on_disconnect) for more information
        
        # Parameters
        mqttc (paho.mqtt.client.Client): The client instance for this callback
        obj (object): The private user data as set in Client() or user_data_set()
        rc (int): indicates the disconnection state.  If `MQTT_ERR_SUCCESS` (0), the callback was 
            called in response to a `disconnect()` call. If any other value the disconnection was 
            unexpected, such as might be caused by a network error.
        
        """
        # Clear the event to indicate we're no longer connected
        self.connectEvent.clear()

        if rc != 0:
            self.logger.error("Unexpected disconnect from IBM Watson IoT Platform: %d" % (rc))
        else:
            self.logger.info("Disconnected from the IBM Watson IoT Platform") 
开发者ID:ibm-watson-iot,项目名称:iot-python,代码行数:23,代码来源:client.py

示例2: loop_forever

# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import MQTT_ERR_SUCCESS [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

示例3: _publish_message

# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import MQTT_ERR_SUCCESS [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

示例4: subscribe_settopics

# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import MQTT_ERR_SUCCESS [as 别名]
def subscribe_settopics(self, subscribe_topic=""):
        """subscribes to the topic-parameter, default:'set/<topic_root_name>/#' is used."""
        if len(subscribe_topic) == 0:
            #subscribe to default topic: "set/<topic_root_name>/#"
            subscribe_topic = "set/" + str(self.cfg_topic_root_name()) + "/#"
        #subscribe that topic
        (result, mid) = self._client_handle().subscribe(subscribe_topic, qos=self.cfg_QoS())
        if result != paho.MQTT_ERR_SUCCESS:
            #error occured un subscribing, log it
            errorstr = """cmqtt_client.subscribe_settopics() subscrib-error:{0}""".format(result)
            self.cfg_logging().critical(errorstr) 
开发者ID:norberts1,项目名称:hometop_HT3,代码行数:13,代码来源:mqtt_client_if.py

示例5: mqtt_on_connect

# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import MQTT_ERR_SUCCESS [as 别名]
def mqtt_on_connect(self, mqtt_client, userdata, flags, result):
        """A callback function that is responsible to being triggered when a connection was established"""

        if result == mqtt.MQTT_ERR_SUCCESS:
            self.cli.update_prompt()
        else:
            self.handle_failed_connection() 
开发者ID:akamai-threat-research,项目名称:mqtt-pwn,代码行数:9,代码来源:mqtt_client.py

示例6: mqtt_on_connect

# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import MQTT_ERR_SUCCESS [as 别名]
def mqtt_on_connect(self, mqtt_client, obj, flags, rc):
        """Handles connection"""

        if rc == mqtt.MQTT_ERR_SUCCESS:
            print('Connection succeeded')
        else:
            print('Connection failed')
            self.handle_failed_connection() 
开发者ID:akamai-threat-research,项目名称:mqtt-pwn,代码行数:10,代码来源:victim.py

示例7: _on_connect_cb

# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import MQTT_ERR_SUCCESS [as 别名]
def _on_connect_cb(self, client, userdata, flags, result):
        if result == MQTT_ERR_SUCCESS:
            logger.info("MQTT Broker Connected")
            self.state = ConnectionState.CONNECTED
            self._report_run_state(self._last_run_state)
            self._call_registars("on_connect", client, userdata, flags, result)
        else:
            logger.error("Failed to connect to MQTT. Code: %d" % result) 
开发者ID:ParadoxAlarmInterface,项目名称:pai,代码行数:10,代码来源:core.py

示例8: _on_disconnect_cb

# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import MQTT_ERR_SUCCESS [as 别名]
def _on_disconnect_cb(self, client, userdata, rc):
        if rc == MQTT_ERR_SUCCESS:
            logger.info("MQTT Broker Disconnected")
        else:
            logger.error("MQTT Broker unexpectedly disconnected. Code: %d", rc)

        self.state = ConnectionState.NEW
        self._call_registars("on_disconnect", client, userdata, rc) 
开发者ID:ParadoxAlarmInterface,项目名称:pai,代码行数:10,代码来源:core.py

示例9: _internal_send_message

# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import MQTT_ERR_SUCCESS [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

示例10: run_misc_loop

# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import MQTT_ERR_SUCCESS [as 别名]
def run_misc_loop(self):
        """Provide loop for paho mqtt."""
        # pylint: disable=import-error, import-outside-toplevel
        import paho.mqtt.client as mqtt

        while self._client.loop_misc() == mqtt.MQTT_ERR_SUCCESS:
            try:
                await asyncio.sleep(1)
            except asyncio.CancelledError:
                break 
开发者ID:theolind,项目名称:pymysensors,代码行数:12,代码来源:gateway_mqtt.py

示例11: mqtt_on_connect

# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import MQTT_ERR_SUCCESS [as 别名]
def mqtt_on_connect(self, client, userdata, flags, rc):
        logger.info("Connected with result code %s" % rc)
        for sub in ["/play","/control","/volume","/info","/search"]:
            rc = self.mqttClient.subscribe(self.topic+sub)
            if rc[0] != mqtt.MQTT_ERR_SUCCESS:
                logger.warn("Error during subscribe: " + str(rc[0]))
            else:              
                logger.info("Subscribed to " + self.topic + sub) 
开发者ID:magcode,项目名称:mopidy-mqtt,代码行数:10,代码来源:frontend.py

示例12: _subscribe

# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import MQTT_ERR_SUCCESS [as 别名]
def _subscribe(self, topic, qos=1):
        if not self.connectEvent.wait(timeout=10):
            self.logger.warning("Unable to subscribe to %s because client is in disconnected state" % (topic))
            return 0
        else:
            (result, mid) = self.client.subscribe(topic, qos=qos)
            if result == paho.MQTT_ERR_SUCCESS:
                with self._subLock:
                    self._subscriptions[topic] = qos
                return mid
            else:
                return 0 
开发者ID:ibm-watson-iot,项目名称:iot-python,代码行数:14,代码来源:client.py

示例13: _publishEvent

# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import MQTT_ERR_SUCCESS [as 别名]
def _publishEvent(self, topic, event, msgFormat, data, qos=0, onPublish=None):
        if not self.connectEvent.wait(timeout=10):
            self.logger.warning("Unable to send event %s because client is is disconnected state", event)
            return False
        else:
            if self.logger.isEnabledFor(logging.DEBUG):
                # The data object may not be serializable, e.g. if using a custom binary format
                try:
                    dataString = json.dumps(data)
                except:
                    dataString = str(data)
                self.logger.debug("Sending event %s with data %s" % (event, dataString))

            # Raise an exception if there is no codec for this msgFormat
            if self.getMessageCodec(msgFormat) is None:
                raise MissingMessageEncoderException(msgFormat)

            payload = self.getMessageCodec(msgFormat).encode(data, datetime.now(pytz.timezone("UTC")))

            result = self.client.publish(topic, payload=payload, qos=qos, retain=False)
            if result[0] == paho.MQTT_ERR_SUCCESS:
                # Because we are dealing with aync pub/sub model and callbacks it is possible that
                # the _onPublish() callback for this mid is called before we obtain the lock to place
                # the mid into the _onPublishCallbacks list.
                #
                # _onPublish knows how to handle a scenario where the mid is not present (no nothing)
                # in this scenario we will need to invoke the callback directly here, because at the time
                # the callback was invoked the mid was not yet in the list.
                with self._messagesLock:
                    if result[1] in self._onPublishCallbacks:
                        # Paho callback beat this thread so call callback inline now
                        del self._onPublishCallbacks[result[1]]
                        if onPublish is not None:
                            onPublish()
                    else:
                        # This thread beat paho callback so set up for call later
                        self._onPublishCallbacks[result[1]] = onPublish
                return True
            else:
                return False 
开发者ID:ibm-watson-iot,项目名称:iot-python,代码行数:42,代码来源:client.py

示例14: connect

# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import MQTT_ERR_SUCCESS [as 别名]
def connect(self, host=None, port=None, keepalive=30, bind_address=""):
        if self.on_connect:
            self.on_connect(self, None, None, 1)
        return MQTT_ERR_SUCCESS, 1 
开发者ID:declension,项目名称:squeeze-alexa,代码行数:6,代码来源:test_mqtt.py

示例15: subscribe

# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import MQTT_ERR_SUCCESS [as 别名]
def subscribe(self, topic, qos=0):
        self.subscribed.append(topic)
        if self.on_subscribe:
            self.on_subscribe(self, None, 123, (qos,))
        return MQTT_ERR_SUCCESS, 2 
开发者ID:declension,项目名称:squeeze-alexa,代码行数:7,代码来源:test_mqtt.py


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