Copyright ©

Mongoose OS Forum


issue with mgos_wif_scan ( using mgoose_os_version : 1.4 )

mgos_wifi_scan is not calling the registered callback second time. First when i tried to scan the APs when the device was in AP+STA mode the registered callback was called properly and i got the scanned APs, but when i change the mode to AP using mgos_wifi_setup_ap and again tried to scan the APs using mgos_wifi_scan it scanned the APs internally by using the esp apis but it didn't call the registered callback. And also i saw that mgos_wifi_scan is changing the mode to AP+STA internally so i think there is no need to change the mode to AP+STA before scanning the aps.


  • rojerrojer Dublin, Ireland

    IIRC the device has to be in STA mode (STA or AP+STA) to perform scanning. it doesn't have to be configured or connected, but STA has to be enabled for scanning to work.

    i just did a quick test and scanning from AP mode works (after turning it into AP+STA). i'll need you to create a simple app that reproduces the bug.

  • I was debugging the issue and i found that mgos_wifi_scan does not call the registered callback when it is called from the registered handler. The attached file is scan.txt

  • rojerrojer Dublin, Ireland
  • rojerrojer Dublin, Ireland

    oh, i see now. you are blocking the main task in your handler, waiting for scan callback:

        if(ev == MG_EV_HTTP_REQUEST) {
            mgos_wifi_scan( wifi_scan_callback, (void *)&ap_count);
                printf("-----waiting for scan done-----\r\n");
            scan_done = 0;
            printf("----scan completed----\r\n");

    this loop here blocks the main task, where all the mOS activity happens. don't run a loop like that on the main task.

  • But this loop is in handler so how the main task got stuck, as you can see the main function (mgos_app_init) is only creating one task ScanThread after creating it the main function will return. I need that loop in the handler as u can see that the scan_done flag is raised from the wifi_scan_callback, so after scaning the aps in the handler i want to send the ap_list to the requester.

  • rojerrojer Dublin, Ireland
    edited July 12

    mongoose events and scan callbacks are executed in main task. loop in your scan task is fine, but you cannot block the main task.

Sign In or Register to comment.