espressif / esp-aws-iot

AWS IoT SDK for ESP32 based chipsets
Apache License 2.0
267 stars 160 forks source link

aws iot aws_iot_shadow_register_delta api 问题 (IDFGH-994) #1

Closed myzhang001 closed 5 years ago

myzhang001 commented 5 years ago

在使用 aws iot sdk 的时候 调用 aws_iot_shadow_register_delta()api 时候注册的字段超过9个 后 然后调用 aws_iot_shadow_update 就会导致复位

myzhang001 commented 5 years ago

程序流程

1.rc = aws_iot_shadow_init(&mqttClient, &sp);

  1. rc = aws_iot_shadow_connect(&mqttClient, &scp);
  2. rc = aws_iot_shadow_set_autoreconnect_status(&mqttClient, true); 4.rc = aws_iot_shadow_register_delta(&mqttClient, &power_strcut);

由于我的字段定义了11个所以我需要 注册11次aws_iot_shadow_register_delta 当我注册完成后在调用rc = aws_iot_shadow_init_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer); 和aws_iot_shadow_update 后程序就会复位

Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandl. Core 0 register dump:
PC : 0x400014fd PS : 0x00060c30 A0 : 0x800ec9c8 A1 : 0x3 A2 : 0x00000000 A3 : 0xfffffffc A4 : 0x000000ff A5 : 0x0 A6 : 0x00ff0000 A7 : 0xff000000 A8 : 0x00000000 A9 : 0x0 A10 : 0x00000033 A11 : 0x3ffae914 A12 : 0x00000001 A13 : 0x3 A14 : 0x3ffe0ec0 A15 : 0x00000003 SAR : 0x00000004 EXCCAUSE: 0x0 EXCVADDR: 0x00000000 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xf

Backtrace: 0x400014fd:0x3ffe11f0 0x400ec9c5:0x3ffe1200 0x400eac50:0x3ffe1220 0x0

Rebooting...
ets Jun 8 2016 00:22:57

mahavirj commented 5 years ago

@myzhang001 Could you please help to share entire application/test code with sdkconfig?

myzhang001 commented 5 years ago

`/ this is sdkconfig

myzhang001 commented 5 years ago

`#include "user_aws_handle.h"

include

include

include

include

include

include

include "freertos/FreeRTOS.h"

include "freertos/task.h"

include "freertos/event_groups.h"

include "esp_system.h"

include "esp_wifi.h"

include "esp_event_loop.h"

include "esp_log.h"

include "esp_vfs_fat.h"

include "driver/sdmmc_host.h"

include "nvs.h"

include "nvs_flash.h"

include "aws_iot_config.h"

include "aws_iot_log.h"

include "aws_iot_version.h"

include "aws_iot_mqtt_client_interface.h"

include "aws_iot_shadow_interface.h"

include "user_smart_config.h"

include "system_parameter.h"

/*!

define ROOMTEMPERATURE_UPPERLIMIT 32.0f

define ROOMTEMPERATURE_LOWERLIMIT 25.0f

define STARTING_ROOMTEMPERATURE ROOMTEMPERATURE_LOWERLIMIT

define MAX_LENGTH_OF_UPDATE_JSON_BUFFER 200*5

static const char *TAG = "shadow_user";

/ FreeRTOS event group to signal when we are connected & ready to make a request / extern EventGroupHandle_t wifi_event_group;

/ The event group allows multiple bits for each event, but we only care about one event - are we connected to the AP with an IP? / extern const int CONNECTED_BIT; extern const int SERVER_BIT;

/* CA Root certificate, device ("Thing") certificate and device

extern const uint8_t aws_root_ca_pem_start[] asm("_binary_aws_root_ca_pem_start"); extern const uint8_t aws_root_ca_pem_end[] asm("_binary_aws_root_ca_pem_end"); extern const uint8_t certificate_pem_crt_start[] asm("_binary_certificate_pem_crt_start"); extern const uint8_t certificate_pem_crt_end[] asm("_binary_certificate_pem_crt_end"); extern const uint8_t private_pem_key_start[] asm("_binary_private_pem_key_start"); extern const uint8_t private_pem_key_end[] asm("_binary_private_pem_key_end");

elif defined(CONFIG_EXAMPLE_FILESYSTEM_CERTS)

static const char DEVICE_CERTIFICATE_PATH = CONFIG_EXAMPLE_CERTIFICATE_PATH; static const char DEVICE_PRIVATE_KEY_PATH = CONFIG_EXAMPLE_PRIVATE_KEY_PATH; static const char * ROOT_CA_PATH = CONFIG_EXAMPLE_ROOT_CA_PATH;

else

error "Invalid method for loading certs"

endif

/*****static var start**/

static uint8_t status_step; //流程步骤 static uint8_t connect_step; //重连步骤

static uint8_t send_data_status; //发送数据状态
static uint8_t update_step_status; //发送步骤

// initialize the mqtt client AWS_IoT_Client mqttClient;

//delta 数据结构点 jsonStruct_t power_strcut; jsonStruct_t atomize_level_struct; jsonStruct_t light_switch_status; jsonStruct_t warring_status; jsonStruct_t cutedown_time_status; jsonStruct_t residue_time_status; jsonStruct_t light_mode_status; jsonStruct_t color_value_status; jsonStruct_t light_mode1_status; jsonStruct_t light_value_status; jsonStruct_t query_info_status;

/*****static var end**/

static void simulateRoomTemperature(float *pRoomTemperature) { static float deltaChange;

if(*pRoomTemperature >= ROOMTEMPERATURE_UPPERLIMIT) {
    deltaChange = -0.5f;
} else if(*pRoomTemperature <= ROOMTEMPERATURE_LOWERLIMIT) {
    deltaChange = 0.5f;
}

*pRoomTemperature += deltaChange;

}

static bool shadowUpdateInProgress;

static bool update_success_flag; //应答标志位

void ShadowUpdateStatusCallback(const char pThingName, ShadowActions_t action, Shadow_Ack_Status_t status, const char pReceivedJsonDocument, void *pContextData) { IOT_UNUSED(pThingName); IOT_UNUSED(action); IOT_UNUSED(pReceivedJsonDocument); IOT_UNUSED(pContextData);

//shadowUpdateInProgress = false;

#if 1

if(SHADOW_ACK_TIMEOUT == status) {
    ESP_LOGE(TAG, "Update timed out");
} else if(SHADOW_ACK_REJECTED == status) {
    ESP_LOGE(TAG, "Update rejected");
} else if(SHADOW_ACK_ACCEPTED == status) {
    ESP_LOGI(TAG, "Update accepted");

    //update_success_flag = true;    //更新成功标志位
}

#endif

}

void control_switch_dateStatusCallback(const char pThingName, ShadowActions_t action, Shadow_Ack_Status_t status, const char pReceivedJsonDocument, void *pContextData) { IOT_UNUSED(pThingName); IOT_UNUSED(action); IOT_UNUSED(pReceivedJsonDocument); IOT_UNUSED(pContextData);

//shadowUpdateInProgress = false;

if 1

if(SHADOW_ACK_TIMEOUT == status) {
    ESP_LOGE(TAG, "Update timed out");
} else if(SHADOW_ACK_REJECTED == status) {
    ESP_LOGE(TAG, "Update rejected");
} else if(SHADOW_ACK_ACCEPTED == status) {
    ESP_LOGI(TAG, "Update accepted");

    //update_success_flag = true;    //更新成功标志位
}

endif

}

