> 文档中心 > HLK-W801wifi连接

HLK-W801wifi连接

废话不多说直接上代码,有什么问题直接问我或评论。

#include "wm_include.h"#include "wm_wifi_oneshot.h"const char ssid[] = "SSID";const char pwd[] = "PASSWORD";static void con_net_status_changed_event(u8 status ){    switch(status)    {    case NETIF_WIFI_JOIN_SUCCESS: printf("WIFI网络连接成功\n"); break;    case NETIF_WIFI_JOIN_FAILED: printf("WIFI网络连接失败\n"); break;    case NETIF_WIFI_DISCONNECTED: printf("WIFI网络已断开连接\n"); break;    case NETIF_IP_NET_UP:    { struct tls_ethif *tmpethif = tls_netif_get_ethif(); print_ipaddr(&tmpethif->ip_addr);//如果有IPV6,在demo/wm_demo.h里面打开TLS_CONFIG_IPV6#if TLS_CONFIG_IPV6 print_ipaddr(&tmpethif->ip6_addr[0]); print_ipaddr(&tmpethif->ip6_addr[1]); print_ipaddr(&tmpethif->ip6_addr[2]);#endif    }    break;    default: //printf("UNKONWN STATE:%d\n", status); break;    }}void UserMain(void) {int demo_connect_net(char *ssid, char *pwd) {struct tls_param_ip *ip_param = NULL;u8 wireless_protocol = 0;if (!ssid) {return WM_FAILED;}printf("\nssid:%s\n", ssid);printf("password=%s\n", pwd);tls_wifi_disconnect();tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void *) &wireless_protocol, TRUE);if (TLS_PARAM_IEEE80211_INFRA != wireless_protocol) {tls_wifi_softap_destroy();wireless_protocol = TLS_PARAM_IEEE80211_INFRA;tls_param_set(TLS_PARAM_ID_WPROTOCOL, (void *) &wireless_protocol, FALSE);}tls_wifi_set_oneshot_flag(0);ip_param = tls_mem_alloc(sizeof(struct tls_param_ip));if (ip_param) {tls_param_get(TLS_PARAM_ID_IP, ip_param, FALSE);ip_param->dhcp_enable = TRUE;tls_param_set(TLS_PARAM_ID_IP, ip_param, FALSE);tls_mem_free(ip_param);}tls_netif_add_status_event(con_net_status_changed_event);tls_wifi_connect((u8 *)ssid, strlen(ssid), (u8 *)pwd, strlen(pwd));printf("\请等待网络连接......\n");return WM_SUCCESS;}//连接WIFIdemo_connect_net(ssid,pwd);}

中评网简体版