Python paho.mqtt.client.connack_string() Examples

The following are 26 code examples of paho.mqtt.client.connack_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: __init__.py    From smarthome with GNU General Public License v3.0 6 votes vote down vote up
def _on_connect(self, client, userdata, flags, rc):
        """
        Callback function called on connect
        """
        self._connect_result = mqtt.connack_string(rc)

        if rc == 0:
            self.logger.info("Connection returned result '{}' (userdata={}) ".format(mqtt.connack_string(rc), userdata))
            self._connected = True

            self._subscribe_broker_infos()

            # subscribe to topics to listen for items
            for topic in self._subscribed_topics:
                item = self._subscribed_topics[topic]
                self._client.subscribe(topic, qos=self._get_qos_forTopic(item) )
                self.logger.info("Listening on topic '{}' for item '{}'".format( topic, item.id() ))

            self.logger.info("self._subscribed_topics = {}".format(self._subscribed_topics))

            return

        msg = "Connection returned result '{}': {} (client={}, userdata={}, self._client={})".format( str(rc), mqtt.connack_string(rc), client, userdata, self._client )
        if rc == 5:
            self.logger.error(msg)
            self._disconnect_from_broker()
        else:
            self.logger.warning(msg) 
Example #2
Source File: mqtt_wrapper.py    From gateway with Apache License 2.0 5 votes vote down vote up
def _on_connect(self, client, userdata, flags, rc):
        # pylint: disable=unused-argument
        if rc != 0:
            self.logger.error("MQTT cannot connect: %s (%s)", connack_string(rc), rc)
            self.running = False
            return

        self.connected = True
        if self.on_connect_cb is not None:
            self.on_connect_cb() 
Example #3
Source File: plantgw.py    From plantgateway with Apache License 2.0 5 votes vote down vote up
def _start_client(self):
        self.mqtt_client = mqtt.Client(self.config.mqtt_client_id)
        if self.config.mqtt_user is not None:
            self.mqtt_client.username_pw_set(self.config.mqtt_user, self.config.mqtt_password)
        if self.config.mqtt_ca_cert is not None:
            self.mqtt_client.tls_set(self.config.mqtt_ca_cert, cert_reqs=mqtt.ssl.CERT_REQUIRED)

        def _on_connect(client, _, flags, return_code):
            self.connected = True
            logging.info("MQTT connection returned result: %s", mqtt.connack_string(return_code))
        self.mqtt_client.on_connect = _on_connect

        self.mqtt_client.connect(self.config.mqtt_server, self.config.mqtt_port, 60)
        self.mqtt_client.loop_start() 
Example #4
Source File: publish.py    From jarvis with GNU General Public License v2.0 5 votes vote down vote up
def _on_connect(client, userdata, flags, rc):
    """Internal callback"""
    #pylint: disable=invalid-name, unused-argument

    if rc == 0:
        if len(userdata) > 0:
            _do_publish(client)
    else:
        raise mqtt.MQTTException(paho.connack_string(rc)) 
Example #5
Source File: subscribe.py    From jarvis with GNU General Public License v2.0 5 votes vote down vote up
def _on_connect(client, userdata, flags, rc):
    """Internal callback"""
    if rc != 0:
        raise mqtt.MQTTException(paho.connack_string(rc))

    if isinstance(userdata['topics'], list):
        for topic in userdata['topics']:
            client.subscribe(topic, userdata['qos'])
    else:
        client.subscribe(userdata['topics'], userdata['qos']) 
Example #6
Source File: vehicle_mqtt_client.py    From Hands-On-MQTT-Programming-with-Python with MIT License 5 votes vote down vote up
def on_connect(client, userdata, flags, rc):
        print("Result from connect: {}".format(
            mqtt.connack_string(rc)))
        # Check whether the result form connect is the CONNACK_ACCEPTED connack code
        if rc == mqtt.CONNACK_ACCEPTED:
            # Subscribe to the commands topic filter
            client.subscribe(
                VehicleCommandProcessor.commands_topic, 
                qos=2) 
Example #7
Source File: vehicle_mqtt_remote_control.py    From Hands-On-MQTT-Programming-with-Python with MIT License 5 votes vote down vote up
def on_connect(client, userdata, flags, rc):
    print("Result from connect: {}".format(
        mqtt.connack_string(rc)))
    # Check whether the result form connect is the CONNACK_ACCEPTED connack code
    if rc == mqtt.CONNACK_ACCEPTED:
        # Subscribe to the commands topic filter
        client.subscribe(
            processed_commands_topic, 
            qos=2) 
