aws / aws-iot-device-sdk-arduino-yun

SDK for connecting to AWS IoT from an Arduino Yún.
Apache License 2.0
163 stars 77 forks source link

Shadow Upadate problems #36

Closed eczajk1 closed 7 years ago

eczajk1 commented 7 years ago

I am experiencing a situation where the shadow_update function seems to work once, but will then fail. I believe it returns GENERIC_ERROR (-1). This is the output from serial monitor:

eption in thread Thread-4 (most likely raised during interpr5
/bin/ash: su: not found
/bin/ash: my-thing-name: not found
}
/bin/ash: 1: not found
/bin/ash: 5: not found

and...

: No messages.
/bin/ash: su: not found
/bin/ash: my-thing-name: not found
}
/bin/ash: 2: not found
/bin/ash: 5: not found

and

/bin/ash: 5: not found
/bin/ash: su: not found
/bin/ash: my-thing-name: not found
}
/bin/ash: 2: not found
/bin/ash: 5: not found

Later I am getting a yield error:

/bin/ash: 1: not found
/bin/ash: z: not found
Yield failed.
-35

...where -35 is the result of myClient.yield()

This is from my log:

DEBUG:AWSIoTPythonSDK.core.protocol.mqttCore:Started a subscribe request 1
DEBUG:AWSIoTPythonSDK.core.protocol.mqttCore:_resubscribeCount: -1
DEBUG:AWSIoTPythonSDK.core.protocol.mqttCore:Subscribe request 1 sent.
DEBUG:AWSIoTPythonSDK.core.protocol.mqttCore:Subscribe request 1 succeeded. Time consumption: 40.0ms.
DEBUG:AWSIoTPythonSDK.core.protocol.mqttCore:Recover subscribe context for the next request: subscribeSent: False
INFO:AWSIoTPythonSDK.core.shadow.deviceShadow:Subscribed to delta topic for deviceShadow: my-thing-name
DEBUG:comm.serialCommunicationServer:Updated serialCommunicationServer internal protocolMessageQueue by inserting a new message. Size: 1
DEBUG:comm.serialCommunicationServer:Send through serial to remote client: S_RD T Size: 6
DEBUG:comm.serialCommunicationServer:Clear internal list. Size: 0
DEBUG:comm.serialCommunicationServer:Accept-timer starts, with acceptTimeout: 10 second(s).
DEBUG:comm.serialCommunicationServer:5 lines to be received. Loop begins.
DEBUG:comm.serialCommunicationServer:Received: 1/5 Message is: su
DEBUG:comm.serialCommunicationServer:Received: 2/5 Message is: my-thing-name
DEBUG:comm.serialCommunicationServer:Received: 3/5 Message is: {"state":{"reported":{"something": 0.00}}}
DEBUG:comm.serialCommunicationServer:Received: 4/5 Message is: 1
DEBUG:comm.serialCommunicationServer:Received: 5/5 Message is: 5
DEBUG:comm.serialCommunicationServer:Finish reading from remote client. Accept-timer ends.
DEBUG:AWSIoTPythonSDK.core.protocol.mqttCore:Started a subscribe request 2
DEBUG:AWSIoTPythonSDK.core.protocol.mqttCore:_resubscribeCount: -1
DEBUG:AWSIoTPythonSDK.core.protocol.mqttCore:Subscribe request 2 sent.
DEBUG:AWSIoTPythonSDK.core.protocol.mqttCore:Subscribe request 2 succeeded. Time consumption: 30.0ms.
DEBUG:AWSIoTPythonSDK.core.protocol.mqttCore:Recover subscribe context for the next request: subscribeSent: False
DEBUG:AWSIoTPythonSDK.core.protocol.mqttCore:Started a subscribe request 3
DEBUG:AWSIoTPythonSDK.core.protocol.mqttCore:_resubscribeCount: -1
DEBUG:AWSIoTPythonSDK.core.protocol.mqttCore:Subscribe request 3 sent.
DEBUG:AWSIoTPythonSDK.core.protocol.mqttCore:Subscribe request 3 succeeded. Time consumption: 80.0ms.
DEBUG:AWSIoTPythonSDK.core.protocol.mqttCore:Recover subscribe context for the next request: subscribeSent: False
INFO:AWSIoTPythonSDK.core.shadow.deviceShadow:Subscribed to update accepted/rejected topics for deviceShadow: my-thing-name
DEBUG:AWSIoTPythonSDK.core.protocol.mqttCore:Try to put a publish request 4 in the TCP stack.
DEBUG:AWSIoTPythonSDK.core.protocol.mqttCore:Publish request 4 succeeded.
DEBUG:comm.serialCommunicationServer:Updated serialCommunicationServer internal yieldMessageQueue by inserting a new message. Size: 1
DEBUG:AWSIoTPythonSDK.core.shadow.deviceShadow:shadow message clientToken: seeed02_my-thing-name_0_bnpyc
DEBUG:comm.serialCommunicationServer:Updated serialCommunicationServer internal protocolMessageQueue by inserting a new message. Size: 1
DEBUG:AWSIoTPythonSDK.core.shadow.deviceShadow:Token is in the pool. Type: accepted
DEBUG:comm.serialCommunicationServer:Send through serial to remote client: SU T Size: 4
DEBUG:comm.serialCommunicationServer:Updated serialCommunicationServer internal yieldMessageQueue by inserting a new message. Size: 2
DEBUG:comm.serialCommunicationServer:Clear internal list. Size: 0
DEBUG:comm.serialCommunicationServer:Accept-timer starts, with acceptTimeout: 10 second(s).
DEBUG:comm.serialCommunicationServer:1 lines to be received. Loop begins.
DEBUG:comm.serialCommunicationServer:Received: 1/1 Message is: z
DEBUG:comm.serialCommunicationServer:Finish reading from remote client. Accept-timer ends.
DEBUG:comm.serialCommunicationServer:Updated serialCommunicationServer internal protocolMessageQueue by inserting a new message. Size: 1
DEBUG:comm.serialCommunicationServer:Send through serial to remote client: Z T Size: 3
DEBUG:comm.serialCommunicationServer:Clear internal list. Size: 0
DEBUG:comm.serialCommunicationServer:Accept-timer starts, with acceptTimeout: 10 second(s).
DEBUG:comm.serialCommunicationServer:1 lines to be received. Loop begins.
DEBUG:comm.serialCommunicationServer:Received: 1/1 Message is: y
DEBUG:comm.serialCommunicationServer:Finish reading from remote client. Accept-timer ends.
DEBUG:comm.serialCommunicationServer:Start sending a new message to remote client: Y 0 0 JSON-2
DEBUG:comm.serialCommunicationServer:Send through serial to remote client. Chunk: Y 0 0 JSON-2 Size: 12
DEBUG:comm.serialCommunicationServer:Clear internal list. Size: 0
DEBUG:comm.serialCommunicationServer:Accept-timer starts, with acceptTimeout: 10 second(s).
DEBUG:comm.serialCommunicationServer:4 lines to be received. Loop begins.
DEBUG:comm.serialCommunicationServer:Received: 1/4 Message is: j
DEBUG:comm.serialCommunicationServer:Received: 2/4 Message is: JSON-2
DEBUG:comm.serialCommunicationServer:Received: 3/4 Message is: state"target
DEBUG:comm.serialCommunicationServer:Received: 4/4 Message is: 1
DEBUG:comm.serialCommunicationServer:Finish reading from remote client. Accept-timer ends.
DEBUG:comm.serialCommunicationServer:Updated serialCommunicationServer internal json buffer with a new JSON payload of size: 5
DEBUG:comm.serialCommunicationServer:JSON: Send through serial to remote client. Chunk: J 9.9 Size: 5
DEBUG:comm.serialCommunicationServer:Clear internal list. Size: 0
DEBUG:comm.serialCommunicationServer:Accept-timer starts, with acceptTimeout: 10 second(s).
DEBUG:comm.serialCommunicationServer:4 lines to be received. Loop begins.
DEBUG:comm.serialCommunicationServer:Received: 1/4 Message is: j
DEBUG:comm.serialCommunicationServer:Received: 2/4 Message is: JSON-2
DEBUG:comm.serialCommunicationServer:Received: 3/4 Message is: state"target
DEBUG:comm.serialCommunicationServer:Received: 4/4 Message is: 0
DEBUG:comm.serialCommunicationServer:Finish reading from remote client. Accept-timer ends.
DEBUG:comm.serialCommunicationServer:No more chunks for this JSON payload. Exiting writeToExternalJSON.
DEBUG:comm.serialCommunicationServer:Clear internal list. Size: 0
DEBUG:comm.serialCommunicationServer:Accept-timer starts, with acceptTimeout: 10 second(s).
DEBUG:comm.serialCommunicationServer:1 lines to be received. Loop begins.
DEBUG:comm.serialCommunicationServer:Received: 1/1 Message is: y
DEBUG:comm.serialCommunicationServer:Finish reading from remote client. Accept-timer ends.
DEBUG:comm.serialCommunicationServer:Start sending a new message to remote client: Y 1 0 JSON-0
DEBUG:comm.serialCommunicationServer:Send through serial to remote client. Chunk: Y 1 0 JSON-0 Size: 12
DEBUG:comm.serialCommunicationServer:Clear internal list. Size: 0
DEBUG:comm.serialCommunicationServer:Accept-timer starts, with acceptTimeout: 10 second(s).
DEBUG:comm.serialCommunicationServer:1 lines to be received. Loop begins.
DEBUG:comm.serialCommunicationServer:Received: 1/1 Message is: y
DEBUG:comm.serialCommunicationServer:Finish reading from remote client. Accept-timer ends.
DEBUG:comm.serialCommunicationServer:No more messages for yield. Exiting writeToExternalYield.
DEBUG:comm.serialCommunicationServer:Clear internal list. Size: 0
DEBUG:comm.serialCommunicationServer:Accept-timer starts, with acceptTimeout: 10 second(s).
DEBUG:comm.serialCommunicationServer:Raise a custom exception for accept timeout.
eczajk1 commented 7 years ago

