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


Python MQTTLib.AWSIoTMQTTClient方法代码示例

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


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

示例1: waitForResponse

# 需要导入模块: from AWSIoTPythonSDK import MQTTLib [as 别名]
# 或者: from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient [as 别名]
def waitForResponse():
    myAWSIoTMQTTClient = AWSIoTMQTTClient(clientId)
    myAWSIoTMQTTClient.configureEndpoint(host, port)
    myAWSIoTMQTTClient.configureCredentials(rootCAPath, privateKeyPath, certificatePath)
    myAWSIoTMQTTClient.configureAutoReconnectBackoffTime(1, 32, 20)
    myAWSIoTMQTTClient.configureOfflinePublishQueueing(-1)  # Infinite offline Publish queueing
    myAWSIoTMQTTClient.configureDrainingFrequency(2)  # Draining: 2 Hz
    myAWSIoTMQTTClient.configureConnectDisconnectTimeout(10)  # 10 sec
    myAWSIoTMQTTClient.configureMQTTOperationTimeout(5)  # 5 sec
    myAWSIoTMQTTClient.connect()
    myAWSIoTMQTTClient.subscribe(topic, 1, customCallback)
    time.sleep(2)

    # Publish to the same topic in a loop forever
    loopCount = 0
    while True:
        time.sleep(2) 
开发者ID:aws-samples,项目名称:aws-builders-fair-projects,代码行数:19,代码来源:recorder.py

示例2: clearLastWill

# 需要导入模块: from AWSIoTPythonSDK import MQTTLib [as 别名]
# 或者: from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient [as 别名]
def clearLastWill(self):
        """
        **Description**

        Used to clear the last will configuration that is previously set through configureLastWill. This is a public
        facing API inherited by application level public clients.

        **Syntax**

        .. code:: python

          myShadowClient.clearLastWill()
          myJobsClient.clearLastWill()

        **Parameter**

        None

        **Returns**

        None
        
        """
        # AWSIoTMQTTClient.clearLastWill()
        self._AWSIoTMQTTClient.clearLastWill() 
开发者ID:aws,项目名称:aws-iot-device-sdk-python,代码行数:27,代码来源:MQTTLib.py

示例3: connect_client

# 需要导入模块: from AWSIoTPythonSDK import MQTTLib [as 别名]
# 或者: from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient [as 别名]
def connect_client(self):
        # Init AWSIoTMQTTClient
        self.myAWSIoTMQTTClient = None
        if self.useWebsocket:
            self.myAWSIoTMQTTClient = AWSIoTMQTTClient(self.clientId, useWebsocket=True)
            self.myAWSIoTMQTTClient.configureEndpoint(self.host, 443)
            self.myAWSIoTMQTTClient.configureCredentials(self.rootCAPath)
        else:
            self.myAWSIoTMQTTClient = AWSIoTMQTTClient(self.clientId)
            self.myAWSIoTMQTTClient.configureEndpoint(self.host, 8883)
            self.myAWSIoTMQTTClient.configureCredentials(self.rootCAPath, self.privateKeyPath, self.certificatePath)

        # AWSIoTMQTTClient connection configuration
        self.myAWSIoTMQTTClient.configureAutoReconnectBackoffTime(1, 32, 20)
        self.myAWSIoTMQTTClient.configureOfflinePublishQueueing(-1)  # Infinite offline Publish queueing
        self.myAWSIoTMQTTClient.configureDrainingFrequency(2)  # Draining: 2 Hz
        self.myAWSIoTMQTTClient.configureConnectDisconnectTimeout(10)  # 10 sec
        self.myAWSIoTMQTTClient.configureMQTTOperationTimeout(5)  # 5 sec

        # Connect and subscribe to AWS IoT
        self.myAWSIoTMQTTClient.connect() 
开发者ID:aws-samples,项目名称:aws-builders-fair-projects,代码行数:23,代码来源:inference_worker.py

示例4: core_connect

