Languages

Menu
Sites
Language
Scanning wifi periodically

Hi,

I'm developing a native app for wearable, for scan wifi signals periodically.

Here's my work bellow,

bool
__wifi_found_ap_cb(wifi_ap_h ap, void *user_data)
{
   int error_code = 0;
   int rssi = 0;
   char *ap_name = NULL;
   wifi_connection_state_e state;


   error_code = wifi_ap_get_essid(ap, &ap_name);
   if (error_code != WIFI_ERROR_NONE)
   {
      dlog_print(DLOG_INFO, LOG_TAG, "Fail to get AP name.");

      return false;
   }
   error_code = wifi_ap_get_connection_state(ap, &state);
   if (error_code != WIFI_ERROR_NONE)
   {
      dlog_print(DLOG_INFO, LOG_TAG, "Fail to get state.");

      return false;
   }
   error_code =  wifi_ap_get_rssi(ap, &rssi);
   dlog_print(DLOG_INFO, LOG_TAG, "AP name : %s, state : %s rssi: %d", ap_name, print_state(state), rssi);

   return true;
}

void
__scan_request_cb(wifi_error_e error_code, void *user_data)
{
   error_code = wifi_foreach_found_aps(__wifi_found_ap_cb, NULL);
   if (error_code != WIFI_ERROR_NONE)
      dlog_print(DLOG_INFO, LOG_TAG, "Fail to scan");
   wifi_deinitialize();

}

static void
__wifi_activated_cb(wifi_error_e result, void *user_data)
{
   if (result == WIFI_ERROR_NONE)
      dlog_print(DLOG_INFO, LOG_TAG, "Success to activate Wi-Fi device!");
}

void
check_cb(void *data, Evas_Object *obj, void *event_info)
{
    int error_code;

    //initialize.
    error_code = wifi_initialize();
    if (error_code != WIFI_ERROR_NONE) {
        dlog_print(DLOG_INFO, LOG_TAG, "Fail to initialize wifi.");
       exit(1);
    }

    //activate.
    error_code = wifi_activate(__wifi_activated_cb, NULL);
    bool wifi_activated = false;
    wifi_is_activated(&wifi_activated);
    if (wifi_activated)
    {
       dlog_print(DLOG_INFO, LOG_TAG, "Success to get Wi-Fi device state.");
    }
    else
    {
       dlog_print(DLOG_INFO, LOG_TAG, "Fail to get Wi-Fi device state.");
    }

    //wifi_set_background_scan_cb(__wifi_scan_finished_cb, NULL);

    //scan.
    wifi_scan(__scan_request_cb, NULL);
}

 

Here is the main question: Everytime I tap the button, i.e. call check_cb, the app successfully print wifi signal. I want to print them periodically, without manually tapping. Do you have any idea, plz?

-sleep(5); after wifi_scan and call wifi_scan again  (sleep stops scanning too)

-use wifi_set_background_scan_cb(__wifi_scan_finished_cb, NULL);  (it doesn't work)

-call wifi_scan after wifi_deinitialize in __scan_request_cb  (it does call wifi_scan ftn again, but doesn't scan...)

Responses

6 Replies
SeokHoon LEE

You can use ecore timer simply.

Refer below test code and link.

https://developer.tizen.org/development/api-references/api-reference-2.3.1?redirect=https%3A//developer.tizen.org/dev-guide/2.3.1/org.tizen.native.mobile.apireference/group__Ecore__Timer__Group.html

 

Eina_Bool _timer_cb(void *data)
{
    dlog_print(DLOG_ERROR, LOG_TAG, "Timer occured");

	return EINA_TRUE;
}


static bool app_create(void *user_data)
{

    Ecore_Timer *timer;

    timer = ecore_timer_loop_add(5, _timer_cb, NULL);

}

 

Kee-Hoon Kim

Hi, thanks for replying :)

It is good help for calling a given function periodically,

although my problem still be unsolved : 1st calling wifi_scan successfully print the wifi data; 2nd, 3rd, ... calling wifi_scan somehow doesn't work; since a __scan_request_cb function is not called, I think after 1st wifi_scan, this app doesn't scan at all.. do you know why this happening?

Alex Dem

Hi,
Of course you could use ecore timer as it has been proposed above,
but per my opinion better try to use Wi-Fi Monitor API:
https://developer.tizen.org/dev-guide/2.3.1/org.tizen.native.wearable.apireference/group__CAPI__NETWORK__WIFI__MONITOR__MODULE.html
If you try to set/unset appropriate callbacks, you could track changes in states of such parameters as wifi_device_state_e/wifi_connection_state_e/wifi_rssi_level_e
Alexey.

Kee-Hoon Kim

Hi, Alex, tks for your reply

I have checked Wi-Fi Monitor API and wifi_set_background_scan_cb, and I'm understood that this registered callback function will be called whenever after the background scanning. But I can't understand : what is the background scanning? Is it different from a scan by wifi_scan? I registered cb function and it never happened to be called.. and if I can use this function, how can I set a time period?

And unfortunately, I think other api such as wifi_device_state_e/wifi_connection_state_e/wifi_rssi_level_e can't be help me as I'm trying to get wifi data, don't have to actually connect to it.

Tks again :)

SeokHoon LEE

Thanks for your opinion.

It would be better to use wi-fi monitor api.

It only need to wifi scanning, wifi_set_background_scan_cb will be good choice than ecore timer.

Kee-Hoon Kim

Oh, I had tried to enlarging a period using Ecore_timer, and it certainly works! 

I think wifi_scan maybe needs some time to be called after 1st time..

I really thank both of you!