【问题标题】:Shadow status is out of sync in aws iot how to resolve影子状态在 aws iot 中不同步如何解决
【发布时间】:2020-01-01 05:33:28
【问题描述】:

我正在使用 aws iot 并能够通过 shell 脚本获取终端更新的影子状态。但我能够得到 root@raspberrypi:~# ./aws_subscribe.py 与结果代码 0 连接 而且在 aws iot home 中我也出现了不同步错误 下面附上。 I followed the following link

【问题讨论】:

标签: python amazon-web-services aws-iot


【解决方案1】:

这是我所能得到的。这是我在树莓派上运行,所以我需要证书。我不确定您是否需要 lambda 上的证书。阴影状态在自定义回调中返回。这是他们决定这样做的方式。我仍然无法弄清楚如何在回调之外获取影子状态,以便您实际上可以用它做一些有用的事情而不是打印。

   from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTShadowClient
   import logging
   import json 


def get(payload, responseStatus, token):
    dict = json.loads(payload)
    print(str(dict["state"]["desired"]["State"])) #make sure this matches your shadow names



# Read in command-line parameters
useWebsocket = False
host = "XXXXXYourINFO HEREXXXXXX.iot.us-east-1.amazonaws.com"
rootCAPath = "XXXXXYourINFO HEREXXXXXX"
certificatePath = "XXXXXYourINFO HEREXXXXXX"
privateKeyPath = "XXXXXYourINFO HEREXXXXXX"


# Configure logging
logger = logging.getLogger("AWSIoTPythonSDK.core")
logger.setLevel(logging.DEBUG)
streamHandler = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
streamHandler.setFormatter(formatter)
logger.addHandler(streamHandler)

# Init AWSIoTMQTTShadowClient

myAWSIoTMQTTShadowClient = AWSIoTMQTTShadowClient("basicShadowUpdater")
myAWSIoTMQTTShadowClient.configureEndpoint(host, 8883)
myAWSIoTMQTTShadowClient.configureCredentials(rootCAPath, privateKeyPath, certificatePath)

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

# Connect to AWS IoT
myAWSIoTMQTTShadowClient.connect()

# Create a deviceShadow with persistent subscription
Bot = myAWSIoTMQTTShadowClient.createShadowHandlerWithName("GarageRBP", True)

#get the shadow here and the state is included in the custom callback
Bot.shadowGet(get, 5)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-20
    • 2016-08-23
    • 2017-07-15
    • 1970-01-01
    • 2021-11-10
    • 1970-01-01
    • 2021-07-28
    • 1970-01-01
    相关资源
    最近更新 更多