Example #8
Source File: subscribe_with_paho.py    From Hands-On-MQTT-Programming-with-Python with MIT License 5 votes vote down vote up
def on_connect(client, userdata, flags, rc):
    print("Result from connect: {}".format(
        mqtt.connack_string(rc)))
    # Subscribe to the vehicles/vehiclepi01/tests topic filter
    client.subscribe("vehicles/vehiclepi01/tests", qos=2) 
Example #9
Source File: vehicle_mqtt_client.py    From Hands-On-MQTT-Programming-with-Python with MIT License 5 votes vote down vote up
def on_connect(client, userdata, flags, rc):
        print("Result from connect: {}".format(
            mqtt.connack_string(rc)))
        # Check whether the result form connect is the CONNACK_ACCEPTED connack code
        if rc == mqtt.CONNACK_ACCEPTED:
            # Subscribe to the commands topic filter
            client.subscribe(
                VehicleCommandProcessor.commands_topic, 
                qos=2) 
Example #10
Source File: vehicle_mqtt_remote_control.py    From Hands-On-MQTT-Programming-with-Python with MIT License 5 votes vote down vote up
def on_connect(client, userdata, flags, rc):
    print("Result from connect: {}".format(
        mqtt.connack_string(rc)))
    # Check whether the result form connect is the CONNACK_ACCEPTED connack code
    if rc == mqtt.CONNACK_ACCEPTED:
        # Subscribe to the commands topic filter
        client.subscribe(
            processed_commands_topic, 
            qos=2) 
Example #11
Source File: vehicle_mqtt_client.py    From Hands-On-MQTT-Programming-with-Python with MIT License 5 votes vote down vote up
def on_connect(client, userdata, flags, rc):
        print("Result from connect: {}".format(
            mqtt.connack_string(rc)))
        # Check whether the result form connect is the CONNACK_ACCEPTED connack code
        if rc == mqtt.CONNACK_ACCEPTED:
            # Subscribe to the commands topic filter
            client.subscribe(
                VehicleCommandProcessor.commands_topic, 
                qos=2) 
Example #12
Source File: vehicle_mqtt_remote_control.py    From Hands-On-MQTT-Programming-with-Python with MIT License 5 votes vote down vote up
def on_connect(client, userdata, flags, rc):
    print("Result from connect: {}".format(
        mqtt.connack_string(rc)))
    # Check whether the result form connect is the CONNACK_ACCEPTED connack code
    if rc == mqtt.CONNACK_ACCEPTED:
        # Subscribe to the commands topic filter
        client.subscribe(
            processed_commands_topic, 
            qos=2) 
Example #13
Source File: subscribe_with_paho.py    From Hands-On-MQTT-Programming-with-Python with MIT License 5 votes vote down vote up
def on_connect(client, userdata, flags, rc):
    print("Result from connect: {}".format(
        mqtt.connack_string(rc)))
    # Subscribe to the vehicles/vehiclepi01/tests topic filter
    client.subscribe("vehicles/vehiclepi01/tests", qos=2) 
Example #14
Source File: vehicle_mqtt_client.py    From Hands-On-MQTT-Programming-with-Python with MIT License 5 votes vote down vote up
def on_connect(client, userdata, flags, rc):
        print("Result from connect: {}".format(
            mqtt.connack_string(rc)))
        # Check whether the result form connect is the CONNACK_ACCEPTED connack code
        if rc == mqtt.CONNACK_ACCEPTED:
            # Subscribe to the commands topic filter
            client.subscribe(
                VehicleCommandProcessor.commands_topic, 
                qos=2) 
Example #15
Source File: vehicle_mqtt_remote_control.py    From Hands-On-MQTT-Programming-with-Python with MIT License 5 votes vote down vote up
def on_connect(client, userdata, flags, rc):
    print("Result from connect: {}".format(
        mqtt.connack_string(rc)))
    # Check whether the result form connect is the CONNACK_ACCEPTED connack code
    if rc == mqtt.CONNACK_ACCEPTED:
        # Subscribe to the commands topic filter
        client.subscribe(
            processed_commands_topic, 
            qos=2) 
Example #16
Source File: vehicle_mqtt_client.py    From Hands-On-MQTT-Programming-with-Python with MIT License 5 votes vote down vote up
def on_connect(client, userdata, flags, rc):
        print("Result from connect: {}".format(
            mqtt.connack_string(rc)))
        # Check whether the result form connect is the CONNACK_ACCEPTED connack code
        if rc == mqtt.CONNACK_ACCEPTED:
            # Subscribe to the commands topic filter
            client.subscribe(
                VehicleCommandProcessor.commands_topic, 
                qos=2) 
