File tree Expand file tree Collapse file tree 2 files changed +39
-13
lines changed
examples/AP_SimpleWebServer Expand file tree Collapse file tree 2 files changed +39
-13
lines changed Original file line number Diff line number Diff line change @@ -76,12 +76,26 @@ void loop() {
76
76
status = WiFi.status ();
77
77
78
78
if (status == WL_AP_CONNECTED) {
79
+ byte remoteMac[6 ];
80
+
79
81
// a device has connected to the AP
80
- Serial.println (" Device connected to AP" );
82
+ Serial.print (" Device connected to AP, MAC address: " );
83
+ WiFi.BSSID (remoteMac);
84
+ Serial.print (remoteMac[5 ], HEX);
85
+ Serial.print (" :" );
86
+ Serial.print (remoteMac[4 ], HEX);
87
+ Serial.print (" :" );
88
+ Serial.print (remoteMac[3 ], HEX);
89
+ Serial.print (" :" );
90
+ Serial.print (remoteMac[2 ], HEX);
91
+ Serial.print (" :" );
92
+ Serial.print (remoteMac[1 ], HEX);
93
+ Serial.print (" :" );
94
+ Serial.println (remoteMac[0 ], HEX);
81
95
} else {
82
96
// a device has disconnected from the AP, and we are back in listening mode
83
97
Serial.println (" Device disconnected from AP" );
84
- }
98
+ }
85
99
}
86
100
87
101
WiFiClient client = server.available (); // listen for incoming clients
@@ -154,4 +168,5 @@ void printWifiStatus() {
154
168
// print where to go in a browser:
155
169
Serial.print (" To see this page in action, open a browser to http://" );
156
170
Serial.println (ip);
171
+
157
172
}
Original file line number Diff line number Diff line change @@ -140,15 +140,26 @@ static void wifi_cb(uint8_t u8MsgType, void *pvMsg)
140
140
if (scan_ssid_len) {
141
141
memcpy (WiFi._scan_ssid , (const char *)pstrScanResult->au8SSID , scan_ssid_len);
142
142
}
143
- if (WiFi._bssid ) {
144
- memcpy (WiFi._bssid , (const char *)pstrScanResult->au8BSSID , 6 );
145
- }
146
143
WiFi._resolve = pstrScanResult->s8rssi ;
147
144
WiFi._scan_auth = pstrScanResult->u8AuthType ;
148
145
WiFi._status = WL_SCAN_COMPLETED;
149
146
}
150
147
break ;
151
148
149
+ case M2M_WIFI_RESP_CONN_INFO:
150
+ {
151
+ tstrM2MConnInfo *pstrConnInfo = (tstrM2MConnInfo*)pvMsg;
152
+
153
+ if (WiFi._bssid ) {
154
+ // reverse copy the remote MAC
155
+ for (int i = 0 ; i < 6 ; i++) {
156
+ WiFi._bssid [i] = pstrConnInfo->au8MACAddress [5 -i];
157
+ }
158
+ WiFi._bssid = 0 ;
159
+ }
160
+ }
161
+ break ;
162
+
152
163
default :
153
164
break ;
154
165
}
@@ -591,17 +602,17 @@ char* WiFiClass::SSID()
591
602
592
603
uint8_t * WiFiClass::BSSID (uint8_t * bssid)
593
604
{
594
- int8_t net = scanNetworks ();
595
-
596
605
_bssid = bssid;
597
606
memset (bssid, 0 , 6 );
598
- for (uint8_t i = 0 ; i < net; ++i) {
599
- SSID (i);
600
- if (strcmp (_scan_ssid, _ssid) == 0 ) {
601
- break ;
602
- }
607
+
608
+ m2m_wifi_get_connection_info ();
609
+
610
+ // Wait for connection or timeout:
611
+ unsigned long start = millis ();
612
+ while (_bssid != 0 && millis () - start < 1000 ) {
613
+ m2m_wifi_handle_events (NULL );
603
614
}
604
-
615
+
605
616
_bssid = 0 ;
606
617
return bssid;
607
618
}
You can’t perform that action at this time.
0 commit comments