This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3220S-LAUNCHXL: AWS Shadow Echo Sample problems

Part Number: CC3220S-LAUNCHXL
Other Parts Discussed in Thread: TIDM-1020

Hi,

1. I seem to get the below error a lot, but the shadow echo example still works fine. What does this error mean and should I be concerned about it?

ERROR: runAWSClient L#154
An error occurred in the loop -32

2. I noticed that the DeltaCallback function only prints out the delta value(s) that were changed in the AWS shadow. It doesn't print out any of the values that weren't changed in the AWS shadow. I wanted to ask if it was possible to retrieve the entire json "state" instead of just the delta value(s)?

  • Hi Jack,

    Error -32 is simply that the RX buffer you are using in the AWS shadow example is too small (MQTT_RX_BUFFER_TOO_SHORT_ERROR).. You can adjust the RX buffer size through modifying the AWS_IOT_MQTT_RX_BUF_LEN define in aws_iot_config.h.

    I don't think there is an API built into the AWS shadow API functions to retrieve the current shadow state. You could try to use the underlying MQTT topics to manually request the shadow state:

    https://docs.aws.amazon.com/iot/latest/developerguide/device-shadow-mqtt.html

    Let me know if you need more clarification or have further questions on this topic.

    Regards,

    Michael

  •  For #2, is it possible to register a delta callback for a specific value in the shadow instead of just the "state"?

    So instead of doing

    jsonStruct_t deltaObject;
    deltaObject.pData = stringToEchoDelta;
    deltaObject.dataLength = SHADOW_MAX_SIZE_OF_RX_BUFFER;
    deltaObject.pKey = "state";
    deltaObject.type = SHADOW_JSON_OBJECT;
    deltaObject.cb = DeltaCallback;

    I could do 

    jsonStruct_t deltaObject;
    deltaObject.pData = stringToEchoDelta;
    deltaObject.dataLength = SHADOW_MAX_SIZE_OF_RX_BUFFER;
    deltaObject.pKey = "value1";
    deltaObject.type = SHADOW_JSON_OBJECT;
    deltaObject.cb = Value1DeltaCallback;

    This way I can do specific actions based on changes on certain values in the shadow.

  • Michael Reymond For #2, is it possible to register a delta callback for a specific value in the shadow instead of just the "state"?

    So instead of doing

    ?

    1

    2

    3

    4

    5

    6

    jsonStruct_t deltaObject;

    deltaObject.pData = stringToEchoDelta;

    deltaObject.dataLength = SHADOW_MAX_SIZE_OF_RX_BUFFER;

    deltaObject.pKey = "state";

    deltaObject.type = SHADOW_JSON_OBJECT;

    deltaObject.cb = DeltaCallback;

    I could do

    ?

    1

    2

    3

    4

    5

    6

    jsonStruct_t deltaObject;

    deltaObject.pData = stringToEchoDelta;

    deltaObject.dataLength = SHADOW_MAX_SIZE_OF_RX_BUFFER;

    deltaObject.pKey = "value1";

    deltaObject.type = SHADOW_JSON_OBJECT;

    deltaObject.cb = Value1DeltaCallback;

    This way I can do specific actions based on changes on certain values in the shadow.

  • Hi,

    Looking closer at the AWS SDK APIs, it seems like it is actually possible to request the full shadow state from the cloud, using the aws_iot_shadow_get() API. You would use it like so:

    void ShadowGetCallback(const char *pThingName, ShadowActions_t action,
            Shadow_Ack_Status_t status, const char *pReceivedJsonDocument,
            void *pContextData)
    {
        IOT_INFO("%s",pReceivedJsonDocument);
    }
    
    aws_iot_shadow_get(&mqttClient, AWS_IOT_MY_THING_NAME,ShadowGetCallback, NULL, 4, false);

    As for your second question about setting a trigger for a specific shadow value to watch for, I would simply put an if statement in your shadow callback to check and see if the desired state is set to a specific value.

    Regards,

    Michael

  •  thanks. I also have another problem though. I've set up a button to update the "reported" status of the shadow every time it is pressed, by doing the below code. However, once this update is sent, it differs from the previous "desired" state which then triggers a delta change. How can I also update the "desired" state in addition to the "reported" state of the shadow so that I avoid this problem?

    if (buildJSONForReported(stringToEchoDelta, SHADOW_MAX_SIZE_OF_RX_BUFFER,
                                     valueString, strlen(valueString))) {
                messageArrivedOnDelta = false;
            }

  • Hi,

    I would simply use the aws_iot_shadow_add_desired() API to alter the "desired":{} section of your shadow JsonDocumentBuffer, and then use aws_iot_shadow_update() to push it to the cloud and overwrite the desired state much like how you report the state of your device using aws_iot_shadow_add_reported(). 

    I think that you may want to look at the mqtt_client_task.c file of the TIDM-1020 CC3220 AWS thermostat code. It implements much of the shadow manipulation that you are interested in. I suggest you take a look at that file as a guide for how to handle different AWS shadow use cases.

    Regards,
    Michael