diff --git a/components/network/libemqtt/luat_lib_mqtt.c b/components/network/libemqtt/luat_lib_mqtt.c index 53f13548..e3e2e9a8 100644 --- a/components/network/libemqtt/luat_lib_mqtt.c +++ b/components/network/libemqtt/luat_lib_mqtt.c @@ -65,6 +65,23 @@ int32_t luatos_mqtt_callback(lua_State *L, void* ptr){ luat_mqtt_ping(mqtt_ctrl); break; } + case MQTT_MSG_PINGRESP : { + if (mqtt_ctrl->mqtt_cb) { + lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_cb); + if (lua_isfunction(L, -1)) { + lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_ref); + lua_pushstring(L, "pong"); + lua_call(L, 2, 0); + } + lua_getglobal(L, "sys_pub"); + if (lua_isfunction(L, -1)) { + lua_pushstring(L, "MQTT_PONG"); + lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_ref); + lua_call(L, 2, 0); + } + } + break; + } case MQTT_MSG_RECONNECT : { luat_mqtt_reconnect(mqtt_ctrl); break; diff --git a/components/network/libemqtt/luat_mqtt_client.c b/components/network/libemqtt/luat_mqtt_client.c index 0eb09dfd..d101904b 100644 --- a/components/network/libemqtt/luat_mqtt_client.c +++ b/components/network/libemqtt/luat_mqtt_client.c @@ -381,6 +381,8 @@ static int luat_mqtt_msg_cb(luat_mqtt_ctrl_t *mqtt_ctrl) { } case MQTT_MSG_PINGRESP : { LLOGD("MQTT_MSG_PINGRESP"); + msg_id = mqtt_parse_msg_id(mqtt_ctrl->mqtt_packet_buffer); + l_luat_mqtt_msg_cb(mqtt_ctrl, MQTT_MSG_PINGRESP, msg_id); break; } case MQTT_MSG_DISCONNECT : {