本文整理匯總了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()
示例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()
示例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)
示例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
示例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
示例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