void control_atomize_level_dateStatusCallback(const char pThingName, ShadowActions_t action, Shadow_Ack_Status_t status, const char pReceivedJsonDocument, void *pContextData) { IOT_UNUSED(pThingName); IOT_UNUSED(action); IOT_UNUSED(pReceivedJsonDocument); IOT_UNUSED(pContextData);

//shadowUpdateInProgress = false;

#if 1

if(SHADOW_ACK_TIMEOUT == status) {
    ESP_LOGE(TAG, "Update timed out");
} else if(SHADOW_ACK_REJECTED == status) {
    ESP_LOGE(TAG, "Update rejected");
} else if(SHADOW_ACK_ACCEPTED == status) {
    ESP_LOGI(TAG, "Update accepted");

    //update_success_flag = true;    //更新成功标志位
}

#endif

}

void control_light_swtich_dateStatusCallback(const char pThingName, ShadowActions_t action, Shadow_Ack_Status_t status, const char pReceivedJsonDocument, void *pContextData) { IOT_UNUSED(pThingName); IOT_UNUSED(action); IOT_UNUSED(pReceivedJsonDocument); IOT_UNUSED(pContextData);

//shadowUpdateInProgress = false;

#if 1

if(SHADOW_ACK_TIMEOUT == status) {
    ESP_LOGE(TAG, "Update timed out");
} else if(SHADOW_ACK_REJECTED == status) {
    ESP_LOGE(TAG, "Update rejected");
} else if(SHADOW_ACK_ACCEPTED == status) {
    ESP_LOGI(TAG, "Update accepted");

    //update_success_flag = true;    //更新成功标志位
}

#endif

}

void control_warring_dateStatusCallback(const char pThingName, ShadowActions_t action, Shadow_Ack_Status_t status, const char pReceivedJsonDocument, void *pContextData) { IOT_UNUSED(pThingName); IOT_UNUSED(action); IOT_UNUSED(pReceivedJsonDocument); IOT_UNUSED(pContextData);

#if 1

if(SHADOW_ACK_TIMEOUT == status) {
    ESP_LOGE(TAG, "Update timed out");
} else if(SHADOW_ACK_REJECTED == status) {
    ESP_LOGE(TAG, "Update rejected");
} else if(SHADOW_ACK_ACCEPTED == status) {
    ESP_LOGI(TAG, "Update accepted");

    //update_success_flag = true;    //更新成功标志位
}

#endif

}

void control_residue_dateStatusCallback(const char pThingName, ShadowActions_t action, Shadow_Ack_Status_t status, const char pReceivedJsonDocument, void *pContextData) { IOT_UNUSED(pThingName); IOT_UNUSED(action); IOT_UNUSED(pReceivedJsonDocument); IOT_UNUSED(pContextData);

#if 1

if(SHADOW_ACK_TIMEOUT == status) {
    ESP_LOGE(TAG, "Update timed out");
} else if(SHADOW_ACK_REJECTED == status) {
    ESP_LOGE(TAG, "Update rejected");
} else if(SHADOW_ACK_ACCEPTED == status) {
    ESP_LOGI(TAG, "Update accepted");

    //update_success_flag = true;    //更新成功标志位
}

#endif

}

void control_light_mode_dateStatusCallback(const char pThingName, ShadowActions_t action, Shadow_Ack_Status_t status, const char pReceivedJsonDocument, void *pContextData) { IOT_UNUSED(pThingName); IOT_UNUSED(action); IOT_UNUSED(pReceivedJsonDocument); IOT_UNUSED(pContextData);

//shadowUpdateInProgress = false;

#if 1

if(SHADOW_ACK_TIMEOUT == status) {
    ESP_LOGE(TAG, "Update timed out");
} else if(SHADOW_ACK_REJECTED == status) {
    ESP_LOGE(TAG, "Update rejected");
} else if(SHADOW_ACK_ACCEPTED == status) {
    ESP_LOGI(TAG, "Update accepted");

    //update_success_flag = true;    //更新成功标志位
}

#endif

}

void control_color_value_dateStatusCallback(const char pThingName, ShadowActions_t action, Shadow_Ack_Status_t status, const char pReceivedJsonDocument, void *pContextData) { IOT_UNUSED(pThingName); IOT_UNUSED(action); IOT_UNUSED(pReceivedJsonDocument); IOT_UNUSED(pContextData);

#if 1

if(SHADOW_ACK_TIMEOUT == status) {
    ESP_LOGE(TAG, "Update timed out");
} else if(SHADOW_ACK_REJECTED == status) {
    ESP_LOGE(TAG, "Update rejected");
} else if(SHADOW_ACK_ACCEPTED == status) {
    ESP_LOGI(TAG, "Update accepted");

    //update_success_flag = true;    //更新成功标志位
}

#endif

}

void control_light_mode1_dateStatusCallback(const char pThingName, ShadowActions_t action, Shadow_Ack_Status_t status, const char pReceivedJsonDocument, void *pContextData) { IOT_UNUSED(pThingName); IOT_UNUSED(action); IOT_UNUSED(pReceivedJsonDocument); IOT_UNUSED(pContextData);

#if 1

if(SHADOW_ACK_TIMEOUT == status) {
    ESP_LOGE(TAG, "Update timed out");
} else if(SHADOW_ACK_REJECTED == status) {
    ESP_LOGE(TAG, "Update rejected");
} else if(SHADOW_ACK_ACCEPTED == status) {
    ESP_LOGI(TAG, "Update accepted");

    //update_success_flag = true;    //更新成功标志位
}
#endif

}

//设备运行状态 void deviceUpdateStatusCallback(const char pThingName, ShadowActions_t action, Shadow_Ack_Status_t status, const char pReceivedJsonDocument, void *pContextData) { IOT_UNUSED(pThingName); IOT_UNUSED(action); IOT_UNUSED(pReceivedJsonDocument); IOT_UNUSED(pContextData);

//shadowUpdateInProgress = false;

#if 1

if(SHADOW_ACK_TIMEOUT == status) {
    ESP_LOGE(TAG, "Update timed out");
} else if(SHADOW_ACK_REJECTED == status) {
    ESP_LOGE(TAG, "Update rejected");
} else if(SHADOW_ACK_ACCEPTED == status) {
    ESP_LOGI(TAG, "Update accepted");

    //update_success_flag = true;    //更新成功标志位
}
#endif

}

//开关模式回调函数 void power_mode_switch_Callback(const char pJsonString, uint32_t JsonStringDataLen, jsonStruct_t pContext) { IOT_UNUSED(pJsonString); IOT_UNUSED(JsonStringDataLen);

//shadowUpdateInProgress = true;

if(pContext != NULL) {
    ESP_LOGI(TAG, "Delta - Window state changed to %s", (char *) (pContext->pData));
    ESP_LOGI(TAG," window %s",(char *)pContext->pData);
    memcpy(&sysworkpara.data_buffer.switch_buffer,(char *)pContext->pData,pContext->dataLength);

    sysworkpara.data_point.update_flag_high  |= 0x01; 

    if(strcmp(&sysworkpara.data_buffer.switch_buffer,"on") )
    {
        sysworkpara.data_point.switch_mode = 1;
    }
    if(strcmp(&sysworkpara.data_buffer.switch_buffer,"off") )
    {
        sysworkpara.data_point.switch_mode = 0; 
    }
    //ESP_LOGI(TAG, " update data len %d  data %s   ", JsonStringDataLen,pJsonString);
}

}

