From 3ce212e0a67424c4c89c273e7509be84dc30a172 Mon Sep 17 00:00:00 2001
From: Bill Owens <owens.bill@gmail.com>
Date: Wed, 10 Jun 2015 07:11:34 -0700
Subject: [PATCH] esp8266: Changed esp_scan to keep the current WiFi operating
 mode but throw an exception if WiFi is in AP only mode

---
 esp8266/modesp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/esp8266/modesp.c b/esp8266/modesp.c
index 3ca7f7271..c1591fea2 100644
--- a/esp8266/modesp.c
+++ b/esp8266/modesp.c
@@ -528,7 +528,10 @@ STATIC void esp_scan_cb(scaninfo *si, STATUS status) {
 
 STATIC mp_obj_t esp_scan(mp_obj_t cb_in) {
     MP_STATE_PORT(scan_cb_obj) = cb_in;
-    wifi_set_opmode(STATION_MODE);
+    if (wifi_get_opmode() == SOFTAP_MODE) {
+        nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, 
+            "Scan not supported in AP mode"));
+    }
     wifi_station_scan(NULL, (scan_done_cb_t)esp_scan_cb);
     return mp_const_none;
 }
-- 
GitLab