-->
Page 1 of 1

How to scan networks with FreeRTOS SDK?

PostPosted: Mon Jan 05, 2015 1:39 pm
by crazyferajna
Hello everyone! I have written the code to get list of available networks, but it isn't working... The function wifi_station_scan always returns false. What am I doing wrong?

Code: Select all#include <espressif/esp_common.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <lwip/sockets.h>
#include <lwip/dns.h>
#include <lwip/netdb.h>
#include <udhcp/dhcpd.h>

void ICACHE_FLASH_ATTR scan_done_callback(void *arg, STATUS status)
{
    struct bss_info *bss = arg;

    bss = STAILQ_NEXT(bss, next); // ignore first

    while (bss)
    {
        printf("%s %d %d %d\n", bss->ssid, bss->channel, bss->rssi, bss->authmode);
        bss = STAILQ_NEXT(bss, next);
    }
}

void ICACHE_FLASH_ATTR scanner(void *pvParameters)
{
    printf("Starting scanning...");
    if (wifi_station_scan(NULL, scan_done_callback))
    {
        printf("OK!");
       
    }
    else
    {
        printf("Error...");
    }

    vTaskDelete(NULL);
}

void ICACHE_FLASH_ATTR user_init(void)
{
    wifi_set_opmode(STATION_MODE);
    wifi_station_set_auto_connect(FALSE);

    xTaskCreate(scanner, "scanner", 128, NULL, 2, NULL);
}

Re: How to scan networks with FreeRTOS SDK?

PostPosted: Thu Jan 08, 2015 9:14 am
by ofpaulus
In my opinion, you should use function system_init_done_cb from SDK\include\user_interface.h

Please try something like this.
Code: Select allvoid ICACHE_FLASH_ATTR init_done(void)
{
    xTaskCreate(scanner, "scanner", 128, NULL, 2, NULL);
}

void ICACHE_FLASH_ATTR user_init(void)
{
    wifi_set_opmode(STATION_MODE);
    wifi_station_set_auto_connect(FALSE);

    system_init_done_cb(init_done);
}

Re: How to scan networks with FreeRTOS SDK?

PostPosted: Fri Jan 09, 2015 1:52 pm
by crazyferajna
Thank you for your reply. Unfortunately, in FreeRTOS version of the SDK this function is unavailable.

Re: How to scan networks with FreeRTOS SDK?

PostPosted: Wed Aug 24, 2016 7:32 am
by psychegr
crazyferajna wrote:Thank you for your reply. Unfortunately, in FreeRTOS version of the SDK this function is unavailable.


A bit late but i had the same issue as you. The code from the link will help you.
In sort you have to create a task and do the wifi scan in that task. For me it works great.

http://bbs.espressif.com/viewtopic.php?t=974