//雾量 void atomize_level_Callback(const char pJsonString, uint32_t JsonStringDataLen, jsonStruct_t pContext) { IOT_UNUSED(pJsonString); IOT_UNUSED(JsonStringDataLen);

if(pContext != NULL) {
    ESP_LOGI(TAG, "Delta - atomize state changed to %s", (char *) (pContext->pData));
    ESP_LOGI(TAG," atomize %s",(char *)pContext->pData);

    sysworkpara.data_point.update_flag_high  |= 0x02; 

    memcpy(&sysworkpara.data_buffer.atomize_buffer,(char *)pContext->pData,pContext->dataLength);
    if(strcmp(&sysworkpara.data_buffer.atomize_buffer,"small") )
    {
        sysworkpara.data_point.atomoze_level = 0;
    }
    if(strcmp(&sysworkpara.data_buffer.atomize_buffer,"large") )
    {
        sysworkpara.data_point.atomoze_level = 1;   
    }
    //ESP_LOGI(TAG, " update data len %d  data %s   ", JsonStringDataLen,pJsonString);
}

}

//灯光 void light_switch_Callback(const char pJsonString, uint32_t JsonStringDataLen, jsonStruct_t pContext) { IOT_UNUSED(pJsonString); IOT_UNUSED(JsonStringDataLen);

if(pContext != NULL) {
    ESP_LOGI(TAG, "Delta - light switch state changed to %s", (char *) (pContext->pData));
    ESP_LOGI(TAG," light switch  %s",(char *)pContext->pData);

    sysworkpara.data_point.update_flag_high  |= 0x04; 

    memcpy(&sysworkpara.data_buffer.light_switch_buffer,(char *)pContext->pData,pContext->dataLength);
    if(strcmp(&sysworkpara.data_buffer.light_switch_buffer,"off") )
    {
        sysworkpara.data_point.light_switch = 0;
    }
    if(strcmp(&sysworkpara.data_buffer.light_switch_buffer,"on") )
    {
        sysworkpara.data_point.light_switch = 1;    
    }
    //ESP_LOGI(TAG, " update data len %d  data %s   ", JsonStringDataLen,pJsonString);
}

}

//警告 void warring_Callback(const char pJsonString, uint32_t JsonStringDataLen, jsonStruct_t pContext) { IOT_UNUSED(pJsonString); IOT_UNUSED(JsonStringDataLen);

if(pContext != NULL) {

    ESP_LOGI(TAG, "Delta - warring state changed to %s", (char *) (pContext->pData));
    ESP_LOGI(TAG," warring  %s",(char *)pContext->pData);

    sysworkpara.data_point.update_flag_high  |= 0x08; 

    memcpy(&sysworkpara.data_buffer.warring_buffer,(char *)pContext->pData,pContext->dataLength);
    if(strcmp(&sysworkpara.data_buffer.warring_buffer,"off") )
    {
        sysworkpara.data_point.warring_status = 0;
    }
    if(strcmp(&sysworkpara.data_buffer.warring_buffer,"on") )
    {
        sysworkpara.data_point.warring_status = 1;  
    }
    //ESP_LOGI(TAG, " update data len %d  data %s   ", JsonStringDataLen,pJsonString);

}

}

//剩余时间 void cutedown_time_Callback(const char pJsonString, uint32_t JsonStringDataLen, jsonStruct_t pContext) { IOT_UNUSED(pJsonString); IOT_UNUSED(JsonStringDataLen);

if(pContext != NULL) {

    ESP_LOGI(TAG, "Delta - cutedown changed to %s", (char *) (pContext->pData));
    ESP_LOGI(TAG," cutedown  %s",(char *)pContext->pData);

    sysworkpara.data_point.update_flag_high  |= 0x10; 
    memcpy(&sysworkpara.data_buffer.time_cutedown_buffer,(char *)pContext->pData,pContext->dataLength);

    //ESP_LOGI(TAG, " update data len %d  data %s   ", JsonStringDataLen,pJsonString);
}

}

//倒计时时间 void residue_time_Callback(const char pJsonString, uint32_t JsonStringDataLen, jsonStruct_t pContext) { IOT_UNUSED(pJsonString); IOT_UNUSED(JsonStringDataLen);

if(pContext != NULL) {

    ESP_LOGI(TAG, "Delta - residue time changed to %s", (char *) (pContext->pData));
    ESP_LOGI(TAG," residue time  %s",(char *)pContext->pData);

    memcpy(&sysworkpara.data_buffer.time_cutedown_buffer,(char *)pContext->pData,pContext->dataLength);

    //ESP_LOGI(TAG, " update data len %d  data %s   ", JsonStringDataLen,pJsonString);

}

}

//灯光模式 void light_mode_Callback(const char pJsonString, uint32_t JsonStringDataLen, jsonStruct_t pContext){ IOT_UNUSED(pJsonString); IOT_UNUSED(JsonStringDataLen);

if(pContext != NULL) {

    ESP_LOGI(TAG, "Delta - light mode changed to %s", (char *) (pContext->pData));
    ESP_LOGI(TAG," light mode  %s",(char *)pContext->pData);

    sysworkpara.data_point.update_flag_high  |= 0x10; 

    memcpy(&sysworkpara.data_buffer.light_mode_buffer,(char *)pContext->pData,pContext->dataLength);
        if(strcmp(&sysworkpara.data_buffer.light_mode_buffer,"white") )
    {
        sysworkpara.data_point.light_mode = 0x00;
    }
    if(strcmp(&sysworkpara.data_buffer.warring_buffer,"color") )
    {
        sysworkpara.data_point.light_mode = 0x01;   
    }
    if(strcmp(&sysworkpara.data_buffer.warring_buffer,"color1") )
    {
        sysworkpara.data_point.light_mode = 0x02;   
    }
    if(strcmp(&sysworkpara.data_buffer.warring_buffer,"color2") )
    {
        sysworkpara.data_point.light_mode = 0x03;   
    }
    if(strcmp(&sysworkpara.data_buffer.warring_buffer,"color3") )
    {
        sysworkpara.data_point.light_mode = 0x04;   
    }
    if(strcmp(&sysworkpara.data_buffer.warring_buffer,"color4") )
    {
        sysworkpara.data_point.light_mode = 0x05;   
    }
    if(strcmp(&sysworkpara.data_buffer.warring_buffer,"color5") )
    {
        sysworkpara.data_point.light_mode = 0x06;   
    }
    //ESP_LOGI(TAG, " update data len %d  data %s   ", JsonStringDataLen,pJsonString);
}

}

//灯光模式 void color_value_Callback(const char pJsonString, uint32_t JsonStringDataLen, jsonStruct_t pContext) { IOT_UNUSED(pJsonString); IOT_UNUSED(JsonStringDataLen);

if(pContext != NULL) {

ESP_LOGI(TAG, "Delta - color_value changed to %s", (char *) (pContext->pData));
ESP_LOGI(TAG," color_value  %s",(char *)pContext->pData);

sysworkpara.data_point.update_flag_high  |= 0x20; 

memcpy(&sysworkpara.data_buffer.color_value_buffer,(char *)pContext->pData,pContext->dataLength);
//ESP_LOGI(TAG, " update data len %d  data %s   ", JsonStringDataLen,pJsonString);
}

}

//灯光模式 void light_mode1_Callback(const char pJsonString, uint32_t JsonStringDataLen, jsonStruct_t pContext){ IOT_UNUSED(pJsonString); IOT_UNUSED(JsonStringDataLen);

