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


Python MQTTLib.AWSIoTMQTTShadowClient方法代码示例

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


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

示例1: connect_shadow_client

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

        # AWSIoTMQTTShadowClient configuration
        self.myAWSIoTMQTTShadowClient.configureAutoReconnectBackoffTime(1, 32, 20)
        self.myAWSIoTMQTTShadowClient.configureConnectDisconnectTimeout(10)  # 10 sec
        self.myAWSIoTMQTTShadowClient.configureMQTTOperationTimeout(5)  # 5 sec

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

示例2: __init__

# 需要导入模块: from AWSIoTPythonSDK import MQTTLib [as 别名]
# 或者: from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTShadowClient [as 别名]
def __init__(self, thingName, iotEndpoint, rootCA=rootCA, privateKey=privateKey, certFile=certFile):
    self.rootCA = rootCA
    self.privateKey = privateKey
    self.certFile = certFile
    self.iotEndpoint = iotEndpoint
    self.thingName = thingName
    self.shadowClient = AWSIoTMQTTShadowClient(self.thingName)
    self.deviceShadow = None
    self.mqttClient = None
    self.connect() 
开发者ID:aws-samples,项目名称:aws-builders-fair-projects,代码行数:12,代码来源:iot_client.py

示例3: _getAWSIoTMQTTShadowClient

# 需要导入模块: from AWSIoTPythonSDK import MQTTLib [as 别名]
# 或者: from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTShadowClient [as 别名]
def _getAWSIoTMQTTShadowClient(self, clientID, protocol, useWebsocket, cleanSession):
        return AWSIoTMQTTShadowClient(clientID, protocol, useWebsocket, cleanSession) 
开发者ID:aws,项目名称:aws-iot-device-sdk-arduino-yun,代码行数:4,代码来源:runtimeHub.py

示例4: local_shadow_connect

# 需要导入模块: from AWSIoTPythonSDK import MQTTLib [as 别名]
# 或者: from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTShadowClient [as 别名]
def local_shadow_connect(device_name, config_file, root_ca, certificate,
                         private_key, group_ca_dir):
    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(
        "[shadow_connect] Discovery using CA:{0} cert:{1} prv_key:{2}".format(
            root_ca, certificate, private_key
    ))
    gg_core, discovery_info = discover_configured_core(
        config_file=config_file, dip=dip, device_name=ggd_name,
    )
    if not gg_core:
        raise EnvironmentError("[core_connect] Couldn't find the Core")

    ca_list = discovery_info.getAllCas()
    core_list = discovery_info.getAllCores()
    group_id, ca = ca_list[0]
    core_info = core_list[0]
    logging.info("Discovered Greengrass Core:{0} from Group:{1}".format(
        core_info.coreThingArn, group_id)
    )
    group_ca_file = save_group_ca(ca, group_ca_dir, group_id)

    # local Greengrass Core discovered
    # get a shadow client to receive commands
    mqttsc = AWSIoTMQTTShadowClient(ggd_name)

    # now connect to Core from this Device
    logging.info("[core_connect] gca_file:{0} cert:{1}".format(
        group_ca_file, certificate))
    mqttsc.configureCredentials(group_ca_file, private_key, certificate)

    mqttc = mqttsc.getMQTTConnection()
    mqttc.configureOfflinePublishQueueing(10, DROP_OLDEST)
    if not mqtt_connect(mqttsc, gg_core):
        raise EnvironmentError("connection to Master Shadow failed.")

    # create and register the shadow handler on delta topics for commands
    # with a persistent connection to the Master shadow
    master_shadow = mqttsc.createShadowHandlerWithName(
        cfg['misc']['master_shadow_name'], True)

    return mqttc, mqttsc, master_shadow, ggd_name 
开发者ID:aws-samples,项目名称:aws-greengrass-mini-fulfillment,代码行数:53,代码来源:utils.py