# 需要导入模块: from AWSIoTPythonSDK import MQTTLib [as 别名]
# 或者: from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient [as 别名]
def core_connect(device_name, config_file, root_ca, certificate, private_key,
                 group_ca_path):
    global ggd_name, mqttc
    cfg = GroupConfigFile(config_file)
    ggd_name = cfg['devices'][device_name]['thing_name']
    iot_endpoint = cfg['misc']['iot_endpoint']

    dip = DiscoveryInfoProvider()
    dip.configureEndpoint(iot_endpoint)
    dip.configureCredentials(
        caPath=root_ca, certPath=certificate, keyPath=private_key
    )
    dip.configureTimeout(10)  # 10 sec
    logging.info("[button] Discovery using CA:{0} cert:{1} prv_key:{2}".format(
        root_ca, certificate, private_key
    ))

    gg_core, discovery_info = utils.discover_configured_core(
        device_name=device_name, dip=dip, config_file=config_file,
    )
    if not gg_core:
        raise EnvironmentError("[button] Couldn't find the Core")

    ca_list = discovery_info.getAllCas()
    group_id, ca = ca_list[0]
    group_ca_file = utils.save_group_ca(ca, group_ca_path, group_id)

    mqttc = AWSIoTMQTTClient(ggd_name)
    # local Greengrass Core discovered, now connect to Core from this Device
    log.info("[button] gca_file:{0} cert:{1}".format(
        group_ca_file, certificate))
    mqttc.configureCredentials(group_ca_file, private_key, certificate)
    mqttc.configureOfflinePublishQueueing(10, DROP_OLDEST)

    return mqttc, gg_core 
开发者ID:aws-samples,项目名称:aws-greengrass-mini-fulfillment,代码行数:37,代码来源:button.py

示例5: __init__

# 需要导入模块: from AWSIoTPythonSDK import MQTTLib [as 别名]
# 或者: from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient [as 别名]
def __init__(self, clientID, protocolType=MQTTv3_1_1, useWebsocket=False, cleanSession=True, awsIoTMQTTClient=None):
        """

        This class is used internally by the SDK and should not be instantiated directly.

        It delegates to a provided AWS IoT MQTT Client or creates a new one given the configuration
        parameters and exposes core operations for subclasses provide convenience methods

        **Syntax**

        None

        **Parameters**

        *clientID* - String that denotes the client identifier used to connect to AWS IoT.
        If empty string were provided, client id for this connection will be randomly generated 
        n server side.

        *protocolType* - MQTT version in use for this connection. Could be :code:`AWSIoTPythonSDK.MQTTLib.MQTTv3_1` or :code:`AWSIoTPythonSDK.MQTTLib.MQTTv3_1_1`

        *useWebsocket* - Boolean that denotes enabling MQTT over Websocket SigV4 or not.

        **Returns**

        AWSIoTPythonSDK.MQTTLib._AWSIoTMQTTDelegatingClient object

        """
        # AWSIOTMQTTClient instance
        self._AWSIoTMQTTClient = awsIoTMQTTClient if awsIoTMQTTClient is not None else AWSIoTMQTTClient(clientID, protocolType, useWebsocket, cleanSession)

    # Configuration APIs 
开发者ID:aws,项目名称:aws-iot-device-sdk-python,代码行数:33,代码来源:MQTTLib.py

示例6: configureLastWill

# 需要导入模块: from AWSIoTPythonSDK import MQTTLib [as 别名]
# 或者: from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient [as 别名]
def configureLastWill(self, topic, payload, QoS):
        """
        **Description**

        Used to configure the last will topic, payload and QoS of the client. Should be called before connect. This is a public
        facing API inherited by application level public clients.

        **Syntax**

        .. code:: python

          myShadowClient.configureLastWill("last/Will/Topic", "lastWillPayload", 0)
          myJobsClient.configureLastWill("last/Will/Topic", "lastWillPayload", 0)

        **Parameters**

        *topic* - Topic name that last will publishes to.

        *payload* - Payload to publish for last will.

        *QoS* - Quality of Service. Could be 0 or 1.

        **Returns**

        None

        """
        # AWSIoTMQTTClient.configureLastWill(srcTopic, srcPayload, srcQos)
        self._AWSIoTMQTTClient.configureLastWill(topic, payload, QoS) 
开发者ID:aws,项目名称:aws-iot-device-sdk-python,代码行数:31,代码来源:MQTTLib.py

示例7: configureEndpoint