if(pContext != NULL) {

    ESP_LOGI(TAG, "Delta - light mode 1 changed to %s", (char *) (pContext->pData));
    ESP_LOGI(TAG," light mode 1  %s",(char *)pContext->pData);

    sysworkpara.data_point.update_flag_high  |= 0x40; 

    memcpy(&sysworkpara.data_buffer.light_mode1_buffer,(char *)pContext->pData,pContext->dataLength);
        if(strcmp(&sysworkpara.data_buffer.light_mode1_buffer,"white") )
    {
        sysworkpara.data_point.light_mode1 = 0x00;
    }
    if(strcmp(&sysworkpara.data_buffer.light_mode1_buffer,"color") )
    {
        sysworkpara.data_point.light_mode1 = 0x01;  
    }
    if(strcmp(&sysworkpara.data_buffer.light_mode1_buffer,"color1") )
    {
        sysworkpara.data_point.light_mode1 = 0x02;  
    }
    if(strcmp(&sysworkpara.data_buffer.light_mode1_buffer,"color2") )
    {
        sysworkpara.data_point.light_mode1 = 0x03;  
    }
    if(strcmp(&sysworkpara.data_buffer.light_mode1_buffer,"color3") )
    {
        sysworkpara.data_point.light_mode1 = 0x04;  
    }
    if(strcmp(&sysworkpara.data_buffer.light_mode1_buffer,"color4") )
    {
        sysworkpara.data_point.light_mode1 = 0x05;  
    }
    if(strcmp(&sysworkpara.data_buffer.light_mode1_buffer,"color5") )
    {
        sysworkpara.data_point.light_mode1 = 0x06;  
    }
    //ESP_LOGI(TAG, " update data len %d  data %s   ", JsonStringDataLen,pJsonString);
}

}

//灯光模式 void light_value_Callback(const char pJsonString, uint32_t JsonStringDataLen, jsonStruct_t pContext) { IOT_UNUSED(pJsonString); IOT_UNUSED(JsonStringDataLen);

if(pContext != NULL) {

ESP_LOGI(TAG, "Delta - light_valuechanged to %s", (char *) (pContext->pData));
ESP_LOGI(TAG," light_value  %s",(char *)pContext->pData);

sysworkpara.data_point.update_flag_high  |= 0x80; 

memcpy(&sysworkpara.data_buffer.light_value_buffer,(char *)pContext->pData,pContext->dataLength);
//ESP_LOGI(TAG, " update data len %d    data %s   ", JsonStringDataLen,pJsonString);

}

}

//查询设备所有信息 void query_info_Callback(const char pJsonString, uint32_t JsonStringDataLen, jsonStruct_t pContext) { IOT_UNUSED(pJsonString); IOT_UNUSED(JsonStringDataLen);

if(pContext != NULL) {

    ESP_LOGI(TAG, "Delta - query_info changed to %s", (char *) (pContext->pData));
    ESP_LOGI(TAG," query_info  %s",(char *)pContext->pData);

    //memcpy(&sysworkpara.data_buffer.light_value_buffer,(char *)pContext->pData,pContext->dataLength);

    /*查询所有设备信息*/

    sysworkpara.query_all_info_flag = 1;
    //ESP_LOGI(TAG, " update data len %d    data %s   ", JsonStringDataLen,pJsonString);

}

}

//上传控制数据 void contro_power_mode_switch(void) { IoT_Error_t rc = FAILURE;

char JsonDocumentBuffer[MAX_LENGTH_OF_UPDATE_JSON_BUFFER];
size_t sizeOfJsonDocumentBuffer = sizeof(JsonDocumentBuffer) / sizeof(JsonDocumentBuffer[0]);

rc = aws_iot_shadow_yield(&mqttClient,100);
//ESP_LOGI(TAG, "=======================================================================================");

rc = aws_iot_shadow_init_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
if(SUCCESS == rc) 
{
    rc = aws_iot_shadow_add_reported(JsonDocumentBuffer, sizeOfJsonDocumentBuffer,1,&power_strcut);

    if(SUCCESS == rc) 
    {
        rc = aws_iot_finalize_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
        if(SUCCESS == rc) 
        {
            //ESP_LOGI(TAG, "Update Shadow: %s", JsonDocumentBuffer);
            #if 1
            rc = aws_iot_shadow_update(&mqttClient, CONFIG_AWS_EXAMPLE_THING_NAME, JsonDocumentBuffer,
            control_switch_dateStatusCallback, NULL, 6, true);
            #endif

        }
    }
}

//ESP_LOGI(TAG, "*****************************************************************************************");
//ESP_LOGI(TAG, "Stack remaining for task '%s' is %d bytes", pcTaskGetTaskName(NULL), uxTaskGetStackHighWaterMark(NULL));

}

//上传雾量挡位变化 void contro_atomize_level(void) { IoT_Error_t rc = FAILURE;

char JsonDocumentBuffer[MAX_LENGTH_OF_UPDATE_JSON_BUFFER];
size_t sizeOfJsonDocumentBuffer = sizeof(JsonDocumentBuffer) / sizeof(JsonDocumentBuffer[0]);

rc = aws_iot_shadow_yield(&mqttClient,100);
//ESP_LOGI(TAG, "=======================================================================================");

rc = aws_iot_shadow_init_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
if(SUCCESS == rc) 
{
    rc = aws_iot_shadow_add_reported(JsonDocumentBuffer, sizeOfJsonDocumentBuffer,1,&atomize_level_struct);

    if(SUCCESS == rc) 
    {
        rc = aws_iot_finalize_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
        if(SUCCESS == rc) 
        {
            //ESP_LOGI(TAG, "Update Shadow: %s", JsonDocumentBuffer);
            #if 1
            rc = aws_iot_shadow_update(&mqttClient, CONFIG_AWS_EXAMPLE_THING_NAME, JsonDocumentBuffer,
            control_atomize_level_dateStatusCallback, NULL, 6, true);
            #endif

        }
    }
}

//ESP_LOGI(TAG, "*****************************************************************************************");
//ESP_LOGI(TAG, "Stack remaining for task '%s' is %d bytes", pcTaskGetTaskName(NULL), uxTaskGetStackHighWaterMark(NULL));

}

//灯光状态 void contro_light(void) { IoT_Error_t rc = FAILURE;

char JsonDocumentBuffer[MAX_LENGTH_OF_UPDATE_JSON_BUFFER];
size_t sizeOfJsonDocumentBuffer = sizeof(JsonDocumentBuffer) / sizeof(JsonDocumentBuffer[0]);

rc = aws_iot_shadow_yield(&mqttClient,100);
//ESP_LOGI(TAG, "=======================================================================================");

rc = aws_iot_shadow_init_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
if(SUCCESS == rc) 
{
    rc = aws_iot_shadow_add_reported(JsonDocumentBuffer, sizeOfJsonDocumentBuffer,1,&light_switch_status);

    if(SUCCESS == rc) 
    {
        rc = aws_iot_finalize_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
        if(SUCCESS == rc) 
        {
            //ESP_LOGI(TAG, "Update Shadow: %s", JsonDocumentBuffer);
            #if 1
            rc = aws_iot_shadow_update(&mqttClient, CONFIG_AWS_EXAMPLE_THING_NAME, JsonDocumentBuffer,
            control_light_swtich_dateStatusCallback, NULL, 6, true);
            #endif

        }
    }
}

//ESP_LOGI(TAG, "*****************************************************************************************");
//ESP_LOGI(TAG, "Stack remaining for task '%s' is %d bytes", pcTaskGetTaskName(NULL), uxTaskGetStackHighWaterMark(NULL));

}

