Page 1 of 1

获取配网状态以及联网状态

Posted: 2024年 Aug 22日 10:47
by tianchou

开发过程中可能会需要对配网状态进行实时获取,配网状态可通过以下接口获取:
进入配网:
先注册wifi网络状态回调

VOID wifi_network_state_cb(CONST GW_WIFI_NW_STAT_E net_state)
{
}
tuya_iot_reg_get_wf_nw_stat_cb(
wifi_network_state_cb);
通过回调获取网络状态值,状态值定义如下:
typedef BYTE_T GW_WIFI_NW_STAT_E;
#define STAT_LOW_POWER 0 // idle status,use to external config network
#define STAT_UNPROVISION 1 // smart config status
#define STAT_AP_STA_UNCFG 2 // ap WIFI config status
#define STAT_AP_STA_DISC 3 // ap WIFI already config,station disconnect
#define STAT_AP_STA_CONN 4 // ap station mode,station connect
#define STAT_STA_DISC 5 // only station mode,disconnect
#define STAT_STA_CONN 6 // station mode connect
#define STAT_CLOUD_CONN 7 // cloud connect
#define STAT_AP_CLOUD_CONN 8 // cloud connect and ap start
#define STAT_REG_FAIL 9 // register fail
#define STAT_OFFLINE 10 // offline
#define STAT_MQTT_ONLINE 11
#define STAT_MQTT_OFFLINE 12
#define STAT_UNPROVISION_AP_STA_UNCFG 13 //smart-cfg and ap-cfg concurrent config status
#define STAT_PROXY_ACTIVED 14
其中进入配网状态为:1、2、3、4、13

配网中:
同样是上述状态5为配网中

配网结果:
订阅系统配网error事件,通过事件获取配网结果

#define EVENT_NETCFG_ERROR "netcfg.error"
STATIC INT_T netcfg_cb(VOID *data)
{
PR_NOTICE("receive netcfg event! data:%d",data);
return 0;
}
ty_subscribe_event(EVENT_NETCFG_ERROR, "gfw", netcfg_error_cb, 0);
获取配网结果值定义如下
typedef int AP_CFG_ERR_CODE;
#define AP_CFG_SUCC 0
#define AP_CFG_ERR_PCK 1
#define AP_CFG_AP_NOT_FOUND 2
#define AP_CFG_ERR_PASSWD 3
#define AP_CFG_CANT_CONN_AP 4
#define AP_CFG_DHCP_FAILED 5
#define AP_CFG_CONN_CLOUD_FAILED 6
#define AP_CFG_GET_URL_FAILED 7
#define AP_CFG_GW_ACTIVE_FAILED 8
#define AP_CFG_GW_ACTIVE_SUCCESS 9

wifi网络状态:
直接通过网络状态回调获取,其中5为STA模式未连上路由器,6为连上路由器未连上云端,7为已连上云端