# 需要导入模块: from AWSIoTPythonSDK import MQTTLib [as 别名]
# 或者: from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient [as 别名]
def configureEndpoint(self, hostName, portNumber):
        """
        **Description**

        Used to configure the host name and port number the underneath AWS IoT MQTT Client tries to connect to. Should be called
        before connect. This is a public facing API inherited by application level public clients.

        **Syntax**

        .. code:: python

          myShadowClient.clearLastWill("random.iot.region.amazonaws.com", 8883)
          myJobsClient.clearLastWill("random.iot.region.amazonaws.com", 8883)

        **Parameters**

        *hostName* - String that denotes the host name of the user-specific AWS IoT endpoint.

        *portNumber* - Integer that denotes the port number to connect to. Could be :code:`8883` for
        TLSv1.2 Mutual Authentication or :code:`443` for Websocket SigV4 and TLSv1.2 Mutual Authentication
        with ALPN extension.

        **Returns**

        None

        """
        # AWSIoTMQTTClient.configureEndpoint
        self._AWSIoTMQTTClient.configureEndpoint(hostName, portNumber) 
开发者ID:aws,项目名称:aws-iot-device-sdk-python,代码行数:31,代码来源:MQTTLib.py

示例8: configureCredentials

# 需要导入模块: from AWSIoTPythonSDK import MQTTLib [as 别名]
# 或者: from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient [as 别名]
def configureCredentials(self, CAFilePath, KeyPath="", CertificatePath=""):  # Should be good for MutualAuth and Websocket
        """
        **Description**

        Used to configure the rootCA, private key and certificate files. Should be called before connect. This is a public
        facing API inherited by application level public clients.

        **Syntax**

        .. code:: python

          myShadowClient.clearLastWill("PATH/TO/ROOT_CA", "PATH/TO/PRIVATE_KEY", "PATH/TO/CERTIFICATE")
          myJobsClient.clearLastWill("PATH/TO/ROOT_CA", "PATH/TO/PRIVATE_KEY", "PATH/TO/CERTIFICATE")

        **Parameters**

        *CAFilePath* - Path to read the root CA file. Required for all connection types.

        *KeyPath* - Path to read the private key. Required for X.509 certificate based connection.

        *CertificatePath* - Path to read the certificate. Required for X.509 certificate based connection.

        **Returns**

        None

        """
        # AWSIoTMQTTClient.configureCredentials
        self._AWSIoTMQTTClient.configureCredentials(CAFilePath, KeyPath, CertificatePath) 
开发者ID:aws,项目名称:aws-iot-device-sdk-python,代码行数:31,代码来源:MQTTLib.py

示例9: configureAutoReconnectBackoffTime

# 需要导入模块: from AWSIoTPythonSDK import MQTTLib [as 别名]
# 或者: from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient [as 别名]
def configureAutoReconnectBackoffTime(self, baseReconnectQuietTimeSecond, maxReconnectQuietTimeSecond, stableConnectionTimeSecond):
        """
        **Description**

        Used to configure the auto-reconnect backoff timing. Should be called before connect. This is a public
        facing API inherited by application level public clients.

        **Syntax**

        .. code:: python

          # Configure the auto-reconnect backoff to start with 1 second and use 128 seconds as a maximum back off time.
          # Connection over 20 seconds is considered stable and will reset the back off time back to its base.
          myShadowClient.clearLastWill(1, 128, 20)
          myJobsClient.clearLastWill(1, 128, 20)

        **Parameters**

        *baseReconnectQuietTimeSecond* - The initial back off time to start with, in seconds.
        Should be less than the stableConnectionTime.

        *maxReconnectQuietTimeSecond* - The maximum back off time, in seconds.

        *stableConnectionTimeSecond* - The number of seconds for a connection to last to be considered as stable.
        Back off time will be reset to base once the connection is stable.

        **Returns**

        None

        """
        # AWSIoTMQTTClient.configureBackoffTime
        self._AWSIoTMQTTClient.configureAutoReconnectBackoffTime(baseReconnectQuietTimeSecond, maxReconnectQuietTimeSecond, stableConnectionTimeSecond) 
开发者ID:aws,项目名称:aws-iot-device-sdk-python,代码行数:35,代码来源:MQTTLib.py

