Comments (5)
程序流程
1.rc = aws_iot_shadow_init(&mqttClient, &sp);
2. rc = aws_iot_shadow_connect(&mqttClient, &scp);
3. 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
from esp-aws-iot.
@myzhang001 Could you please help to share entire application/test code with sdkconfig
?
from esp-aws-iot.
`/*
this is sdkconfig
*
- Automatically generated file; DO NOT EDIT.
- Espressif IoT Development Framework Configuration
*/
#define CONFIG_ESP32_PHY_MAX_TX_POWER 20
#define CONFIG_TRACEMEM_RESERVE_DRAM 0x0
#define CONFIG_FREERTOS_MAX_TASK_NAME_LEN 16
#define CONFIG_MQTT_TRANSPORT_SSL 1
#define CONFIG_MB_SERIAL_TASK_PRIO 10
#define CONFIG_MQTT_PROTOCOL_311 1
#define CONFIG_TCP_RECVMBOX_SIZE 6
#define CONFIG_FATFS_CODEPAGE_437 1
#define CONFIG_AWS_IOT_SHADOW_MAX_SIMULTANEOUS_ACKS 15
#define CONFIG_TCP_WND_DEFAULT 5744
#define CONFIG_PARTITION_TABLE_OFFSET 0x8000
#define CONFIG_SPIFFS_USE_MAGIC_LENGTH 1
#define CONFIG_ESPTOOLPY_FLASHSIZE_4MB 1
#define CONFIG_IPC_TASK_STACK_SIZE 1024
#define CONFIG_FATFS_PER_FILE_CACHE 1
#define CONFIG_ESPTOOLPY_FLASHFREQ "80m"
#define CONFIG_AWS_IOT_SHADOW_MAX_SIZE_OF_THING_NAME 30
#define CONFIG_MBEDTLS_KEY_EXCHANGE_RSA 1
#define CONFIG_UDP_RECVMBOX_SIZE 6
#define CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE 0
#define CONFIG_MBEDTLS_AES_C 1
#define CONFIG_MBEDTLS_ECP_DP_SECP521R1_ENABLED 1
#define CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN 752
#define CONFIG_MBEDTLS_GCM_C 1
#define CONFIG_ESPTOOLPY_FLASHSIZE "4MB"
#define CONFIG_HEAP_POISONING_DISABLED 1
#define CONFIG_SPIFFS_CACHE_WR 1
#define CONFIG_BROWNOUT_DET_LVL_SEL_0 1
#define CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER 1
#define CONFIG_EMAC_L2_TO_L3_RX_BUF_MODE 1
#define CONFIG_SPIFFS_CACHE 1
#define CONFIG_INT_WDT 1
#define CONFIG_MBEDTLS_SSL_PROTO_TLS1 1
#define CONFIG_ESP_GRATUITOUS_ARP 1
#define CONFIG_AWS_IOT_SHADOW_MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES 80
#define CONFIG_MBEDTLS_ECDSA_C 1
#define CONFIG_LOG_BOOTLOADER_LEVEL_INFO 1
#define CONFIG_HTTPD_MAX_REQ_HDR_LEN 512
#define CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE 0
#define CONFIG_AWS_IOT_MQTT_PORT 8883
#define CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS 1
#define CONFIG_MBEDTLS_ECDH_C 1
#define CONFIG_MBEDTLS_KEY_EXCHANGE_ELLIPTIC_CURVE 1
#define CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM 10
#define CONFIG_AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000
#define CONFIG_MBEDTLS_SSL_ALPN 1
#define CONFIG_MBEDTLS_PEM_WRITE_C 1
#define CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN 4096
#define CONFIG_LOG_DEFAULT_LEVEL_INFO 1
#define CONFIG_BT_RESERVE_DRAM 0x0
#define CONFIG_APP_COMPILE_TIME_DATE 1
#define CONFIG_FATFS_FS_LOCK 0
#define CONFIG_IP_LOST_TIMER_INTERVAL 120
#define CONFIG_SPIFFS_META_LENGTH 4
#define CONFIG_ESP32_PANIC_PRINT_REBOOT 1
#define CONFIG_MB_CONTROLLER_NOTIFY_QUEUE_SIZE 20
#define CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED 1
#define CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED 1
#define CONFIG_AWS_IOT_MQTT_RX_BUF_LEN 2048
#define CONFIG_MB_SERIAL_BUF_SIZE 256
#define CONFIG_CONSOLE_UART_BAUDRATE 115200
#define CONFIG_LWIP_MAX_SOCKETS 10
#define CONFIG_LWIP_NETIF_LOOPBACK 1
#define CONFIG_ESP32_PTHREAD_TASK_NAME_DEFAULT "pthread"
#define CONFIG_EMAC_TASK_PRIORITY 20
#define CONFIG_TIMER_TASK_STACK_DEPTH 2048
#define CONFIG_TCP_MSS 1436
#define CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED 1
#define CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN_EFF 0
#define CONFIG_FATFS_CODEPAGE 437
#define CONFIG_ESP32_DEFAULT_CPU_FREQ_160 1
#define CONFIG_ULP_COPROC_RESERVE_MEM 0
#define CONFIG_LWIP_MAX_UDP_PCBS 16
#define CONFIG_ESPTOOLPY_BAUD 115200
#define CONFIG_INT_WDT_CHECK_CPU1 1
#define CONFIG_ADC_CAL_LUT_ENABLE 1
#define CONFIG_AWS_IOT_MQTT_TX_BUF_LEN 2048
#define CONFIG_FLASHMODE_DIO 1
#define CONFIG_ESPTOOLPY_AFTER_RESET 1
#define CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED 1
#define CONFIG_LWIP_DHCPS_MAX_STATION_NUM 8
#define CONFIG_TOOLPREFIX "xtensa-esp32-elf-"
#define CONFIG_MBEDTLS_ECP_C 1
#define CONFIG_FREERTOS_IDLE_TASK_STACKSIZE 1536
#define CONFIG_MBEDTLS_RC4_DISABLED 1
#define CONFIG_CONSOLE_UART_NUM 0
#define CONFIG_AWS_IOT_SHADOW_MAX_JSON_TOKEN_EXPECTED 120
#define CONFIG_ESP32_APPTRACE_LOCK_ENABLE 1
#define CONFIG_PTHREAD_STACK_MIN 768
#define CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC 1
#define CONFIG_ESPTOOLPY_BAUD_115200B 1
#define CONFIG_TCP_OVERSIZE_MSS 1
#define CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS 1
#define CONFIG_CONSOLE_UART_DEFAULT 1
#define CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS 4
#define CONFIG_ESPTOOLPY_FLASHSIZE_DETECT 1
#define CONFIG_EXAMPLE_EMBEDDED_CERTS 1
#define CONFIG_TIMER_TASK_STACK_SIZE 3584
#define CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE 1
#define CONFIG_MBEDTLS_X509_CRL_PARSE_C 1
#define CONFIG_AWS_IOT_SHADOW_MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME 200
#define CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER 1
#define CONFIG_MB_SERIAL_TASK_STACK_SIZE 2048
#define CONFIG_LWIP_DHCPS_LEASE_UNIT 60
#define CONFIG_SPIFFS_USE_MAGIC 1
#define CONFIG_TCPIP_TASK_STACK_SIZE 3072
#define CONFIG_TASK_WDT 1
#define CONFIG_MAIN_TASK_STACK_SIZE 3584
#define CONFIG_SPIFFS_PAGE_CHECK 1
#define CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0 1
#define CONFIG_LWIP_MAX_ACTIVE_TCP 16
#define CONFIG_TASK_WDT_TIMEOUT_S 5
#define CONFIG_INT_WDT_TIMEOUT_MS 300
#define CONFIG_ESPTOOLPY_FLASHMODE "dio"
#define CONFIG_NEWLIB_STDIN_LINE_ENDING_CR 1
#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA 1
#define CONFIG_ESPTOOLPY_BEFORE "default_reset"
#define CONFIG_ADC2_DISABLE_DAC 1
#define CONFIG_FATFS_LFN_HEAP 1
#define CONFIG_LOG_DEFAULT_LEVEL 3
#define CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION 1
#define CONFIG_TIMER_QUEUE_LENGTH 10
#define CONFIG_SUPPRESS_SELECT_DEBUG_OUTPUT 1
#define CONFIG_TCPIP_TASK_AFFINITY_NO_AFFINITY 1
#define CONFIG_MAKE_WARN_UNDEFINED_VARIABLES 1
#define CONFIG_FATFS_TIMEOUT_MS 10000
#define CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM 32
#define CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS 1
#define CONFIG_MBEDTLS_CCM_C 1
#define CONFIG_SPI_MASTER_ISR_IN_IRAM 1
#define CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER 20
#define CONFIG_ESP32_RTC_CLK_CAL_CYCLES 1024
#define CONFIG_AWS_IOT_SHADOW_MAX_SIZE_OF_RX_BUFFER 2048
#define CONFIG_ESP32_WIFI_TX_BA_WIN 6
#define CONFIG_ESP32_WIFI_NVS_ENABLED 1
#define CONFIG_MDNS_MAX_SERVICES 10
#define CONFIG_IDF_TARGET_ESP32 1
#define CONFIG_EMAC_CHECK_LINK_PERIOD_MS 2000
#define CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED 1
#define CONFIG_LIBSODIUM_USE_MBEDTLS_SHA 1
#define CONFIG_AWS_IOT_SDK 1
#define CONFIG_DMA_RX_BUF_NUM 10
#define CONFIG_MBEDTLS_ECP_DP_SECP384R1_ENABLED 1
#define CONFIG_AWS_IOT_OVERRIDE_THING_SHADOW_RX_BUFFER 1
#define CONFIG_TCP_SYNMAXRTX 6
#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA 1
#define CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN_EFF 0
#define CONFIG_PYTHON "python"
#define CONFIG_MBEDTLS_ECP_NIST_OPTIM 1
#define CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1 1
#define CONFIG_ESPTOOLPY_COMPRESSED 1
#define CONFIG_PARTITION_TABLE_FILENAME "partitions_singleapp.csv"
#define CONFIG_MB_CONTROLLER_STACK_SIZE 4096
#define CONFIG_TCP_SND_BUF_DEFAULT 5744
#define CONFIG_GARP_TMR_INTERVAL 60
#define CONFIG_LWIP_DHCP_MAX_NTP_SERVERS 1
#define CONFIG_TCP_MSL 60000
#define CONFIG_MBEDTLS_SSL_PROTO_TLS1_1 1
#define CONFIG_LWIP_SO_REUSE_RXTOALL 1
#define CONFIG_MB_CONTROLLER_NOTIFY_TIMEOUT 20
#define CONFIG_WIFI_SSID "TP-LINK_461306"
#define CONFIG_PARTITION_TABLE_SINGLE_APP 1
#define CONFIG_UNITY_ENABLE_FLOAT 1
#define CONFIG_ESP32_WIFI_RX_BA_WIN 6
#define CONFIG_MBEDTLS_X509_CSR_PARSE_C 1
#define CONFIG_SPIFFS_USE_MTIME 1
#define CONFIG_EMAC_TASK_STACK_SIZE 3072
#define CONFIG_MB_QUEUE_LENGTH 20
#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA 1
#define CONFIG_LWIP_DHCP_DOES_ARP_CHECK 1
#define CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER 1
#define CONFIG_ESPTOOLPY_FLASHFREQ_80M 1
#define CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE 2304
#define CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V 1
#define CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY 2000
#define CONFIG_AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 10
#define CONFIG_BROWNOUT_DET_LVL 0
#define CONFIG_MBEDTLS_PEM_PARSE_C 1
#define CONFIG_SPIFFS_GC_MAX_RUNS 10
#define CONFIG_ESP32_APPTRACE_DEST_NONE 1
#define CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC 1
#define CONFIG_MBEDTLS_SSL_PROTO_TLS1_2 1
#define CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA 1
#define CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM 32
#define CONFIG_HTTPD_MAX_URI_LEN 512
#define CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED 1
#define CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED 1
#define CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1 1
#define CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ 160
#define CONFIG_MBEDTLS_HARDWARE_AES 1
#define CONFIG_FREERTOS_HZ 100
#define CONFIG_LOG_COLORS 1
#define CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE 1
#define CONFIG_STACK_CHECK_NONE 1
#define CONFIG_ADC_CAL_EFUSE_TP_ENABLE 1
#define CONFIG_FREERTOS_ASSERT_FAIL_ABORT 1
#define CONFIG_BROWNOUT_DET 1
#define CONFIG_AWS_IOT_SHADOW_MAX_SIMULTANEOUS_THINGNAMES 15
#define CONFIG_ESP32_XTAL_FREQ 40
#define CONFIG_MONITOR_BAUD_115200B 1
#define CONFIG_LOG_BOOTLOADER_LEVEL 3
#define CONFIG_MBEDTLS_TLS_ENABLED 1
#define CONFIG_LWIP_MAX_RAW_PCBS 16
#define CONFIG_MBEDTLS_SSL_SESSION_TICKETS 1
#define CONFIG_SPIFFS_MAX_PARTITIONS 3
#define CONFIG_ESP_ERR_TO_NAME_LOOKUP 1
#define CONFIG_MBEDTLS_SSL_RENEGOTIATION 1
#define CONFIG_ESPTOOLPY_BEFORE_RESET 1
#define CONFIG_MB_EVENT_QUEUE_TIMEOUT 20
#define CONFIG_ESPTOOLPY_BAUD_OTHER_VAL 115200
#define CONFIG_AWS_EXAMPLE_CLIENT_ID "PN777777777777777"
#define CONFIG_SPIFFS_OBJ_NAME_LEN 32
#define CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT 5
#define CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_ACL_CONN_EFF 0
#define CONFIG_PARTITION_TABLE_MD5 1
#define CONFIG_TCPIP_RECVMBOX_SIZE 32
#define CONFIG_TCP_MAXRTX 12
#define CONFIG_ESPTOOLPY_AFTER "hard_reset"
#define CONFIG_TCPIP_TASK_AFFINITY 0x7FFFFFFF
#define CONFIG_LWIP_SO_REUSE 1
#define CONFIG_ESP32_XTAL_FREQ_40 1
#define CONFIG_DMA_TX_BUF_NUM 10
#define CONFIG_LWIP_MAX_LISTENING_TCP 16
#define CONFIG_FREERTOS_INTERRUPT_BACKTRACE 1
#define CONFIG_WL_SECTOR_SIZE 4096
#define CONFIG_ESP32_DEBUG_OCDAWARE 1
#define CONFIG_MQTT_TRANSPORT_WEBSOCKET 1
#define CONFIG_TIMER_TASK_PRIORITY 1
#define CONFIG_MBEDTLS_TLS_CLIENT 1
#define CONFIG_AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000
#define CONFIG_ESP32_DEFAULT_PTHREAD_CORE_NO_AFFINITY 1
#define CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED 1
#define CONFIG_MONITOR_BAUD 115200
#define CONFIG_ESP32_PTHREAD_TASK_CORE_DEFAULT -1
#define CONFIG_ESP32_DEBUG_STUBS_ENABLE 1
#define CONFIG_TCPIP_LWIP 1
#define CONFIG_REDUCE_PHY_TX_POWER 1
#define CONFIG_BOOTLOADER_WDT_TIME_MS 9000
#define CONFIG_FREERTOS_CORETIMER_0 1
#define CONFIG_PARTITION_TABLE_CUSTOM_FILENAME "partitions.csv"
#define CONFIG_MBEDTLS_HAVE_TIME 1
#define CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY 1
#define CONFIG_TCP_QUEUE_OOSEQ 1
#define CONFIG_ADC_CAL_EFUSE_VREF_ENABLE 1
#define CONFIG_MBEDTLS_TLS_SERVER 1
#define CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT 1
#define CONFIG_FREERTOS_ISR_STACKSIZE 1536
#define CONFIG_SUPPORT_TERMIOS 1
#define CONFIG_OPENSSL_ASSERT_DO_NOTHING 1
#define CONFIG_IDF_TARGET "esp32"
#define CONFIG_WL_SECTOR_SIZE_4096 1
#define CONFIG_OPTIMIZATION_LEVEL_DEBUG 1
#define CONFIG_FREERTOS_NO_AFFINITY 0x7FFFFFFF
#define CONFIG_AWS_IOT_MQTT_HOST "abfq55dszm6fm-ats.iot.us-west-2.amazonaws.com"
#define CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED 1
#define CONFIG_MB_TIMER_INDEX 0
#define CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED 1
#define CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED 1
#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA 1
#define CONFIG_SPI_SLAVE_ISR_IN_IRAM 1
#define CONFIG_WIFI_PASSWORD "12345678"
#define CONFIG_SYSTEM_EVENT_QUEUE_SIZE 32
#define CONFIG_FATFS_MAX_LFN 255
#define CONFIG_ESP32_WIFI_TX_BUFFER_TYPE 1
#define CONFIG_BOOTLOADER_WDT_ENABLE 1
#define CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED 1
#define CONFIG_LWIP_LOOPBACK_MAX_PBUFS 8
#define CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN 16384
#define CONFIG_MB_TIMER_GROUP 0
#define CONFIG_SPI_FLASH_ROM_DRIVER_PATCH 1
#define CONFIG_MQTT_TRANSPORT_WEBSOCKET_SECURE 1
#define CONFIG_SPIFFS_PAGE_SIZE 256
#define CONFIG_MBEDTLS_ECP_DP_SECP192K1_ENABLED 1
#define CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0 1
#define CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT 3072
#define CONFIG_MB_TIMER_PORT_ENABLED 1
#define CONFIG_MONITOR_BAUD_OTHER_VAL 115200
#define CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF 1
#define CONFIG_ESPTOOLPY_PORT "/dev/ttyUSB0"
#define CONFIG_UNITY_ENABLE_DOUBLE 1
#define CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN 1
#define CONFIG_AWS_EXAMPLE_THING_NAME "PN777777777777777"
#define CONFIG_FATFS_API_ENCODING_ANSI_OEM 1
`
from esp-aws-iot.
`#include "user_aws_handle.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include <limits.h>
#include <string.h>
#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"
/*!
- The goal of this sample application is to demonstrate the capabilities of shadow.
- This device(say Connected Window) will open the window of a room based on temperature
- It can report to the Shadow the following parameters:
-
- temperature of the room (double)
-
- status of the window (open or close)
- It can act on commands from the cloud. In this case it will open or close the window based on the json object "windowOpen" data[open/close]
- The two variables from a device's perspective are double temperature and bool windowOpen
- The device needs to act on only on windowOpen variable, so we will create a primitiveJson_t object with callback
The Json Document in the cloud will be
{
"reported": {
"temperature": 0,
"windowOpen": false
},
"desired": {
"windowOpen": false
}
}
*/
#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
-
("Thing") key.
Example can be configured one of two ways:
"Embedded Certs" are loaded from files in "certs/" and embedded into the app binary.
"Filesystem Certs" are loaded from the filesystem (SD card, etc.)
See example README for more details.
*/
#if defined(CONFIG_EXAMPLE_EMBEDDED_CERTS)
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
}
}
}
`
from esp-aws-iot.
@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:
- Is problem reproducible with default
thing_shadow
example in IDF? - Which IDF version you are using?
from esp-aws-iot.
Related Issues (20)
- The configured path is incorrect,what should I do (CA-322)
- When the ssl_mutual_auth routine is frequently connected: Dynamic Impl: alloc(5347 bytes) failed HOT 1
- Dumped packet issue coreMQTT library (CA-324)
- `ota_mqtt` example not working for esp32-wroom-32d (DevKitC v4) (CA-325) HOT 1
- cbor not present in ESP-IDF >4.4 (CA-326) HOT 2
- Connection with MQTT broker failed (CA-327) HOT 4
- coreMQTT: Argument cannot be NULL: pContext=0x3ffc3dd8, pSubscriptionList=0x0 AND coreMQTT: MQTT operation failed with status MQTTBadParameter (CA-328) HOT 1
- New Releases (CA-330) HOT 1
- Fleet Provisioning build error (CA-331) HOT 5
- Any esp-aws-iot release supporting or usable with IDF v5.2.1 ? (CA-332) HOT 11
- Customize software to do OTA with cellular modem (CA-333)
- MQTT_ProcessLoop() producing 1 s Pings even with 40s KeepAlive time. (CA-334) HOT 4
- Enabling esp secure cert cause firmware unable to compile (CA-335) HOT 1
- AWS-OTA not sure about what comes in Code signing signiture field (CA-336) HOT 1
- smartDeviceConnectionDisconnectionEvent : "disconnectReason": "DUPLICATE_CLIENTID", (CA-337) HOT 4
- Ported Mqtt demo mqtt_demo_mutual_auth,but stuck at sendPacket when run MQTT_Connect (CA-338)
- AWS recovers from read error 0x004C once but not a second time (IDFGH-13081) (CA-339)
- AWS does not recover from disconnect (IDFGH-13132) (CA-340)
- MQTT TLS MUTUAL AUTHENTICATION from example project Having Issues ! (CA-341) HOT 2
- migration guide from IDF 4 to IDF 5 for esp-aws-iot (CA-342)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esp-aws-iot.