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