示例10: configureConnectDisconnectTimeout

# 需要导入模块: from AWSIoTPythonSDK import MQTTLib [as 别名]
# 或者: from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient [as 别名]
def configureConnectDisconnectTimeout(self, timeoutSecond):
        """
        **Description**

        Used to configure the time in seconds to wait for a CONNACK or a disconnect to complete. 
        Should be called before connect. This is a public facing API inherited by application level public clients.

        **Syntax**

        .. code:: python

          # Configure connect/disconnect timeout to be 10 seconds
          myShadowClient.configureConnectDisconnectTimeout(10)
          myJobsClient.configureConnectDisconnectTimeout(10)

        **Parameters**

        *timeoutSecond* - Time in seconds to wait for a CONNACK or a disconnect to complete.

        **Returns**

        None

        """
        # AWSIoTMQTTClient.configureConnectDisconnectTimeout
        self._AWSIoTMQTTClient.configureConnectDisconnectTimeout(timeoutSecond) 
开发者ID:aws,项目名称:aws-iot-device-sdk-python,代码行数:28,代码来源:MQTTLib.py

示例11: configureMQTTOperationTimeout

# 需要导入模块: from AWSIoTPythonSDK import MQTTLib [as 别名]
# 或者: from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient [as 别名]
def configureMQTTOperationTimeout(self, timeoutSecond):
        """
        **Description**

        Used to configure the timeout in seconds for MQTT QoS 1 publish, subscribe and unsubscribe. 
        Should be called before connect. This is a public facing API inherited by application level public clients.

        **Syntax**

        .. code:: python

          # Configure MQTT operation timeout to be 5 seconds
          myShadowClient.configureMQTTOperationTimeout(5)
          myJobsClient.configureMQTTOperationTimeout(5)

        **Parameters**

        *timeoutSecond* - Time in seconds to wait for a PUBACK/SUBACK/UNSUBACK.

        **Returns**

        None

        """
        # AWSIoTMQTTClient.configureMQTTOperationTimeout
        self._AWSIoTMQTTClient.configureMQTTOperationTimeout(timeoutSecond) 
开发者ID:aws,项目名称:aws-iot-device-sdk-python,代码行数:28,代码来源:MQTTLib.py

示例12: getMQTTConnection

# 需要导入模块: from AWSIoTPythonSDK import MQTTLib [as 别名]
# 或者: from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient [as 别名]
def getMQTTConnection(self):
        """
        **Description**

        Retrieve the AWS IoT MQTT Client used underneath, making it possible to perform
        plain MQTT operations along with specialized operations using the same single connection.
        This is a public facing API inherited by application level public clients.

        **Syntax**

        .. code:: python

          # Retrieve the AWS IoT MQTT Client used in the AWS IoT MQTT Delegating Client
          thisAWSIoTMQTTClient = myShadowClient.getMQTTConnection()
          thisAWSIoTMQTTClient = myJobsClient.getMQTTConnection()
          # Perform plain MQTT operations using the same connection
          thisAWSIoTMQTTClient.publish("Topic", "Payload", 1)
          ...

        **Parameters**

        None

        **Returns**

        AWSIoTPythonSDK.MQTTLib.AWSIoTMQTTClient object

        """
        # Return the internal AWSIoTMQTTClient instance
        return self._AWSIoTMQTTClient 
开发者ID:aws,项目名称:aws-iot-device-sdk-python,代码行数:32,代码来源:MQTTLib.py

示例13: connect_greengrass

# 需要导入模块: from AWSIoTPythonSDK import MQTTLib [as 别名]
# 或者: from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient [as 别名]
def connect_greengrass():
    global mqttClient, deviceShadowHandler
    retryCount = MAX_RETRIES
    coreInfo = dicovery_greengrass()
    mqttClient = AWSIoTMQTTClient(THING_NAME)

    while retryCount != 0:
        # Connect to Greengrass
        logger.info("MQTT Client setup")
        connected = False
        for connectivityInfo in coreInfo.connectivityInfoList:
            logger.info("connect to IP:{} port:{}".format(connectivityInfo.host, connectivityInfo.port))
            mqttClient.configureEndpoint(connectivityInfo.host, connectivityInfo.port)
            mqttClient.configureCredentials(GROUP_CA_FILE, PRIVATE_KEY_FILE, CERT_FILE)
            try:
                mqttClient.connect()
                logger.info("MQTT Client setup done")
                connected = True
                break
            except BaseException as e:
                print(e)
                pass

        if connected:
            mqttClient.subscribe(MOVE_COMMAND_TOPIC, 0, move_command_callback)
            logger.info("subscribe done")
            return

        # if connection fail
        retryCount -= 1
        backOffCore.backOff() 
