Re: 【求助】【TuyaOS SDK】tuya mqtt上线后,程序执行段错误的问题
Posted: 2024年 Jan 16日 15:30
(1)扫码
int ret = tuya_ipc_direct_connect(pDataBuf, TUYA_IPC_DIRECT_CONNECT_QRCODE);
(2)tkl_wifi建立sta
Code: Select all
OPERATE_RET tkl_wifi_station_connect(CONST SCHAR_T *ssid, CONST SCHAR_T *passwd)
{
CHECK_RTNP(!ssid || !passwd, OPRT_INVALID_PARM, "%s => input error!!!\n", __FUNCTION__);
WF_STATION_STAT_E cur_WifiStaState = (WF_STATION_STAT_E)tuya_wifi_get_StationState();
if(WSS_IDLE != cur_WifiStaState && WSS_PASSWD_WRONG != cur_WifiStaState &&
WSS_NO_AP_FOUND != cur_WifiStaState && WSS_CONN_FAIL != cur_WifiStaState)
{
DBG("%s => wpa is running, do nothing!!! cur_WifiStaState: %d\n", __FUNCTION__, cur_WifiStaState);
return OPRT_OK;
}
if(strcmp((char*)ssid, g_app_config.wlan_ssid) || (strcmp((char*)passwd, g_app_config.wlan_key)) )
{
strncpy(g_app_config.wlan_ssid, (char*)ssid, WIFI_SSID_LEN);
strncpy(g_app_config.wlan_key, (char*)passwd, WIFI_PASSWD_LEN);
save_app_config();
}
DBG("%s => ssid:%s, passwd:%s\n", __FUNCTION__, (char*)ssid, (char*)passwd);
EasyCamMsgInfo msg = {0};
msg.cmdId = NET_TASK_MSG_ID_CONNECT_TO_AP;
post_net_task_msg( &msg );
tuya_wifi_set_sta_conn_flag(1);
return OPRT_OK;
}
(3) 连接过程中上报状态
Code: Select all
WF_EVENT_E wf_event = WFE_CONNECTED;
if(state == WSS_CONN_FAIL)
{
wf_event = WFE_CONNECT_FAILED;
}
else if(state == WSS_GOT_IP || state == WSS_CONN_SUCCESS)
{
wf_event = WFE_CONNECTED;
}
else
{
wf_event = WFE_DISCONNECTED;
}
if(tuya_sdk_wifi_status_cb) tuya_sdk_wifi_status_cb(wf_event, NULL);
(4)sdk状态回调
Code: Select all
VOID tuya_ipc_status_changed_cb(IN TUYA_IPC_STATUS_GROUP_E changed_group, IN CONST TUYA_IPC_STATUS_E status[TUYA_IPC_STATUS_GROUP_MAX])
{
TUYA_IPC_STATUS_E cur_status = status[changed_group];
INT_T i = 0;
DBG("status chaged: group[%d] status[%d]\n", changed_group, cur_status);
if(0 == access("/mnt/mtd/config/zw_mqtt_debug.flag", 0))
{
if(TUYA_IPC_STATUS_ONLINE == cur_status)
{
DBG("------mqtt online------\n");
sleep(10);
DBG("------mqtt online cb out------\n");
}
}
return ;
}