當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。