@@ -16,97 +16,18 @@ class WiFiClass: public NetworkInterface
1616 WiFiClass () {}
1717 ~WiFiClass () {}
1818
19- int begin (const char * ssid, const char * passphrase, wl_enc_type security = ENC_TYPE_UNKNOWN, bool blocking = true ) {
20- sta_iface = net_if_get_wifi_sta ();
21- netif = sta_iface;
22- sta_config.ssid = (const uint8_t *)ssid;
23- sta_config.ssid_length = strlen (ssid);
24- sta_config.psk = (const uint8_t *)passphrase;
25- sta_config.psk_length = strlen (passphrase);
26- // TODO: change these fields with scan() results
27- sta_config.security = WIFI_SECURITY_TYPE_PSK;
28- sta_config.channel = WIFI_CHANNEL_ANY;
29- sta_config.band = WIFI_FREQ_BAND_2_4_GHZ;
30- sta_config.bandwidth = WIFI_FREQ_BANDWIDTH_20MHZ;
19+ int begin (const char * ssid, const char * passphrase, wl_enc_type security = ENC_TYPE_UNKNOWN, bool blocking = true );
3120
32- int ret = net_mgmt (NET_REQUEST_WIFI_CONNECT, sta_iface, &sta_config,
33- sizeof (struct wifi_connect_req_params ));
34- if (ret) {
35- return false ;
36- }
21+ int beginAP (char * ssid, char * passphrase, int channel = WIFI_CHANNEL_ANY, bool blocking = true );
3722
38- NetworkInterface::begin (false , NET_EVENT_WIFI_MASK);
39- if (blocking) {
40- net_mgmt_event_wait_on_iface (sta_iface, NET_EVENT_WIFI_CONNECT_RESULT, NULL , NULL , NULL , K_FOREVER);
41- }
42-
43- return status ();
44- }
45-
46- int beginAP (char * ssid, char * passphrase, int channel = WIFI_CHANNEL_ANY, bool blocking = true ) {
47- if (ap_iface != NULL ) {
48- return false ;
49- }
50- ap_iface = net_if_get_wifi_sap ();
51- netif = ap_iface;
52- ap_config.ssid = (const uint8_t *)ssid;
53- ap_config.ssid_length = strlen (ssid);
54- ap_config.psk = (const uint8_t *)passphrase;
55- ap_config.psk_length = strlen (passphrase);
56- ap_config.security = WIFI_SECURITY_TYPE_PSK;
57- ap_config.channel = channel;
58- ap_config.band = WIFI_FREQ_BAND_2_4_GHZ;
59- ap_config.bandwidth = WIFI_FREQ_BANDWIDTH_20MHZ;
60-
61- int ret = net_mgmt (NET_REQUEST_WIFI_AP_ENABLE, ap_iface, &ap_config,
62- sizeof (struct wifi_connect_req_params ));
63-
64- if (ret) {
65- return false ;
66- }
67-
68- enable_dhcpv4_server (ap_iface);
69-
70- if (blocking) {
71- net_mgmt_event_wait_on_iface (ap_iface, NET_EVENT_WIFI_AP_ENABLE_RESULT, NULL , NULL , NULL , K_FOREVER);
72- }
73-
74- return status ();
75- }
76-
77- int status () {
78- sta_iface = net_if_get_wifi_sta ();
79- netif = sta_iface;
80- if (net_mgmt (NET_REQUEST_WIFI_IFACE_STATUS, netif, &sta_state,
81- sizeof (struct wifi_iface_status ))) {
82- return WL_NO_SHIELD;
83- }
84-
85- if (sta_state.state >= WIFI_STATE_ASSOCIATED) {
86- return WL_CONNECTED;
87- } else {
88- return WL_DISCONNECTED;
89- }
90- return WL_NO_SHIELD;
91- }
23+ int status ();
9224
9325 int8_t scanNetworks () {
9426 // TODO: borrow code from mbed core for scan results handling
9527 }
9628
97- char * SSID () {
98- if (status () == WL_CONNECTED) {
99- return (char *)sta_state.ssid ;
100- }
101- return nullptr ;
102- }
103-
104- int32_t RSSI () {
105- if (status () == WL_CONNECTED) {
106- return sta_state.rssi ;
107- }
108- return 0 ;
109- }
29+ char * SSID ();
30+ int32_t RSSI ();
11031
11132 String firmwareVersion ();
11233
0 commit comments