同步旧版本MQTT的修改内容

This commit is contained in:
helloyifa 2025-10-10 17:43:48 +08:00
parent eef8a88ba4
commit 0c3c767b2a
7 changed files with 68 additions and 50 deletions

1
bk_idk/components/ali_mqtt/mqtt/iot_export_mqtt.h Executable file → Normal file
View File

@ -70,6 +70,7 @@ typedef enum {
/* MQTT packet buffer overflow which the remaining space less than to receive byte */
IOTX_MQTT_EVENT_BUFFER_OVERFLOW = 13,
IOTX_MQTT_EVENT_PING_RESP = 14,
} iotx_mqtt_event_type_t;
/* topic information */

11
bk_idk/components/ali_mqtt/mqtt/mqtt_client.c Executable file → Normal file
View File

@ -1350,6 +1350,17 @@ static int iotx_mc_cycle(iotx_mc_client_t *c, iotx_time_t *timer)
case PINGRESP: {
rc = SUCCESS_RETURN;
log_info("receive ping response!\n");
//iotx_mc_set_client_state(c, IOTX_MQTT_EVENT_PING_RESP);
/* handle callback function */
//helloyifa
if (NULL != c->handle_event.h_fp) {
iotx_mqtt_event_msg_t msg;
msg.event_type = IOTX_MQTT_EVENT_PING_RESP;
msg.msg = NULL;
c->handle_event.h_fp(c->handle_event.pcontext,
c,
&msg);
}
break;
}
default:

1
bk_idk/components/ali_mqtt/mqtt/mqtt_instance.h Executable file → Normal file
View File

@ -4,6 +4,7 @@
enum {
MQTT_INSTANCE_EVENT_DISCONNECTED = 0,
MQTT_INSTANCE_EVENT_CONNECTED = 1,
MQTT_INSTANCE_EVENT_PING_RESP = 2,
};

View File

@ -5,7 +5,7 @@ bootloader,,68k,code,TRUE,FALSE
app,,2584K,code,TRUE,FALSE
app1,,408k,code,TRUE,FALSE
app2,,136k,code,TRUE,FALSE
download,,1792K,data,TRUE,
download,,3196K,data,TRUE,
usr_config,,68K,data,TRUE,
easyflash,,8K,data,TRUE,
rf_firmware,0x3fe000,4k,data,TRUE,

1 # The bin size whose type is code occupies more space in flash
5 app 2584K code TRUE FALSE
6 app1 408k code TRUE FALSE
7 app2 136k code TRUE FALSE
8 download 1792K 3196K data TRUE
9 usr_config 68K data TRUE
10 easyflash 8K data TRUE
11 rf_firmware 0x3fe000 4k data TRUE

4
projects/thirdparty/lock_lfvx/main/include/mqtt_instance.h vendored Executable file → Normal file
View File