void control_warring(void) { IoT_Error_t rc = FAILURE;

char JsonDocumentBuffer[MAX_LENGTH_OF_UPDATE_JSON_BUFFER];
size_t sizeOfJsonDocumentBuffer = sizeof(JsonDocumentBuffer) / sizeof(JsonDocumentBuffer[0]);

rc = aws_iot_shadow_yield(&mqttClient,100);
//ESP_LOGI(TAG, "=======================================================================================");

rc = aws_iot_shadow_init_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
if(SUCCESS == rc) 
{
    rc = aws_iot_shadow_add_reported(JsonDocumentBuffer, sizeOfJsonDocumentBuffer,1,&warring_status);

    if(SUCCESS == rc) 
    {
        rc = aws_iot_finalize_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
        if(SUCCESS == rc) 
        {
            //ESP_LOGI(TAG, "Update Shadow: %s", JsonDocumentBuffer);
        #if 1
            rc = aws_iot_shadow_update(&mqttClient, CONFIG_AWS_EXAMPLE_THING_NAME, JsonDocumentBuffer,
            control_warring_dateStatusCallback, NULL, 6, true);
        #endif

        }
    }
}

//ESP_LOGI(TAG, "*****************************************************************************************");
//ESP_LOGI(TAG, "Stack remaining for task '%s' is %d bytes", pcTaskGetTaskName(NULL), uxTaskGetStackHighWaterMark(NULL));

}

//倒计时 void control_cutedown(void) { IoT_Error_t rc = FAILURE;

char JsonDocumentBuffer[MAX_LENGTH_OF_UPDATE_JSON_BUFFER];
size_t sizeOfJsonDocumentBuffer = sizeof(JsonDocumentBuffer) / sizeof(JsonDocumentBuffer[0]);

rc = aws_iot_shadow_yield(&mqttClient,100);
//ESP_LOGI(TAG, "=======================================================================================");

rc = aws_iot_shadow_init_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
if(SUCCESS == rc) 
{
    rc = aws_iot_shadow_add_reported(JsonDocumentBuffer, sizeOfJsonDocumentBuffer,1,&cutedown_time_status);

    if(SUCCESS == rc) 
    {
        rc = aws_iot_finalize_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
        if(SUCCESS == rc) 
        {
            //ESP_LOGI(TAG, "Update Shadow: %s", JsonDocumentBuffer);
    #if 1
            rc = aws_iot_shadow_update(&mqttClient, CONFIG_AWS_EXAMPLE_THING_NAME, JsonDocumentBuffer,
            control_warring_dateStatusCallback, NULL, 6, true);
    #endif

        }
    }
}

//ESP_LOGI(TAG, "*****************************************************************************************");
//ESP_LOGI(TAG, "Stack remaining for task '%s' is %d bytes", pcTaskGetTaskName(NULL), uxTaskGetStackHighWaterMark(NULL));

}

void control_residue(void) { IoT_Error_t rc = FAILURE;

char JsonDocumentBuffer[MAX_LENGTH_OF_UPDATE_JSON_BUFFER];
size_t sizeOfJsonDocumentBuffer = sizeof(JsonDocumentBuffer) / sizeof(JsonDocumentBuffer[0]);

rc = aws_iot_shadow_yield(&mqttClient,100);
//ESP_LOGI(TAG, "=======================================================================================");

rc = aws_iot_shadow_init_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
if(SUCCESS == rc) 
{
    rc = aws_iot_shadow_add_reported(JsonDocumentBuffer, sizeOfJsonDocumentBuffer,1,&residue_time_status);

    if(SUCCESS == rc) 
    {
        rc = aws_iot_finalize_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
        if(SUCCESS == rc) 
        {
            //ESP_LOGI(TAG, "Update Shadow: %s", JsonDocumentBuffer);
    #if 1
            rc = aws_iot_shadow_update(&mqttClient, CONFIG_AWS_EXAMPLE_THING_NAME, JsonDocumentBuffer,
            control_residue_dateStatusCallback, NULL, 6, true);
    #endif

        }
    }
}

//ESP_LOGI(TAG, "*****************************************************************************************");
//ESP_LOGI(TAG, "Stack remaining for task '%s' is %d bytes", pcTaskGetTaskName(NULL), uxTaskGetStackHighWaterMark(NULL));

}

void control_light_mode(void) { IoT_Error_t rc = FAILURE;

char JsonDocumentBuffer[MAX_LENGTH_OF_UPDATE_JSON_BUFFER];
size_t sizeOfJsonDocumentBuffer = sizeof(JsonDocumentBuffer) / sizeof(JsonDocumentBuffer[0]);

rc = aws_iot_shadow_yield(&mqttClient,100);
//ESP_LOGI(TAG, "=======================================================================================");

rc = aws_iot_shadow_init_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
if(SUCCESS == rc) 
{
    rc = aws_iot_shadow_add_reported(JsonDocumentBuffer, sizeOfJsonDocumentBuffer,1,&light_mode_status);

    if(SUCCESS == rc) 
    {
        rc = aws_iot_finalize_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
        if(SUCCESS == rc) 
        {
            //ESP_LOGI(TAG, "Update Shadow: %s", JsonDocumentBuffer);
    #if 1
            rc = aws_iot_shadow_update(&mqttClient, CONFIG_AWS_EXAMPLE_THING_NAME, JsonDocumentBuffer,
            control_light_mode_dateStatusCallback, NULL, 6, true);
    #endif

        }
    }
}

//ESP_LOGI(TAG, "*****************************************************************************************");
//ESP_LOGI(TAG, "Stack remaining for task '%s' is %d bytes", pcTaskGetTaskName(NULL), uxTaskGetStackHighWaterMark(NULL));

}

void control_color_value(void) { IoT_Error_t rc = FAILURE;

char JsonDocumentBuffer[MAX_LENGTH_OF_UPDATE_JSON_BUFFER];
size_t sizeOfJsonDocumentBuffer = sizeof(JsonDocumentBuffer) / sizeof(JsonDocumentBuffer[0]);

rc = aws_iot_shadow_yield(&mqttClient,100);
//ESP_LOGI(TAG, "=======================================================================================");

rc = aws_iot_shadow_init_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
if(SUCCESS == rc) 
{
    rc = aws_iot_shadow_add_reported(JsonDocumentBuffer, sizeOfJsonDocumentBuffer,1,&color_value_status);

    if(SUCCESS == rc) 
    {
        rc = aws_iot_finalize_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
        if(SUCCESS == rc) 
        {
            //ESP_LOGI(TAG, "Update Shadow: %s", JsonDocumentBuffer);
    #if 1
            rc = aws_iot_shadow_update(&mqttClient, CONFIG_AWS_EXAMPLE_THING_NAME, JsonDocumentBuffer,
            control_color_value_dateStatusCallback, NULL, 6, true);
    #endif

        }
    }
}

//ESP_LOGI(TAG, "*****************************************************************************************");
//ESP_LOGI(TAG, "Stack remaining for task '%s' is %d bytes", pcTaskGetTaskName(NULL), uxTaskGetStackHighWaterMark(NULL));

}

