#ifndef MQTT_H #define MQTT_H #include #include #include #include "nvs_flash.h" #include "esp_netif.h" #include "protocol_examples_common.h" #include "mqtt_client.h" #include "cjson.h" #include "esp_timer.h" #define DEVICE_FIRMWARE_VERSION "v1.0.3"//原为V1.0.0 void handle_received_data(const char* topic, int topic_len, const char* data, int data_len); void handle_event(const char* data, int data_len); void report_firmware_version(char* event_time); void handle_ota_command(const char* data); void ota_timeout_handler(void *arg); void setup_ota_timeout_timer(void); void clear_ota_timeout_timer(void); static esp_mqtt_client_handle_t esp_mqtt_client_get_handle(void); static void handle_version_query_manual(const char* data, int data_len); static void find_field_manually(cJSON *root, const char* field_name); static void print_json_structure_recursive(cJSON *item, int depth); void mqtt_main(void); /** 停止并销毁 MQTT 客户端,释放 TLS/TCP 任务与缓冲;下次 mqtt_main() 会重新创建 */ void mqtt_client_shutdown(void); esp_err_t subscribe_ota(); static cJSON* create_data(char* service_id, char* event_type); esp_err_t publish_json_download(char* filename); bool Get_MQTT_FLAG(void); extern bool mqtt_connected; static char current_request_id[64] = {0}; static esp_timer_handle_t ota_timeout_timer; static bool ota_command_received = false; static esp_mqtt_client_handle_t client = NULL; static esp_mqtt_client_handle_t client_http = NULL; static char time_event[64] = {0}; extern char object_device_id[70]; static char version[64] = {0}; extern char custom_info[32]; void trigger_ota_upgrade(char* url); void check_ota_progress(void); void transmit_ota_success(void); #define ota_upgrade 1 #define ota_flash_upgrade 2 static int ota_type = 0; void get_object_device_id(char *product_id); #endif // MQTT_H