@ -43,7 +43,9 @@ void mqtt_remove_instance();
int mqtt_set_instance(void* mqtt_t);
int mqtt_init_instance_poka2(char* host,int port,char *client, char *user, char *password, int maxMsgSize);
/**
*/
int mqtt_update_reconnect_userinfo(char *client, char *user, char *password);
int mqtt_init_instance_poka(char* host,int port,char *client, char *user, char *password, int maxMsgSize);
/**
* @brief Initialize the mqtt singleton instance.

19
projects/thirdparty/lock_lfvx/main/mqtt_instance.c vendored Executable file → Normal file
View File

@ -24,7 +24,8 @@ static void *mqtt_client = NULL;
static void *mqtt_rbuf = NULL;
static void *mqtt_wbuf = NULL;
static iotx_conn_info_pt pconn_info;
static iotx_mqtt_param_t mqtt_params;
static int abort_request = 0;
@ -74,6 +75,10 @@ static void event_handle(void *pcontext, void *pclient, iotx_mqtt_event_msg_pt m
LOGE("MQTT_INSTANCE_EVENT_PING_RESP !!!\n");
event = MQTT_INSTANCE_EVENT_PING_RESP;
break;
case IOTX_MQTT_EVENT_SUBCRIBE_SUCCESS:
//LOGE("IOTX_MQTT_EVENT_SUBCRIBE_SUCCESS !!!\n");
event = MQTT_INSTANCE_EVENT_CONNECTED;
break;
default:
return;
@ -113,8 +118,7 @@ int mqtt_init_instance_poka(char* host,int port,char *client, char *user, char *
// IOT_OpenLog("masterslave");
// IOT_SetLogLevel(IOT_LOG_DEBUG);
iotx_conn_info_pt pconn_info;
iotx_mqtt_param_t mqtt_params;
int ret = IOT_SetupConnInfo(user, user, user, (void **)&pconn_info);
if (ret != SUCCESS_RETURN)
@ -160,6 +164,15 @@ fail:
mqtt_deinit_instance();
return -1;
}
int mqtt_update_reconnect_userinfo(char *client, char *user, char *password){
//if(mqtt_params){
mqtt_params.client_id = client;
mqtt_params.username = user;
mqtt_params.password = password;
//}
return 0;
}
/*
* 1: mqtt instance have been init
* 0: mqtt instance init success

80
projects/thirdparty/lock_lfvx/main/poka_client.c vendored Executable file → Normal file
View File

@ -85,7 +85,9 @@ static char iot_message_id [64] = {0};
static poka_client_cb_ops_t *event_cb;
static beken_timer_t timer_reboot_handle;
static beken_timer_t timer_update_auth_handle;
static int mqtt_is_connected = 0;
char * poka_client_get_device_id(){
return ilock_device_id;
@ -93,7 +95,9 @@ char * poka_client_get_device_id(){
char * poka_client_get_message_id(){
return iot_message_id;
}
int poka_client_is_connected(){
return mqtt_is_connected;
}
/**
*
*
@ -497,7 +501,7 @@ void mqtt_subscribe_invoke_callback(char *topic, int topic_len, void *payload, i
if (event_cb != NULL){
event_cb->event_cloud();
//复位定时器
rtos_reload_timer(&timer_reboot_handle);
//rtos_reload_timer(&timer_update_auth_handle);
}
@ -943,16 +947,8 @@ void mqtt_update_connectinfo(){
poka_client_gen_password(mqtt_password,sizeof(mqtt_password),SECUREID, SECUREKEY,timestamp);
BK_LOGE(TAG,"\r\nupdate mqtt_password: %s\n", mqtt_username);
iotx_mqtt_param_t mqtt_params;
/* Initialize MQTT parameter */
memset(&mqtt_params, 0x0, sizeof(mqtt_params));
mqtt_params.client_id = ilock_device_id;
mqtt_params.username = mqtt_username;
mqtt_params.password = mqtt_password;
mqtt_update_reconnect_userinfo(ilock_device_id, mqtt_username, mqtt_password);
//IOT_MQTT_Update_mqtt_param(mqtt_get_instance(),&mqtt_params);
}
@ -960,45 +956,38 @@ void mqtt_update_connectinfo(){
void mqtt_event_callback(int event, void *ctx){
//BK_LOGE(TAG,"mqtt_event_callback event:%d\n",event);
if(event == MQTT_INSTANCE_EVENT_DISCONNECTED){
BK_LOGE(TAG,"mqtt disconnect! \n");
//mqtt_update_connectinfo();
//poka_client_unsubscribe_topic(PRODUCTID,ilock_device_id);
//mqtt_deinit_instance();
//poka_client_init();
if(ble_boarding_get_state() == BOARDING_STATE_SCAN || ble_boarding_get_state() == BOARDING_STATE_SETWIFI){
}else{
//BK_LOGE(TAG,"MQTT ERROR REBOOT! \n");
//bk_reboot();
}
BK_LOGE(TAG,"mqtt disconnect! \n");
mqtt_is_connected = 0;
}
else if(event == MQTT_INSTANCE_EVENT_CONNECTED){
BK_LOGE(TAG,"mqtt connected!\n");
if (event_cb != NULL)
//BK_LOGE(TAG,"mqtt connected!\n");
mqtt_is_connected = 1;
if (event_cb != NULL && event_cb->event_link_state!= NULL)
event_cb->event_link_state(event);
}
else if(event == MQTT_INSTANCE_EVENT_PING_RESP){
BK_LOGE(TAG,"mqtt recv ping respone\n");
//复位定时器
rtos_reload_timer(&timer_reboot_handle);
}
rtos_reload_timer(&timer_update_auth_handle);
}
}
void poka_client_set_callback(poka_client_cb_ops_t *cb_ops){
event_cb = cb_ops;
}
static void reboot_timer_handle( void *arg )
static void timer_update_auth_info_callback( void *arg )
{
BK_LOGE(TAG,"mqtt recv ping respone timeout--> REBOOT! \n");
bk_reboot();
//BK_LOGE(TAG,"mqtt recv ping respone timeout--> RECONNECT! \n");
//bk_reboot();
//poka_client_reconnect();
mqtt_update_connectinfo();
rtos_reload_timer(&timer_update_auth_handle);
}
void poka_stop_reboot_timer()
{
rtos_stop_timer(&timer_reboot_handle);
rtos_stop_timer(&timer_update_auth_handle);
}
void poka_client_init(void){
@ -1017,7 +1006,7 @@ void poka_client_init(void){
BK_LOGE(TAG,"\r\nmqtt_username: %s\n", mqtt_username);
poka_client_gen_password(mqtt_password,sizeof(mqtt_password),SECUREID, SECUREKEY,timestamp);
BK_LOGE(TAG,"\r\nmqtt_password: %s\n", mqtt_username);
BK_LOGE(TAG,"\r\nmqtt_password: %s\n", mqtt_password);
mqtt_set_event_cb(&mqtt_event_callback, NULL);
mqtt_init_instance_poka(TMQTT_SERVER,TMQTT_PORT,ilock_device_id, mqtt_username, mqtt_password, 1024*4);
@ -1025,19 +1014,20 @@ void poka_client_init(void){
// "YCx4b0m6Uv", "version=2018-10-31&res=products%2FYCx4b0m6Uv%2Fdevices%2F867698041071583&et=1745719251&method=sha1&sign=Qd56NvGRqQDtxUTciKKE9J%2BZvZY%3D", 1024*4);
poka_client_subscribe_topic(PRODUCTID,ilock_device_id);
//启动网络检测定时器,如果两分钟 没有收到PING 回应自动重启
rtos_init_timer(&timer_reboot_handle, ILOCK_MQTT_PINGPONG_TIMEOUT*1000, reboot_timer_handle, 0);
rtos_start_timer(&timer_reboot_handle);
}
void poka_client_reconnect(){
//poka_client_unsubscribe_topic(PRODUCTID,ilock_device_id);
mqtt_deinit_instance();
poka_client_init();
//定时计算用户名和密码 用于断线时自动重连 账户密码和时间戳相关 超过5分钟原有的账号密码已经失效
rtos_init_timer(&timer_update_auth_handle, 60*1000, timer_update_auth_info_callback, 0);
rtos_start_timer(&timer_update_auth_handle);
}
void poka_client_deinit(void){
if (rtos_is_timer_init(&timer_update_auth_handle)) {
if (rtos_is_timer_running(&timer_update_auth_handle))
{
rtos_stop_timer(&timer_update_auth_handle);
}
rtos_deinit_timer(&timer_update_auth_handle);
}
mqtt_deinit_instance();
}