2016-06-22 5 views
0

Je travaille sur aws iot et je suis capable d'obtenir l'état d'ombre mis à jour par le terminal via un script shell. Mais je peux obtenir root @ raspberrypi: ~ #. /aws_subscribe.py Connecté avec le code de résultat 0 et aussi dans aws iot home je suis en train de sortir de l'erreur de synchronisation Le est ci-joint. I followed the following linkL'état de l'ombre est désynchronisé dans aws et comment résoudre

+0

double possible de [sur \ _message ne fonctionne pas en python] (http://stackoverflow.com/questions/37984677/on-message-is-not-working-in-python) –

Répondre

0

Ceci est aussi loin que je peux obtenir. C'est moi qui court sur un pi de framboise alors j'ai besoin des certs. Je ne sais pas si vous avez besoin des certificats sur lambda. L'état d'ombre est renvoyé dans le rappel personnalisé. C'est ainsi qu'ils ont décidé de le faire. Je n'arrive toujours pas à comprendre comment obtenir l'état d'ombre en dehors du rappel afin que vous puissiez réellement faire quelque chose d'utile avec autre chose que l'impression.

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)