Example #17
Source File: subscribe_with_paho.py    From Hands-On-MQTT-Programming-with-Python with MIT License 5 votes vote down vote up
def on_connect(client, userdata, flags, rc):
    print("Result from connect: {}".format(
        mqtt.connack_string(rc)))
    # Subscribe to the vehicles/vehiclepi01/tests topic filter
    client.subscribe("vehicles/vehiclepi01/tests", qos=2) 
Example #18
Source File: surfboard_monitor.py    From Hands-On-MQTT-Programming-with-Python with MIT License 5 votes vote down vote up
def on_connect_pubnub(client, userdata, flags, rc):
    print("Result from PubNub connect: {}".format(
        mqtt.connack_string(rc)))
    # Check whether the result form connect is the CONNACK_ACCEPTED connack code
    if rc == mqtt.CONNACK_ACCEPTED:
        Surfboard.active_instance.is_pubnub_connected = True 
Example #19
Source File: surfboard_monitor.py    From Hands-On-MQTT-Programming-with-Python with MIT License 5 votes vote down vote up
def on_connect_mosquitto(client, userdata, flags, rc):
    print("Result from Mosquitto connect: {}".format(
        mqtt.connack_string(rc)))
    # Check whether the result form connect is the CONNACK_ACCEPTED connack code
    if rc == mqtt.CONNACK_ACCEPTED:
        # Subscribe to a topic filter that provides all the sensors
        sensors_topic_filter = topic_format.format(
            surfboard_name,
            "+")
        client.subscribe(sensors_topic_filter, qos=0) 
Example #20
Source File: surfboard_sensors_emulator.py    From Hands-On-MQTT-Programming-with-Python with MIT License 5 votes vote down vote up
def on_connect(client, userdata, flags, rc):
    print("Result from connect: {}".format(
        mqtt.connack_string(rc)))
    # Check whether the result form connect is the CONNACK_ACCEPTED connack code
    if rc != mqtt.CONNACK_ACCEPTED:
        raise IOError("I couldn't establish a connection with the MQTT server") 
Example #21
Source File: mqtt_locust.py    From mqtt-locust with MIT License 5 votes vote down vote up
def locust_on_connect(self, client, flags_dict, userdata, rc):
        #print("Connection returned result: "+mqtt.connack_string(rc))        
        fire_locust_success(
            request_type=REQUEST_TYPE,
            name='connect',
            response_time=0,
            response_length=0
            ) 
Example #22
Source File: gateway.py    From python-docs-samples with Apache License 2.0 5 votes vote down vote up
def on_connect(client, unused_userdata, unused_flags, rc):
    """Callback for when a device connects."""
    print('on_connect', mqtt.connack_string(rc))

    gateway_state.connected = True

    # Subscribe to the config topic.
    client.subscribe(gateway_state.mqtt_config_topic, qos=1) 
Example #23
Source File: cloudiot_mqtt_example.py    From python-docs-samples with Apache License 2.0 5 votes vote down vote up
def on_connect(unused_client, unused_userdata, unused_flags, rc):
    """Callback for when a device connects."""
    print('on_connect', mqtt.connack_string(rc))

    # After a successful connect, reset backoff time and stop backing off.
    global should_backoff
    global minimum_backoff_time
    should_backoff = False
    minimum_backoff_time = 1 
Example #24
Source File: mqtt_transport.py    From azure-iot-sdk-python-preview with MIT License 5 votes vote down vote up
def _create_error_from_conack_rc_code(rc):
    """
    Given a paho CONACK rc code, return an Exception that can be raised
    """
    message = mqtt.connack_string(rc)
    if rc in paho_conack_rc_to_error:
        return paho_conack_rc_to_error[rc](message)
    else:
        return errors.ProtocolClientError("Unknown CONACK rc={}".format(rc)) 
Example #25
Source File: main.py    From GarageQTPi with MIT License 5 votes vote down vote up
def on_connect(client, userdata, rc):
    print "Connected with result code: %s" % mqtt.connack_string(rc)
    for config in CONFIG['doors']:
        command_topic = config['command_topic']
        print "Listening for commands on %s" % command_topic
        client.subscribe(command_topic)

# Execute the specified command for a door 
Example #26
Source File: mqtt_transport.py    From azure-iot-sdk-python with MIT License 5 votes vote down vote up
def _create_error_from_connack_rc_code(rc):
    """
    Given a paho CONNACK rc code, return an Exception that can be raised
    """
    message = mqtt.connack_string(rc)
    if rc in paho_connack_rc_to_error:
        return paho_connack_rc_to_error[rc](message)
    else:
        return exceptions.ProtocolClientError("Unknown CONNACK rc={}".format(rc))