示例5: __init__

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

        The client class that manages device shadow and accesses its functionality in AWS IoT over MQTT v3.1/3.1.1.

        It delegates to the AWS IoT MQTT Client and exposes devive shadow related operations.
        It shares the same connection types, synchronous MQTT operations and partial on-top features
        with the AWS IoT MQTT Client:

        - Auto reconnect/resubscribe

        Same as AWS IoT MQTT Client.

        - Progressive reconnect backoff

        Same as AWS IoT MQTT Client.

        - Offline publish requests queueing with draining

        Disabled by default. Queueing is not allowed for time-sensitive shadow requests/messages.

        **Syntax**

        .. code:: python

          import AWSIoTPythonSDK.MQTTLib as AWSIoTPyMQTT

          # Create an AWS IoT MQTT Shadow Client using TLSv1.2 Mutual Authentication
          myAWSIoTMQTTShadowClient = AWSIoTPyMQTT.AWSIoTMQTTShadowClient("testIoTPySDK")
          # Create an AWS IoT MQTT Shadow Client using Websocket SigV4
          myAWSIoTMQTTShadowClient = AWSIoTPyMQTT.AWSIoTMQTTShadowClient("testIoTPySDK",  useWebsocket=True)

        **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.AWSIoTMQTTShadowClient object

        """
        super(AWSIoTMQTTShadowClient, self).__init__(clientID, protocolType, useWebsocket, cleanSession, awsIoTMQTTClient)
        #leave passed in clients alone
        if awsIoTMQTTClient is None:
            # Configure it to disable offline Publish Queueing
            self._AWSIoTMQTTClient.configureOfflinePublishQueueing(0)  # Disable queueing, no queueing for time-sensitive shadow messages
            self._AWSIoTMQTTClient.configureDrainingFrequency(10)
        # Now retrieve the configured mqttCore and init a shadowManager instance
        self._shadowManager = shadowManager.shadowManager(self._AWSIoTMQTTClient._mqtt_core)

    # Shadow management API 
开发者ID:aws,项目名称:aws-iot-device-sdk-python,代码行数:59,代码来源:MQTTLib.py

示例6: __init__

# 需要导入模块: from AWSIoTPythonSDK import MQTTLib [as 别名]
# 或者: from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTShadowClient [as 别名]
def __init__(self):
        # Init data members
        # Connection related
        self._endpoint = ""
        self._rootCAFilePathList = ""
        self._certificateFilePathList = ""
        self._privateKeyFilePathList = ""
        self._useWebsocket = False
        self._AWSIoTMQTTShadowClient = None
        self._thermostatSimulatorShadowHandler = None
        # GUI related
        self._tkRootHandler = tkinter.Tk()
        self._reportedDataVariable = None
        self._reportedDataDisplayBox = None
        self._desiredDataVariable = None
        self._desiredDataDisplayBox = None
        self._setTemperatureInputBox = None
        self._setTemperatureButton = None
        # Check command line inputs
        if not self._checkInputs():
            raise ValueError("Malformed/Missing command line inputs.")
        # Create and configure AWSIoTMQTTShadowClient
        self._AWSIoTMQTTShadowClient = AWSIoTMQTTShadowClient("ThermostatSimulatorApp", useWebsocket=self._useWebsocket)
        if self._useWebsocket:
            self._AWSIoTMQTTShadowClient.configureEndpoint(self._endpoint, 443)
            self._AWSIoTMQTTShadowClient.configureCredentials(self._rootCAFilePathList[0])
        else:
            self._AWSIoTMQTTShadowClient.configureEndpoint(self._endpoint, 8883)
            self._AWSIoTMQTTShadowClient.configureCredentials(self._rootCAFilePathList[0], self._privateKeyFilePathList[0], self._certificateFilePathList[0])
        self._AWSIoTMQTTShadowClient.configureAutoReconnectBackoffTime(1, 128, 20)
        self._AWSIoTMQTTShadowClient.configureConnectDisconnectTimeout(10)
        self._AWSIoTMQTTShadowClient.configureMQTTOperationTimeout(5)
        # Set keepAlive interval to be 1 second and connect
        # Raise exception if there is an error in connecting to AWS IoT
        self._AWSIoTMQTTShadowClient.connect(5)
        self._thermostatSimulatorShadowHandler = self._AWSIoTMQTTShadowClient.createShadowHandlerWithName("room", True)
        # Generate GUI
        self._packModule()

    # Validate command line inputs
    # Return False there is any malformed inputs
    # Return True if all the necessary inputs have been discovered 
开发者ID:aws,项目名称:aws-iot-device-sdk-arduino-yun,代码行数:44,代码来源:ThermostatSimulatorApp.py


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