开发者ID:aws-samples,项目名称:aws-builders-fair-projects,代码行数:33,代码来源:main.py

示例14: connect_greengrass

# 需要导入模块: from AWSIoTPythonSDK import MQTTLib [as 别名]
# 或者: from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient [as 别名]
def connect_greengrass():
    global mqttClient, deviceShadowHandler
    retryCount = MAX_RETRIES
    coreInfo = dicovery_greengrass()
    mqttClient = AWSIoTMQTTClient(THING_NAME)

    while retryCount != 0:
        # Connect to Greengrass
        logger.info("MQTT Client setup")
        connected = False
        for connectivityInfo in coreInfo.connectivityInfoList:
            logger.info("connect to IP:{} port:{}".format(connectivityInfo.host, connectivityInfo.port))
            mqttClient.configureEndpoint(connectivityInfo.host, connectivityInfo.port)
            mqttClient.configureCredentials(GROUP_CA_FILE, PRIVATE_KEY_FILE, CERT_FILE)
            try:
                mqttClient.connect()
                logger.info("MQTT Client setup done")
                connected = True
                break
            except BaseException as e:
                print(e)
                pass

        if connected:
            mqttClient.subscribe(RAIL_COMMAND_TOPIC, 0, receive_rail_command)
            logger.info("subscribe done")
            return

        # if connection fail
        retryCount -= 1
        backOffCore.backOff() 
开发者ID:aws-samples,项目名称:aws-builders-fair-projects,代码行数:33,代码来源:main.py

示例15: initialize_mqtt_client

# 需要导入模块: from AWSIoTPythonSDK import MQTTLib [as 别名]
# 或者: from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient [as 别名]
def initialize_mqtt_client(clientId=''):

    initialize_mqtt_client_logger = logging.getLogger('cerebro_processor.initialize_mqtt_client')
    initialize_mqtt_client_logger.info("In initialize_mqtt_client ...")

    if not clientId:
        initialize_mqtt_client_logger.error("Error! No clientId provided - cannot init IOTCore without this!")
        return None

    host = config.__IOT_HOST__
    rootCAPath = config.__IOT_ROOT_CA_PATH__
    certificatePath = config.__IOT_CERTIFICATE_PATH__
    privateKeyPath = config.__IOT_PRIVATE_KEY_PATH__

    topic = config.__IOT_TOPIC__

    port = 443

    # Init AWSIoTMQTTClient
    myAWSIoTMQTTClient = None

    myAWSIoTMQTTClient = AWSIoTMQTTClient(clientId)
    myAWSIoTMQTTClient.configureEndpoint(host, port)
    myAWSIoTMQTTClient.configureCredentials(rootCAPath, privateKeyPath, certificatePath)

    # AWSIoTMQTTClient connection configuration
    myAWSIoTMQTTClient.configureAutoReconnectBackoffTime(1, 32, 20)
    myAWSIoTMQTTClient.configureOfflinePublishQueueing(-1)  # Infinite offline Publish queueing
    myAWSIoTMQTTClient.configureDrainingFrequency(2)  # Draining: 2 Hz
    myAWSIoTMQTTClient.configureConnectDisconnectTimeout(10)  # 10 sec
    myAWSIoTMQTTClient.configureMQTTOperationTimeout(5)  # 5 sec

    # Connect and subscribe to AWS IoT
    myAWSIoTMQTTClient.connect()

    initialize_mqtt_client_logger.info("Completed initialize_mqtt_client!")

    return myAWSIoTMQTTClient 
开发者ID:aws-samples,项目名称:aws-builders-fair-projects,代码行数:40,代码来源:cerebro_processor.py


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