本文整理汇总了Python中paho.mqtt.client.connack_string方法的典型用法代码示例。如果您正苦于以下问题:Python client.connack_string方法的具体用法?Python client.connack_string怎么用?Python client.connack_string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类paho.mqtt.client
的用法示例。
在下文中一共展示了client.connack_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _start_client
# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import connack_string [as 别名]
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()
示例2: _on_connect
# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import connack_string [as 别名]
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)
示例3: _create_error_from_connack_rc_code
# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import connack_string [as 别名]
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))
示例4: on_connect
# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import connack_string [as 别名]
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
示例5: _create_error_from_conack_rc_code
# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import connack_string [as 别名]
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))
示例6: on_connect
# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import connack_string [as 别名]
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
示例7: on_connect
# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import connack_string [as 别名]
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)
示例8: locust_on_connect
# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import connack_string [as 别名]
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
)
示例9: on_connect
# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import connack_string [as 别名]
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")
开发者ID:PacktPublishing,项目名称:Hands-On-MQTT-Programming-with-Python,代码行数:8,代码来源:surfboard_sensors_emulator.py
示例10: on_connect_mosquitto
# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import connack_string [as 别名]
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)
示例11: on_connect_pubnub
# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import connack_string [as 别名]
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
示例12: on_connect
# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import connack_string [as 别名]
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)
示例13: on_connect
# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import connack_string [as 别名]
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)
开发者ID:PacktPublishing,项目名称:Hands-On-MQTT-Programming-with-Python,代码行数:11,代码来源:vehicle_mqtt_client.py
示例14: on_connect
# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import connack_string [as 别名]
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)
开发者ID:PacktPublishing,项目名称:Hands-On-MQTT-Programming-with-Python,代码行数:11,代码来源:vehicle_mqtt_remote_control.py
示例15: _on_connect
# 需要导入模块: from paho.mqtt import client [as 别名]
# 或者: from paho.mqtt.client import connack_string [as 别名]
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'])