void control_light_mode1(void) { IoT_Error_t rc = FAILURE;

char JsonDocumentBuffer[MAX_LENGTH_OF_UPDATE_JSON_BUFFER];
size_t sizeOfJsonDocumentBuffer = sizeof(JsonDocumentBuffer) / sizeof(JsonDocumentBuffer[0]);

rc = aws_iot_shadow_yield(&mqttClient,100);
//ESP_LOGI(TAG, "=======================================================================================");

rc = aws_iot_shadow_init_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
if(SUCCESS == rc) 
{
    rc = aws_iot_shadow_add_reported(JsonDocumentBuffer, sizeOfJsonDocumentBuffer,1,&light_mode1_status);

    if(SUCCESS == rc) 
    {
        rc = aws_iot_finalize_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
        if(SUCCESS == rc) 
        {
            //ESP_LOGI(TAG, "Update Shadow: %s", JsonDocumentBuffer);
    #if 1
            rc = aws_iot_shadow_update(&mqttClient, CONFIG_AWS_EXAMPLE_THING_NAME, JsonDocumentBuffer,
            control_light_mode1_dateStatusCallback, NULL, 6, true);
    #endif

        }
    }
}

//ESP_LOGI(TAG, "*****************************************************************************************");
//ESP_LOGI(TAG, "Stack remaining for task '%s' is %d bytes", pcTaskGetTaskName(NULL), uxTaskGetStackHighWaterMark(NULL));

}

void control_light_value(void) { IoT_Error_t rc = FAILURE;

char JsonDocumentBuffer[MAX_LENGTH_OF_UPDATE_JSON_BUFFER];
size_t sizeOfJsonDocumentBuffer = sizeof(JsonDocumentBuffer) / sizeof(JsonDocumentBuffer[0]);

rc = aws_iot_shadow_yield(&mqttClient,100);
//ESP_LOGI(TAG, "=======================================================================================");

rc = aws_iot_shadow_init_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
if(SUCCESS == rc) 
{
    rc = aws_iot_shadow_add_reported(JsonDocumentBuffer, sizeOfJsonDocumentBuffer,1,&light_value_status);

    if(SUCCESS == rc) 
    {
        rc = aws_iot_finalize_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
        if(SUCCESS == rc) 
        {
            //ESP_LOGI(TAG, "Update Shadow: %s", JsonDocumentBuffer);
    #if 1
            rc = aws_iot_shadow_update(&mqttClient, CONFIG_AWS_EXAMPLE_THING_NAME, JsonDocumentBuffer,
            control_light_mode1_dateStatusCallback, NULL, 6, true);
    #endif

        }
    }
}

//ESP_LOGI(TAG, "*****************************************************************************************");
//ESP_LOGI(TAG, "Stack remaining for task '%s' is %d bytes", pcTaskGetTaskName(NULL), uxTaskGetStackHighWaterMark(NULL));

}

//检测空闲状态 void aws_yield_task(void *param) { IoT_Error_t rc = FAILURE;

while(1)
{
    rc = aws_iot_shadow_yield(&mqttClient, 50);
    if(rc != SUCCESS)
    {
        ESP_LOGI(TAG,"-------------- error -----:  %d",rc);

        if( rc == NETWORK_ATTEMPTING_RECONNECT || rc == NETWORK_MANUALLY_DISCONNECTED )
        {
            set_G_server_mode(SERVER_DISCONNECT);                   //断开连接

        }           
    }

    vTaskDelay(150 / portTICK_RATE_MS);
}

}

static uint8_t all_info_step = 0; //数据包分成两部分发送

void aws_iot_task(void *param) { IoT_Error_t rc = FAILURE;

char JsonDocumentBuffer[MAX_LENGTH_OF_UPDATE_JSON_BUFFER];
size_t sizeOfJsonDocumentBuffer = sizeof(JsonDocumentBuffer) / sizeof(JsonDocumentBuffer[0]);
float temperature = 0.0;

power_strcut.cb = power_mode_switch_Callback;
power_strcut.pKey = "power";
power_strcut.pData = &sysworkpara.data_buffer.switch_buffer;
power_strcut.type = SHADOW_JSON_STRING;
power_strcut.dataLength = sizeof(sysworkpara.data_buffer.switch_buffer);

atomize_level_struct.cb = atomize_level_Callback;
atomize_level_struct.pKey = "atomize";
atomize_level_struct.pData = &sysworkpara.data_buffer.atomize_buffer;
atomize_level_struct.type = SHADOW_JSON_STRING;
atomize_level_struct.dataLength = sizeof(sysworkpara.data_buffer.atomize_buffer);

light_switch_status.cb    = light_switch_Callback;
light_switch_status.pKey  = "light_switch";
light_switch_status.pData = &sysworkpara.data_buffer.light_switch_buffer;
light_switch_status.type  = SHADOW_JSON_STRING;
light_switch_status.dataLength = sizeof(sysworkpara.data_buffer.light_switch_buffer);

warring_status.cb    = warring_Callback;
warring_status.pKey  = "warring";
warring_status.pData = &sysworkpara.data_buffer.warring_buffer;
warring_status.type  = SHADOW_JSON_STRING;
warring_status.dataLength = sizeof(sysworkpara.data_buffer.warring_buffer);

cutedown_time_status.cb    = cutedown_time_Callback;
cutedown_time_status.pKey  = "cutedown";
cutedown_time_status.pData = &sysworkpara.data_buffer.time_cutedown_buffer;
cutedown_time_status.type  = SHADOW_JSON_STRING;
cutedown_time_status.dataLength = sizeof(sysworkpara.data_buffer.time_cutedown_buffer);

residue_time_status.cb    = residue_time_Callback;
residue_time_status.pKey  = "residue_time";
residue_time_status.pData = &sysworkpara.data_buffer.time_cutedown_buffer;
residue_time_status.type  = SHADOW_JSON_STRING;
residue_time_status.dataLength = sizeof(sysworkpara.data_buffer.time_cutedown_buffer);

light_mode_status.cb    = light_mode_Callback;
light_mode_status.pKey  = "light_mode";
light_mode_status.pData = &sysworkpara.data_buffer.light_mode_buffer;
light_mode_status.type  = SHADOW_JSON_STRING;
light_mode_status.dataLength = sizeof(sysworkpara.data_buffer.light_mode_buffer);

color_value_status.cb    = color_value_Callback;
color_value_status.pKey  = "color_value";
color_value_status.pData = &sysworkpara.data_buffer.color_value_buffer;
color_value_status.type  = SHADOW_JSON_STRING;
color_value_status.dataLength = sizeof(sysworkpara.data_buffer.color_value_buffer);

light_mode1_status.cb   = light_mode1_Callback;
light_mode1_status.pKey = "light_mode1";
light_mode1_status.pData = &sysworkpara.data_buffer.light_mode1_buffer;
light_mode1_status.type = SHADOW_JSON_STRING;
light_mode1_status.dataLength = sizeof(sysworkpara.data_buffer.light_mode1_buffer);

light_value_status.cb   = light_value_Callback;
light_value_status.pKey = "light_value";
light_value_status.pData = &sysworkpara.data_buffer.light_value_buffer;
light_value_status.type = SHADOW_JSON_STRING;
light_value_status.dataLength = sizeof(sysworkpara.data_buffer.light_value_buffer);

/*查询所有设备信息*/

light_value_status.cb   = query_info_Callback;
light_value_status.pKey = "query_info";
light_value_status.pData = &sysworkpara.data_buffer.query_info_buffer;
light_value_status.type = SHADOW_JSON_STRING;
light_value_status.dataLength = sizeof(sysworkpara.data_buffer.query_info_buffer);

ESP_LOGI(TAG, "AWS IoT SDK Version %d.%d.%d-%s", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_TAG);

ShadowInitParameters_t sp = ShadowInitParametersDefault;
sp.pHost = AWS_IOT_MQTT_HOST;
sp.port = AWS_IOT_MQTT_PORT;

if defined(CONFIG_EXAMPLE_EMBEDDED_CERTS)

sp.pClientCRT = (const char *)certificate_pem_crt_start;
sp.pClientKey = (const char *)private_pem_key_start;
sp.pRootCA    = (const char *)aws_root_ca_pem_start;

elif defined(CONFIG_EXAMPLE_FILESYSTEM_CERTS)

sp.pClientCRT = DEVICE_CERTIFICATE_PATH;
sp.pClientKey = DEVICE_PRIVATE_KEY_PATH;
sp.pRootCA    = ROOT_CA_PATH;

endif

sp.enableAutoReconnect = false;
sp.disconnectHandler   = NULL;

ifdef CONFIG_EXAMPLE_SDCARD_CERTS

ESP_LOGI(TAG, "Mounting SD card...");
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
    .format_if_mount_failed = false,
    .max_files = 3,
};
sdmmc_card_t* card;
esp_err_t ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);
if (ret != ESP_OK) {
    ESP_LOGE(TAG, "Failed to mount SD card VFAT filesystem. Error: %s", esp_err_to_name(ret));
    abort();
}

