int TuyaSDKInterface::init()
{
    TuyaSDKInterface::extractTuyaConfigFromMtd9();//从mtd9分区读取config.json
    lock_guard guard(m_req_lock);; // 加锁，确保线程安全
    if (m_init) 
    {
        PR_DEBUG("TuyaSDK already initialized"); // 如果已经初始化，直接返回
        return 0;
    }
    OPERATE_RET rt = OPRT_OK;
    CHAR_T *cfg_str = NULL;
    ty_cJSON *cfg_json = NULL;
    CHAR_T *storage_path = NULL;
    CHAR_T *pid = NULL;
    TUYA_PLATEFORM_S *cfg = NULL;

#if defined(WIFI_GW) && (WIFI_GW == 1)
    WF_GW_PROD_INFO_S prod_info = {0};
#else
    GW_PROD_INFO_S prod_info = {0};
#endif

    TY_GW_APP_CBS_S gw_app_cbs = {
        .gw_reset_cb = __gw_reset_cb,
        .gw_reboot_cb = __gw_reboot_cb,
        .gw_upgrade_cb = __gw_upgrade_cb,
        .gw_active_stat_cb = __gw_active_stat_cb,
        .gw_log_path_cb = __gw_local_log_cb,
    };
    TY_DP_REPORT_CBS_S gw_dp_report_cbs = {
        .obj_dp_rept_cb = __obj_dp_rept_cb,
        .raw_dp_rept_cb = __raw_dp_rept_cb,
    };

    TUYA_CALL_ERR_RETURN(tuya_load_config(TUYA_CONFIG_INFO_FILE));

    cfg = tuya_get_config();
    PR_DEBUG("        pid: %s", cfg->product_id);
    PR_DEBUG("  cache_dir: %s", cfg->tmp_dir);
    PR_DEBUG("storage_dir: %s", cfg->storage_dir);

    // Initialize IoT Core
    TUYA_CALL_ERR_RETURN(tuya_iot_init(cfg->storage_dir));

    ty_cJSON *log_level = ty_cJSON_GetObjectItem(cfg->input, "log_level");
    if (log_level && log_level->type == ty_cJSON_Number)
    {
        PR_DEBUG("log level: %d", log_level->valueint);
        SetLogManageAttr((TAL_LOG_LEVEL_E)log_level->valueint);
    }

    // Setting UUID and AuthKey
    ty_cJSON *uuid = ty_cJSON_GetObjectItem(cfg->input, "uuid");
    TUYA_CHECK_NULL_RETURN(uuid, OPRT_COM_ERROR);
    ty_cJSON *authkey = ty_cJSON_GetObjectItem(cfg->input, "authkey");
    TUYA_CHECK_NULL_RETURN(authkey, OPRT_COM_ERROR);
    prod_info.uuid = uuid->valuestring;
    prod_info.auth_key = authkey->valuestring;
#if defined(WIFI_GW) && (WIFI_GW == 1)
    TUYA_CALL_ERR_RETURN(tuya_iot_set_wf_gw_prod_info(&prod_info));
#else
    TUYA_CALL_ERR_RETURN(tuya_iot_set_gw_prod_info(&prod_info));
#endif

    tuya_iot_reg_gw_app_cb(&gw_app_cbs);
    tuya_iot_sdk_reg_netstat_cb(__gw_net_stat_cb, __gw_wired_stat_cb, __gw_wifi_stat_cb);
    tuya_iot_reg_dp_report_cb(&gw_dp_report_cbs); //注册上报接口

    // Pre-Initialize Gateway SDK
    tuya_iot_sdk_pre_init(TRUE);

//#if defined(ENABLE_GW_BLUETOOTH) && (ENABLE_GW_BLUETOOTH == 1)
    // Initialize Bluetooth Service
    PR_DEBUG("*******start Initialize Bluetooth Service*******");
    TUYA_CALL_ERR_RETURN(user_blemesh_svc_init());
    PR_DEBUG("*******finish Initialize Bluetooth Service*******");
//#endif

    // Initialize Zigbee Service
    //TUYA_CALL_ERR_RETURN(user_zigbee_custom_init());
    //TUYA_CALL_ERR_RETURN(user_zigbee_svc_init());

    // Initialize Gateway SDK
#if defined(WIFI_GW) && (WIFI_GW == 1)
#if defined(GW_SUPPORT_WIRED_WIFI) && (GW_SUPPORT_WIRED_WIFI == 1)
    TUYA_CALL_ERR_RETURN(tuya_iot_wr_wf_sdk_init(IOT_GW_NET_WIRED_WIFI, GWCM_OLD, WF_START_AP_ONLY, cfg->product_id, USER_SW_VER, NULL, 0));
#else
    TUYA_CALL_ERR_RETURN(tuya_iot_wf_sdk_init(GWCM_OLD, WF_START_AP_ONLY, cfg->product_id, USER_SW_VER, NULL, 0));
#endif
#else
    TUYA_CALL_ERR_RETURN(tuya_iot_sdk_init(cfg->product_id, USER_SW_VER, NULL, 0));
#endif

    // Start Gateway SDK
    TUYA_CALL_ERR_RETURN(tuya_iot_sdk_start());

//#if defined(ENABLE_GW_BLUETOOTH) && (ENABLE_GW_BLUETOOTH == 1)
    // Start Bluetooth Service
    PR_DEBUG("*******Start Bluetooth Service*******");
    TUYA_CALL_ERR_RETURN(user_blemesh_svc_start());
    PR_DEBUG("*******Start Bluetooth Service finish*******");
//#endif

    // Start Zigbee Service
    //TUYA_CALL_ERR_RETURN(user_zigbee_svc_start());

    m_init = true; // 设置初始化标志为 true
    return 0;
}