Skip to content

Commit 512b827

Browse files
committed
Add new WL_AP_LISTENING and WL_AP_CONNECTED status types for AP mode
1 parent 027e3a6 commit 512b827

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

examples/AP_SimpleWebServer/AP_SimpleWebServer.ino

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ void setup() {
5151
Serial.println(ssid);
5252

5353
// Create open network. Change this line if you want to create an WEP network:
54-
if (WiFi.beginAP(ssid) != WL_CONNECTED) {
54+
status = WiFi.beginAP(ssid);
55+
if (status != WL_AP_LISTENING) {
5556
Serial.println("Creating access point failed");
5657
// don't continue
5758
while (true);
@@ -69,6 +70,20 @@ void setup() {
6970

7071

7172
void loop() {
73+
// compare the previous status to the current status
74+
if (status != WiFi.status()) {
75+
// it has changed update the variable
76+
status = WiFi.status();
77+
78+
if (status == WL_AP_CONNECTED) {
79+
// a device has connected to the AP
80+
Serial.println("Device connected to AP");
81+
} else {
82+
// a device has disconnected from the AP, and we are back in listening mode
83+
Serial.println("Device disconnected from AP");
84+
}
85+
}
86+
7287
WiFiClient client = server.available(); // listen for incoming clients
7388

7489
if (client) { // if you get a client,

src/WiFi.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ static void wifi_cb(uint8_t u8MsgType, void *pvMsg)
4141

4242
// WiFi led ON.
4343
m2m_periph_gpio_set_val(M2M_PERIPH_GPIO15, 0);
44+
} else if (WiFi._mode == WL_AP_MODE) {
45+
WiFi._status = WL_AP_CONNECTED;
4446
}
4547
} else if (pstrWifiState->u8CurrState == M2M_WIFI_DISCONNECTED) {
4648
//SERIAL_PORT_MONITOR.println("wifi_cb: M2M_WIFI_RESP_CON_STATE_CHANGED: DISCONNECTED");
@@ -51,6 +53,8 @@ static void wifi_cb(uint8_t u8MsgType, void *pvMsg)
5153
WiFi._submask = 0;
5254
WiFi._gateway = 0;
5355
}
56+
} else if (WiFi._mode == WL_AP_MODE) {
57+
WiFi._status = WL_AP_LISTENING;
5458
}
5559
// WiFi led OFF (rev A then rev B).
5660
m2m_periph_gpio_set_val(M2M_PERIPH_GPIO15, 1);
@@ -407,7 +411,7 @@ uint8_t WiFiClass::startAP(const char *ssid, uint8_t u8SecType, const void *pvAu
407411
_status = WL_CONNECT_FAILED;
408412
return _status;
409413
}
410-
_status = WL_CONNECTED;
414+
_status = WL_AP_LISTENING;
411415
_mode = WL_AP_MODE;
412416

413417
memset(_ssid, 0, M2M_MAX_SSID_LEN);
@@ -527,6 +531,7 @@ void WiFiClass::end()
527531
m2m_wifi_disable_ap();
528532

529533
_status = WL_IDLE_STATUS;
534+
_mode = WL_RESET_MODE;
530535
} else {
531536
if (_mode == WL_PROV_MODE) {
532537
m2m_wifi_stop_provision_mode();

src/WiFi101.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ typedef enum {
4141
WL_CONNECTED,
4242
WL_CONNECT_FAILED,
4343
WL_CONNECTION_LOST,
44-
WL_DISCONNECTED
44+
WL_DISCONNECTED,
45+
WL_AP_LISTENING,
46+
WL_AP_CONNECTED
4547
} wl_status_t;
4648

4749
/* Encryption modes */

0 commit comments

Comments
 (0)