endif

/* Wait for WiFI to show as connected */
xEventGroupWaitBits(wifi_event_group, SERVER_BIT,
                    false, true, portMAX_DELAY);

ShadowConnectParameters_t scp = ShadowConnectParametersDefault;
scp.pMyThingName = CONFIG_AWS_EXAMPLE_THING_NAME;
scp.pMqttClientId = CONFIG_AWS_EXAMPLE_CLIENT_ID;
scp.mqttClientIdLen = (uint16_t) strlen(CONFIG_AWS_EXAMPLE_CLIENT_ID);

while(1)
{
    if(status_step == SHADOW_INIT)
    {
        ESP_LOGI(TAG, "Shadow Init");
        rc = aws_iot_shadow_init(&mqttClient, &sp);
        if(SUCCESS != rc) 
        {
            ESP_LOGE(TAG, "aws_iot_shadow_init returned error %d, aborting...", rc);
            //abort();
        }
        else
        {
            connect_step = 0;
            status_step =  SHADOW_CONNECT;
        }
        vTaskDelay(1000 / portTICK_RATE_MS);
    }
    else if(status_step == SHADOW_CONNECT)
    {
        ESP_LOGI(TAG, "Shadow Connect");
        rc = aws_iot_shadow_connect(&mqttClient, &scp);
        if(SUCCESS != rc) 
        {
            ESP_LOGE(TAG, "aws_iot_shadow_connect returned error %d, aborting...", rc);

            #if 1
            if(rc != NETWORK_ERR_NET_UNKNOWN_HOST)     //路由器没有网络后会报错  
            {
                if(connect_step++);
                ESP_LOGI(TAG, "connected cnt :%d",connect_step);
                if(connect_step  > 6)
                {
                    connect_step = 0;
                    status_step = SHADOW_INIT;
                }
            }

            rc = aws_iot_shadow_disconnect(&mqttClient);

            if(rc != SUCCESS)
            {
                ESP_LOGI(TAG, "Shadow dis Connect  error");
            }
            #endif  
            //status_step = SHADOW_INIT;
        }
        else
        {
            connect_step = 0;
            status_step = SHADOW_RECONNECT;
        }

        vTaskDelay(100 / portTICK_RATE_MS);
    }
    else if(status_step == SHADOW_RECONNECT)
    {
        /*
        * Enable Auto Reconnect functionality. Minimum and Maximum time of Exponential backoff are set in aws_iot_config.h
        *  #AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL
        *  #AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL
        */

        set_G_server_mode(SERVER_CONNECT);             //已经连接 aws iot 平台

        rc = aws_iot_shadow_set_autoreconnect_status(&mqttClient, true);
        if(SUCCESS != rc) {
            ESP_LOGE(TAG, "Unable to set Auto Reconnect to true - %d, aborting...", rc);
            if(connect_step++ > 6)
            {
                connect_step = 0;
                status_step = SHADOW_INIT;
            }
        }
        else
        {
            connect_step = 0;
            status_step = SHADOW_REGISTER_DELTA;
        }   
        vTaskDelay(100 / portTICK_RATE_MS);
    }
    else if(status_step == SHADOW_REGISTER_DELTA)
    {
        rc = aws_iot_shadow_register_delta(&mqttClient, &power_strcut);
        if(SUCCESS != rc) 
        {
           ESP_LOGE(TAG, "Shadow Register Delta Error");
           status_step = SHADOW_INIT;
        }
        else
        {
            connect_step = 0;
            status_step = SHADOW_COMPLETE_CONNECT;
        }

        xTaskCreate(&aws_yield_task,"user task",4096,NULL,4,NULL);

        rc = aws_iot_shadow_register_delta(&mqttClient, &atomize_level_struct);

        if(SUCCESS != rc) 
        {
           ESP_LOGE(TAG, "Shadow Register Delta Error");
           status_step = SHADOW_INIT;
        }
        else
        {
            connect_step = 0;
            status_step = SHADOW_COMPLETE_CONNECT;
        }

        rc = aws_iot_shadow_register_delta(&mqttClient, &light_switch_status);

        if(SUCCESS != rc) 
        {
           ESP_LOGE(TAG, "Shadow Register Delta Error");
           status_step = SHADOW_INIT;
        }
        else
        {
            connect_step = 0;
            status_step = SHADOW_COMPLETE_CONNECT;
        }

        rc = aws_iot_shadow_register_delta(&mqttClient, &cutedown_time_status);

        if(SUCCESS != rc) 
        {
           ESP_LOGE(TAG, "Shadow Register Delta Error");
           status_step = SHADOW_INIT;
        }
        else
        {
            connect_step = 0;
            status_step = SHADOW_COMPLETE_CONNECT;
        }

        rc = aws_iot_shadow_register_delta(&mqttClient, &residue_time_status);

        if(SUCCESS != rc) 
        {
           ESP_LOGE(TAG, "Shadow Register Delta Error");
           status_step = SHADOW_INIT;
        }
        else
        {
            connect_step = 0;
            status_step = SHADOW_COMPLETE_CONNECT;
        }

        rc = aws_iot_shadow_register_delta(&mqttClient, &light_mode_status);

        if(SUCCESS != rc) 
        {
           ESP_LOGE(TAG, "Shadow Register Delta Error");
           status_step = SHADOW_INIT;
        }
        else
        {
            connect_step = 0;
            status_step = SHADOW_COMPLETE_CONNECT;
        }

        rc = aws_iot_shadow_register_delta(&mqttClient, &color_value_status);

        if(SUCCESS != rc) 
        {
           ESP_LOGE(TAG, "Shadow Register Delta Error");
           status_step = SHADOW_INIT;
        }
        else
        {
            connect_step = 0;
            status_step = SHADOW_COMPLETE_CONNECT;
        }

        rc = aws_iot_shadow_register_delta(&mqttClient, &light_mode1_status);

        if(SUCCESS != rc) 
        {
           ESP_LOGE(TAG, "Shadow Register Delta Error");
           status_step = SHADOW_INIT;
        }
        else
        {
            connect_step = 0;
            status_step = SHADOW_COMPLETE_CONNECT;
        }

        rc = aws_iot_shadow_register_delta(&mqttClient, &light_value_status);

        if(SUCCESS != rc) 
        {
           ESP_LOGE(TAG, "Shadow Register Delta Error");
           status_step = SHADOW_INIT;
        }
        else
        {
            connect_step = 0;
            status_step = SHADOW_COMPLETE_CONNECT;
        }

        #if 0
        rc = aws_iot_shadow_register_delta(&mqttClient, &query_info_status);

        if(SUCCESS != rc) 
        {
           ESP_LOGE(TAG, "Shadow Register Delta Error");
           status_step = SHADOW_INIT;
        }
        else
        {
            connect_step = 0;
            status_step = SHADOW_COMPLETE_CONNECT;
        }
        #endif

        vTaskDelay(100 /portTICK_RATE_MS);
    }
    else if(status_step == SHADOW_COMPLETE_CONNECT)
    {
        #if 0
        //1.更新数据  定时更新数据
        if(send_data_status == 0)     //发送数据
        {
            //if(NETWORK_ATTEMPTING_RECONNECT == rc || NETWORK_RECONNECTED == rc || SUCCESS == rc) 
            //if(shadowUpdateInProgress == true)
            {
                shadowUpdateInProgress = false;

                rc = aws_iot_shadow_yield(&mqttClient, 100);
                #if 0
                if(NETWORK_ATTEMPTING_RECONNECT == rc || shadowUpdateInProgress)
                {
                    rc = aws_iot_shadow_yield(&mqttClient, 1000);
                    // If the client is attempting to reconnect, or already waiting on a shadow update,
                    // we will skip the rest of the loop.
                    continue;
                }
                #endif
                //ESP_LOGI(TAG, "=======================================================================================");
                //ESP_LOGI(TAG, "On Device: window state %s", switch_status );
                //simulateRoomTemperature(&temperature);

                rc = aws_iot_shadow_init_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
                if(SUCCESS == rc) 
                {
                    #if 0
                    rc = aws_iot_shadow_add_reported(JsonDocumentBuffer, sizeOfJsonDocumentBuffer,3,&power_strcut,\
                    &atomize_level_struct,&light_switch_status);
                    #else
                    rc = aws_iot_shadow_add_reported(JsonDocumentBuffer, sizeOfJsonDocumentBuffer,6,&power_strcut,\
                    &atomize_level_struct,&light_switch_status,&warring_status,&cutedown_time_status,&residue_time_status,\
                    &light_mode_status,&color_value_status,&light_mode1_status,&light_value_status);
                    #endif
                    if(SUCCESS == rc) 
                    {
                        rc = aws_iot_finalize_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
                        if(SUCCESS == rc) 
                        {
                            //ESP_LOGI(TAG, "Update Shadow: %s", JsonDocumentBuffer);
                            #if 1
                            rc = aws_iot_shadow_update(&mqttClient, CONFIG_AWS_EXAMPLE_THING_NAME, JsonDocumentBuffer,
                            ShadowUpdateStatusCallback, NULL, 6, true);
                            #endif

                            shadowUpdateInProgress = true;
                        }
                    }
                }

                //ESP_LOGI(TAG, "*****************************************************************************************");
                ESP_LOGI(TAG, "Stack remaining for task '%s' is %d bytes", pcTaskGetTaskName(NULL), uxTaskGetStackHighWaterMark(NULL));

                send_data_status = 1;
            }
        }
        else if(send_data_status == 1)
        {
            rc = aws_iot_shadow_yield(&mqttClient, 100);
            vTaskDelay(5000 / portTICK_RATE_MS);
            send_data_status = 0;
        }
        #endif

        #if 1
        switch(send_data_status)
        {
            case 0:                    //上传控制数据
                if(sysworkpara.update_control_server_flag == 1)
                {
                    sysworkpara.update_control_server_flag = 0;

                }
                send_data_status = 1;
                break;
            case 1:                   //上传所有信息
                //if(sysworkpara.flag_mcu_query == 1)
                {
                    if(update_step_status == 0)
                    {
                        rc = aws_iot_shadow_yield(&mqttClient,100);
                        //ESP_LOGI(TAG, "=======================================================================================");

                        rc = aws_iot_shadow_init_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
                        if(SUCCESS == rc) 
                        {
                            #if 0
                            rc = aws_iot_shadow_add_reported(JsonDocumentBuffer, sizeOfJsonDocumentBuffer,3,&power_strcut,\
                            &atomize_level_struct,&light_switch_status);
                            #else
                            rc = aws_iot_shadow_add_reported(JsonDocumentBuffer, sizeOfJsonDocumentBuffer,6,&power_strcut,\
                            &atomize_level_struct,&light_switch_status,&warring_status,&cutedown_time_status,&residue_time_status);
                            #endif
                            if(SUCCESS == rc) 
                            {
                                rc = aws_iot_finalize_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
                                if(SUCCESS == rc) 
                                {
                                    //ESP_LOGI(TAG, "Update Shadow: %s", JsonDocumentBuffer);
                                    #if 1
                                    rc = aws_iot_shadow_update(&mqttClient, CONFIG_AWS_EXAMPLE_THING_NAME, JsonDocumentBuffer,
                                    ShadowUpdateStatusCallback, NULL, 6, true);
                                    #endif
                                    update_step_status = 1;

                                }
                            }
                        }

                        //ESP_LOGI(TAG, "*****************************************************************************************");
                        //ESP_LOGI(TAG, "Stack remaining for task '%s' is %d bytes", pcTaskGetTaskName(NULL), uxTaskGetStackHighWaterMark(NULL));
                    }
                    else if(update_step_status == 1)
                    {
                        rc = aws_iot_shadow_yield(&mqttClient, 100);
                        //ESP_LOGI(TAG, "=======================================================================================");

                        rc = aws_iot_shadow_init_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
                        if(SUCCESS == rc) 
                        {
                            #if 0
                            rc = aws_iot_shadow_add_reported(JsonDocumentBuffer, sizeOfJsonDocumentBuffer,3,&power_strcut,\
                            &atomize_level_struct,&light_switch_status);
                            #else
                            rc = aws_iot_shadow_add_reported(JsonDocumentBuffer, sizeOfJsonDocumentBuffer,4,\
                            &light_mode_status,&color_value_status,&light_mode1_status,&light_value_status);
                            #endif
                            if(SUCCESS == rc) 
                            {
                                rc = aws_iot_finalize_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
                                if(SUCCESS == rc) 
                                {
                                    //ESP_LOGI(TAG, "Update Shadow: %s", JsonDocumentBuffer);
                                    #if 1
                                    rc = aws_iot_shadow_update(&mqttClient, CONFIG_AWS_EXAMPLE_THING_NAME, JsonDocumentBuffer,
                                    deviceUpdateStatusCallback, NULL, 6, true);
                                    #endif

                                    update_step_status = 0;
                                }
                            }
                        }

                        //ESP_LOGI(TAG, "*****************************************************************************************");
                        ESP_LOGI(TAG, "Stack remaining for task '%s' is %d bytes", pcTaskGetTaskName(NULL), uxTaskGetStackHighWaterMark(NULL));
                    }
                }   
                vTaskDelay(1000 / portTICK_RATE_MS);
                break;

            case 2:                   //变化上传状态数据

                break;
            default:
                break;
        }
        #endif

     }  
}

}

`

mahavirj commented 5 years ago

@myzhang001 I am having trouble understanding your problem. Probably you are using thing_shadow example, can you please provide your changes in zip format so that it is easier to understand?

Also need help on some other questions: