SSID listing and connectivity issues

Greetings community members. I need your help!

  1. My goal is: List available networks in the mobile application
  2. My actions are: Connect to desired network from the scanned list of SSID’s
  3. The result I see is: An empty array

Currently we’re building this IoT device using an ESP8266 (ESP-12F). In short, the device uses Google Cloud in order for the user to communicate with the device, in this case, control an LED panel and turn on/off a small motor. The issue that we are facing right now is in the SSID listing process when we want to connect and configure our device with the local WIFI.

We have an SSID scanning code in mongoose and we have the API to list all available networks into the App. Problem is when we hit the SSID listing API, it responds to an empty array every time.

Any idea why this might happen?

Worth mentioning is that we started our development with Ionic, but then shifted to Native. This is when we started noticing a few bugs.

Your help is greatly appreciated! I really need your assistance.

Stay safe!

/Hamza

You should clearly explain what you are doing, what you are calling, and how you are calling it.
I guess you are sure your device is configured as a station.
I personally don’t have a clue on what Ionic and Native are, please describe your usage of the Mongoose-OS API, either in C or in mJS, in terms of what is documented here

I’m seeing the same thing. It is sometimes really hard to get any SSIDs from the wifi scan routine on ESP8266.
I believe the cause is that Mongoose OS simply calls the ESP-SDK’s wifi scan routine with default scan parameters, which apparently are not really optimal.
Check Mongoose OS’ wifi library and find the mgos_wifi_dev_start_scan() function. The scan parameter is NULL, ie use defaults. Playing with these parameters made a big difference for me. You can find the parameters from Espressif’s documentation or compare with the ESP32 implementation.

1 Like

