MediaTek-Labs / aws_mbedtls_mqtt

The source code to use mbedTLS library to connect to AWS mqtt IOT server.
62 stars 34 forks source link

Shadow example question #3

Closed ghost closed 8 years ago

ghost commented 8 years ago

I want to change the status of the on-board led(D13). So I add the below code,

`void windowActuate_Callback(const char pJsonString, uint32_t JsonStringDataLen, jsonStruct_t pContext) {

if (pContext != NULL) {
    Serial.print("\r\n\r\nDelta - Window state changed to ");
    Serial.println(*(bool *)(pContext->pData));
    Serial.println("\r\n\r\n");
    if((*(bool *)(pContext->pData)) == 1)
    {
        pinMode(13, OUTPUT);
        digitalWrite(13, HIGH);
    }
    else 
    {
        pinMode(13, OUTPUT);
        digitalWrite(13, LOW);
    }
}

}`

And in the aws iot web end, update the following:

{
  "desired": {
    "windowOpen": true
  },
  "reported": {
    "temperature": 22,
    "windowOpen": true
  }
}

It works well when the first time to update. But later it would not work any more.

Do you guys know what happen? Thanks.

johnrotach commented 8 years ago

Hi @loovee,

When you update the value in the AWS console are you changing the desired value? The app is driven off of scenarios where there is a delta (desired state != reported state).

The general flow of this app would be:

And so on. Hope this helps.

John AWS IoT

ghost commented 8 years ago

Thanks John, I works now.