More info:

I was making the shadow_update call from within the loop() function. I am able to get the code to work if I make the call from the delta callback function, as is done in the ThingShadowEcho example.

But, I need to try to update the shadow more frequently. Any insight into what why the call fails when called from loop()?

Thanks in advance.

liuszeng commented 7 years ago

Hi @eczajk1 ,

Thank you very much for using AWS IoT Arduino Yun SDK.

From the serial monitor output, it seems that the Python runtime got an exception and exited. All serial1 commands after that started failing because the expected response is not available any more.

You should be able to do shadow update in loop(). You can check out the example provided along with the SDK: https://github.com/aws/aws-iot-device-sdk-arduino-yun/blob/master/AWS-IoT-Arduino-Yun-Library/examples/ThermostatSimulatorDevice/ThermostatSimulatorDevice.ino

Do you have any log in the file when the exception happened? It should be logged as this: https://github.com/aws/aws-iot-device-sdk-arduino-yun/blob/master/AWS-IoT-Python-Runtime/runtime/runtimeHub.py#L335

Thanks, Liusu

eczajk1 commented 7 years ago

Thanks. I found the message:

DEBUG:runtimeHub:Exception in run: <type 'exceptions.ValueError'>invalid literal for int() with base 10: ''

I think this was just another coding error on my part. Thanks again for your help.