We have same problem with wifi scanning. I’m using simple wifi scan example(https://github.com/mongoose-os-apps/wifi-scan). And even the networks with highest RSSI values aren’t listed in scan results. For example if i use Arduino Framework wifi scan example, everything works correctly(all nearby networks are listed in scan result). I found that mongoose is using little bit old version of EPS8266 NONOS SDK v2.2.1. The latest version is v3.0.4 that has couple of wifi issues fixed. Is it possible to change SDK to newer version? Would be there some porting(API/ABI incopatibility) issues? Thank you for feedback.

Ok, i tried call wifi_station_scan by hand, and i got correct results. Probably there is BUG in bss_info handling in mongoose wifi_scan_done function. I handled results manually using:

        auto result = static_cast<const bss_info*>(arg);
        while (result != nullptr) {
            ...
            result = STAILQ_NEXT(result, next);
        }

Without tweaking scan parameters i got my primary wifi network scanned correctly. By tweaking also active scan parameters i got additional nearby networks. I set minimum and maximum time for active scanning to 100 and 1100 milliseconds.

No, you can’t change the SDK version, Mongoose-OS is a complex piece of software that works over several manufacturers’ SDKs and it is stable to a defined SDK for a release. The developers will in turn migrate to a more recent SDK when circumstances allow it.

Would you care to explain what fails and what works ?
Your code seems to be C++ and I don’t have the faintest idea on what STAILQ_NEXT() does.
What do you call ? What do you get ? What did you do “manually” ? What is bss_info ? Do you get the correct result for ‘n’ and just a corrupt listing ?

@nliviu I’ve run the example on a ESP32 and the logs look strange; the number of SSIDs found is correct, but only a handful are printed, and intertwined with other logs:

[Nov 23 14:41:10.821] main.c:17               Starting WiFi scan
[Nov 23 14:41:10.825] esp32_wifi.c:196        WiFi mode: AP+STA
[Nov 23 14:41:10.832] I (2778) wifi:mode : sta (30:ae:a4:80:7a:98) + softAP (30:ae:a4:80:7a:99)
[Nov 23 14:41:10.838] mgos_mongoose.c:66      New heap free LWM: 227908
[Nov 23 14:41:11.848] mgos_mongoose.c:66      New heap free LWM: 225728
[Nov 23 14:41:12.191] main.c:4                WiFi scan result: SSIDs 8, arg 0x0, results:
[Nov 23 14:41:12.205] esp32_wifi.c:196        main.c:11               WiFi mode: AP  SSID: Pandora                         , BSSID: 92:f6:52:a4:c0:1e auth: 3, channel:  11, RSSI: -63
[Nov 23 14:41:12.205] 
[Nov 23 14:41:12.220] main.c:11                 SSID: LinternaVerde                   , BSSID: 96:f6:52:a4:c0:1e auth: 3, channel:  11, RSSI: -63
[Nov 23 14:41:12.220] I (4158) wifi:mode : softAP (30:ae:a4:80:7a:99)
[Nov 23 14:41:19.966] main.c:17               Starting WiFi scan
[Nov 23 14:41:19.970] esp32_wifi.c:196        WiFi mode: AP+STA
[Nov 23 14:41:19.977] I (11928) wifi:mode : sta (30:ae:a4:80:7a:98) + softAP (30:ae:a4:80:7a:99)
[Nov 23 14:41:20.988] mgos_mongoose.c:66      New heap free LWM: 225528
[Nov 23 14:41:21.377] main.c:4                WiFi scan result: SSIDs 10, arg 0x0, results:esp32_wifi.c:196        
[Nov 23 14:41:21.380] WiFi mode: APmain.c:11               
[Nov 23 14:41:21.394]   SSID: Sandbox                         , BSSID: 90:f6:52:a4:c0:1e auth: 3, channel:  11, RSSI: -65
[Nov 23 14:41:21.394] I (13338) wifi:mode : softAP (30:ae:a4:80:7a:99)
[Nov 23 14:41:29.966] main.c:17               Starting WiFi scan
[Nov 23 14:41:29.970] esp32_wifi.c:196        WiFi mode: AP+STA
[Nov 23 14:41:29.977] I (21928) wifi:mode : sta (30:ae:a4:80:7a:98) + softAP (30:ae:a4:80:7a:99)
[Nov 23 14:41:31.295] main.c:4                WiFi scan result: SSIDs 6, arg 0x0, results:
[Nov 23 14:41:31.309] esp32_wifi.c:196        main.c:11               WiFi mode: AP  SSID: SkinlessSkin                    , BSSID: 9a:f6:52:a4:c0:1e auth: 3, channel:  11, RSSI: -64
[Nov 23 14:41:31.309] 
[Nov 23 14:41:31.324] main.c:11                 SSID: Sandbox                         , BSSID: 90:f6:52:a4:c0:1e auth: 3, channel:  11, RSSI: -65
[Nov 23 14:41:31.324] I (23268) wifi:mode : softAP (30:ae:a4:80:7a:99)

See the “done” text is not printed, this is is weird.

I added a “Entry # of #” text and most of the times the loop seems to exit before all the lines are printed, and the “done” text is not printed (?)(the callback exits ?).

[Nov 23 14:32:24.736] main.c:18               Starting WiFi scan
[Nov 23 14:32:24.740] esp32_wifi.c:196        WiFi mode: AP+STA
[Nov 23 14:32:24.747] I (11928) wifi:mode : sta (30:ae:a4:80:7a:98) + softAP (30:ae:a4:80:7a:99)
[Nov 23 14:32:25.758] mgos_mongoose.c:66      New heap free LWM: 225824
[Nov 23 14:32:26.062] esp32_wifi.c:196        WiFi mode: AP
[Nov 23 14:32:26.067] I (13248) wifi:mode : softAP (30:ae:a4:80:7a:99)
[Nov 23 14:32:34.736] main.c:18               Starting WiFi scan
[Nov 23 14:32:34.740] esp32_wifi.c:196        WiFi mode: AP+STA
[Nov 23 14:32:34.750] I (21928) wifi:mode : sta (30:ae:a4:80:7a:98) + softAP (30:ae:a4:80:7a:99)
[Nov 23 14:32:35.758] mgos_mongoose.c:66      New heap free LWM: 225724
[Nov 23 14:32:36.108] main.c:4                WiFi scan result: SSIDs 8, arg 0x0, results:esp32_wifi.c:196        
[Nov 23 14:32:36.112] WiFi mode: APmain.c:6                
[Nov 23 14:32:36.118] Entry 1 of 8:
[Nov 23 14:32:36.118] I (23298) wifi:mode : softAP (30:ae:a4:80:7a:99)
[Nov 23 14:32:44.737] main.c:18               Starting WiFi scan
[Nov 23 14:32:44.740] esp32_wifi.c:196        WiFi mode: AP+STA
[Nov 23 14:32:44.747] I (31928) wifi:mode : sta (30:ae:a4:80:7a:98) + softAP (30:ae:a4:80:7a:99)
[Nov 23 14:32:46.147] main.c:4                WiFi scan result: SSIDs 8, arg 0x0, results:
[Nov 23 14:32:46.154] esp32_wifi.c:196        main.c:6                WiFi mode: APEntry 1 of 8:
[Nov 23 14:32:46.154] 
[Nov 23 14:32:46.169] main.c:12                 SSID: Sandbox                         , BSSID: 90:f6:52:a4:c0:1e auth: 3, channel:  11, RSSI: -66
[Nov 23 14:32:46.169] I (33338) wifi:mode : softAP (30:ae:a4:80:7a:99)
[Nov 23 14:32:54.737] main.c:18               Starting WiFi scan
[Nov 23 14:32:54.740] esp32_wifi.c:196        WiFi mode: AP+STA
[Nov 23 14:32:54.748] I (41928) wifi:mode : sta (30:ae:a4:80:7a:98) + softAP (30:ae:a4:80:7a:99)
[Nov 23 14:32:56.066] main.c:4                WiFi scan result: SSIDs 6, arg 0x0, results:
[Nov 23 14:32:56.073] esp32_wifi.c:196        main.c:6                WiFi mode: APEntry 1 of 6:
[Nov 23 14:32:56.073] 
[Nov 23 14:32:56.088] main.c:12                 SSID: Sandbox                         , BSSID: 90:f6:52:a4:c0:1e auth: 3, channel:  11, RSSI: -66
[Nov 23 14:32:56.088] I (43258) wifi:mode : softAP (30:ae:a4:80:7a:99)
[Nov 23 14:33:04.737] main.c:18               Starting WiFi scan
[Nov 23 14:33:04.741] esp32_wifi.c:196        WiFi mode: AP+STA
[Nov 23 14:33:04.748] I (51928) wifi:mode : sta (30:ae:a4:80:7a:98) + softAP (30:ae:a4:80:7a:99)
[Nov 23 14:33:06.106] main.c:4                WiFi scan result: SSIDs 7, arg 0x0, results:
[Nov 23 14:33:06.113] esp32_wifi.c:196        main.c:6                WiFi mode: APEntry 1 of 7:
[Nov 23 14:33:06.113] 
[Nov 23 14:33:06.128] main.c:12                 SSID: Sandbox                         , BSSID: 90:f6:52:a4:c0:1e auth: 3, channel:  11, RSSI: -66
[Nov 23 14:33:06.128] I (53298) wifi:mode : softAP (30:ae:a4:80:7a:99)
[Nov 23 14:33:14.737] main.c:18               Starting WiFi scan
[Nov 23 14:33:14.741] esp32_wifi.c:196        WiFi mode: AP+STA
[Nov 23 14:33:14.748] I (61928) wifi:mode : sta (30:ae:a4:80:7a:98) + softAP (30:ae:a4:80:7a:99)
[Nov 23 14:33:16.106] main.c:4                WiFi scan result: SSIDs 6, arg 0x0, results:
[Nov 23 14:33:16.112] esp32_wifi.c:196        main.c:6                WiFi mode: APEntry 1 of 6:
[Nov 23 14:33:16.112] 
[Nov 23 14:33:16.128] main.c:12                 SSID: Sandbox                         , BSSID: 90:f6:52:a4:c0:1e auth: 3, channel:  11, RSSI: -66
[Nov 23 14:33:16.128] I (63298) wifi:mode : softAP (30:ae:a4:80:7a:99)

However, toying with the texts like for example adding a \n here or there, sometimes it works OK.
stack trashing ?

It looks like you are in AP mode and ESP-IDF log messages are intermixed with mOS messages.
I see similar output.

In STA mode the logs are ok:

Nov 23 20:27:48.418] mgos_net.c:102          WiFi STA: ready, IP 192.168.1.250, GW 192.168.1.1, DNS 192.168.1.171
[Nov 23 20:27:56.282] main.c:17               Starting WiFi scan
[Nov 23 20:27:57.561] main.c:4                WiFi scan result: SSIDs 6, arg 0x0, results:
[Nov 23 20:27:57.572] main.c:11                 SSID: zombie123-5g                    , BSSID: 18:e8:29:fb:04:6b auth: 3, channel:  11, RSSI: -43
[Nov 23 20:27:57.582] main.c:11                 SSID: UPC Wi-Free                     , BSSID: ae:22:15:5b:49:aa auth: 5, channel:  11, RSSI: -89
[Nov 23 20:27:57.593] main.c:11                 SSID: UPC6671483                      , BSSID: 38:43:7d:c2:62:1c auth: 4, channel:  11, RSSI: -90
[Nov 23 20:27:57.604] main.c:11                 SSID: DIGI_dfe86b                     , BSSID: dc:f8:b9:df:e8:6b auth: 4, channel:  11, RSSI: -91
[Nov 23 20:27:57.615] main.c:11                 SSID: UPC313E284                      , BSSID: ac:22:05:5b:49:aa auth: 4, channel:  11, RSSI: -91
[Nov 23 20:27:57.626] main.c:11                 SSID: UPC Wi-Free                     , BSSID: 3a:43:1d:c2:62:1c auth: 5, channel:  11, RSSI: -91
[Nov 23 20:27:57.629] main.c:13               WiFi scan done.
[Nov 23 20:28:06.282] main.c:17               Starting WiFi scan

