Python paho.mqtt.client.MQTT_ERR_NO_CONN Examples
The following are 6
code examples of paho.mqtt.client.MQTT_ERR_NO_CONN().
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 | 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)))
Example #2
Source File: mqtt.py From chromecast-mqtt-connector with Mozilla Public License 2.0 | 5 votes |
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
Example #3
Source File: mqtt.py From chromecast-mqtt-connector with Mozilla Public License 2.0 | 5 votes |
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
Example #4
Source File: mqtt.py From chromecast-mqtt-connector with Mozilla Public License 2.0 | 5 votes |
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
Example #5
Source File: mqttConn.py From sensorReporter with Apache License 2.0 | 5 votes |
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]
Example #6
Source File: frontend.py From mopidy-mqtt with Apache License 2.0 | 5 votes |
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)