Python paho.mqtt.client.error_string() Examples
The following are 20
code examples of paho.mqtt.client.error_string().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
paho.mqtt.client
, or try the search function
.
Example #1
Source File: mqtt2sql.py From mqtt2sql with GNU General Public License v3.0 | 6 votes |
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)
Example #2
Source File: mqtt2sql.py From mqtt2sql with GNU General Public License v3.0 | 6 votes |
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)))
Example #3
Source File: client.py From tavern with MIT License | 6 votes |
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
Example #4
Source File: iot_mqtt_client.py From kim-voice-assistant with MIT License | 6 votes |
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))
Example #5
Source File: mqtt_squeeze.py From squeeze-alexa with GNU General Public License v3.0 | 5 votes |
def on_connect(client, data, flags, rc): logger.info("Connection status: %s", mqtt.error_string(rc)) client.subscribe(MQTT_SETTINGS.topic_req, qos=1)
Example #6
Source File: communicator.py From hapi with GNU General Public License v3.0 | 5 votes |
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
Example #7
Source File: test_pubsub.py From openag-device-software with GNU General Public License v3.0 | 5 votes |
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
Example #8
Source File: manager.py From openag-device-software with GNU General Public License v3.0 | 5 votes |
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
Example #9
Source File: pi_cpu_temp_mqtt.py From Cloud-IoT-Core-Kit-Examples with Apache License 2.0 | 5 votes |
def error_str(rc): """Convert a Paho error to a human readable string.""" return '{}: {}'.format(rc, mqtt.error_string(rc))
Example #10
Source File: pubsub_thermostat.py From Cloud-IoT-Core-Kit-Examples with Apache License 2.0 | 5 votes |
def error_str(rc): """Convert a Paho error to a human readable string.""" return '{}: {}'.format(rc, mqtt.error_string(rc))
Example #11
Source File: pubsub_servo.py From Cloud-IoT-Core-Kit-Examples with Apache License 2.0 | 5 votes |
def error_str(rc): """Convert a Paho error to a human readable string.""" return '{}: {}'.format(rc, mqtt.error_string(rc))
Example #12
Source File: pubsub_stick.py From Cloud-IoT-Core-Kit-Examples with Apache License 2.0 | 5 votes |
def error_str(rc): """Convert a Paho error to a human readable string.""" return '{}: {}'.format(rc, mqtt.error_string(rc))
Example #13
Source File: gateway.py From python-docs-samples with Apache License 2.0 | 5 votes |
def error_str(rc): """Convert a Paho error to a human readable string.""" return '{}: {}'.format(rc, mqtt.error_string(rc))
Example #14
Source File: gcs_example_mqtt_device.py From python-docs-samples with Apache License 2.0 | 5 votes |
def error_str(rc): """Convert a Paho error to a human readable string.""" return '{}: {}'.format(rc, mqtt.error_string(rc))
Example #15
Source File: cloudiot_mqtt_example.py From python-docs-samples with Apache License 2.0 | 5 votes |
def error_str(rc): """Convert a Paho error to a human readable string.""" return '{}: {}'.format(rc, mqtt.error_string(rc))
Example #16
Source File: cloudiot_pubsub_example_mqtt_device.py From python-docs-samples with Apache License 2.0 | 5 votes |
def error_str(rc): """Convert a Paho error to a human readable string.""" return '{}: {}'.format(rc, mqtt.error_string(rc))
Example #17
Source File: mqtt_transport.py From azure-iot-sdk-python-preview with MIT License | 5 votes |
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))
Example #18
Source File: mqtt_transport.py From azure-iot-sdk-python with MIT License | 5 votes |
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))
Example #19
Source File: mqtt.py From OpenMTC with Eclipse Public License 1.0 | 5 votes |
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)))
Example #20
Source File: mqtt2sql.py From mqtt2sql with GNU General Public License v3.0 | 5 votes |
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)))