Yes, thanks, I’ve just run the example as is. Maybe the others are having the same issue ?
(I didn’t realize those other msgs where ESP’s and not mOS’, maybe those just trash the log buffer but that “loop exit” effect is kinda weird)

Interesting! I’ll need to try that as well.
Tweaking the scan parameters definitely helps, but this suggests there may be an issue in reporting the results as well. Hmmm… But if that is the case then why did the scan parameters improve the results?

No, the issue here is with the wifi scan routine on ESP8266. The code for ESP32 is quite different.
Now whether the root cause is ESP8266 nonOS SDK’s default wifi scan parameters (as I thought), or the way Mongoose OS’ wifi library handles the scan results (as JanValiska reported above) still needs some checking.

Definitelly try to handle SDK scan results manually. I don’t know what exactly is incorrect in mongoose scan results handling. But for me, the manual(simple as possible) handling of scan results fixed the problem. Scan parameters are not so important for me as correct results handling. But tweaking the scan params can definitely have impact on wifi scanning. Try and you will see.

Hi, try look to: https://github.com/mongoose-os-libs/wifi/blob/master/src/esp8266/esp_wifi.c
On lines 396 the wifi_scan_done handler is defined. This is place where mongoose handles bss_info linked list that is provided by SDK after wifi scan. It seems that there is some problem/bug. Because when i use my “simplistic” version of handling i will receive correct results.

Yes, I use c++ because it is supported by mongoose.

Thanks, that’s what I’ve been looking at.

So is the snippet in your earlier post the core of your simplistic version? What I mean is do you still use the STAILQ_* stuff for storing the results? So no need to try redoing that part?

struct bss_info is a Singly-linked Tail queue
STAILQ_* macros are defined here.