Scanning wifi periodically

Scanning wifi periodically

BY 03 Mar 2016 Native Application Development

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…)

Written by