- Newest
- Most votes
- Most comments
Hi,
Thanks for reaching out. I understand that you would like to retrieve the existing shadow document of a thing. This is certainly possible but I would like to confirm that a subsequent publish is required to get the existing shadow document. This is discussed here in our documentation
First, there would be a need to subscribe to the topics ShadowTopicPrefix/get/accepted
and ShadowTopicPrefix/get/rejected
as this is where the shadow document will be sent(or if the shadow cannot be retrieved).
Once subscribed to the above topics, there would be a need to publish an empty message to the ShadowTopicPrefix/get
topic. The current shadow will then be returned to the ShadowTopicPrefix/get/accepted
topic.
I've just tried this out and it does work as expected. I recommend trying it out in the MQTT test client in the AWS IoT console first. There is currently no topic which will return the existing shadow after subscribing without any subsequent publish.
An alternative to the above method would be using GetThingShadow
API -> https://docs.aws.amazon.com/iot/latest/apireference/API_iotdata_GetThingShadow.html. You can see the SDK equivalent of this API at the bottom of the documentation, for example, here is the link for the python boto3 SDK
I would recommend the first method since you are already using MQTT to communicate with IoT but just letting you know that the second method exists as well.
Please let us know if you may have any other questions.
Relevant content
- asked 2 years ago
- asked 2 years ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 3 years ago
Thanks a lot! I figured I might need to publish an empty one when just doing a subscribe but hoped maybe a missed something. Is there an equivalent react-native javascript library that calls GetThingShadow or do you recommend possibly making the API call directly when the app starts?
Also just curious what the difference between publishing to and subscribing to the /get and /get/accepted topics vs /update and /updated/accepted
Hi,
Thanks for your response. I checked our docs and we have documentation on how you can use the Javascript SDK in React Native -> https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/getting-started-react-native.html.
A publish to the /update topic means that you are trying to update the shadow document. If there is a corresponding message to the /updated/accepted this means that the update has been accepted -> https://docs.aws.amazon.com/iot/latest/developerguide/device-shadow-mqtt.html#update-pub-sub-topic
On the other hand, publishing an empty message to /get only retrieves the current shadow without any updates. As mentioned earlier, the current shadow state will be published to the /get/accepted topic.
Hope this helps! Let us know if anything is unclear.