Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Contributor
yoginih
Posts: 9
Registered: ‎08-22-2011
My Device: 9700
My Carrier: 9700

Get Wifi Scan Result

Hi all,

Anybody tried the Wifi Service Library API?

 

I would like to create an application that be able to interact with Wi-Fi on blackberry 10.2 devices.

More specifically:

  • Passively react to scans
  • Iterate available hotspots and connect to a specified one
  • Save/edit/delete saved networks configurations

I tried the api,

I assume that i will get nearby wifi ssid using wifi_get_scan_results(),  and i can access the result in pointer:
wifi_scan_results_t **scan_results
 
But how i'm gonna read the content of **scan_resultsThere is no documentation about the content of wifi_scan_results_t
The docs just said that "wifi_scan_results_t  is an opaque structure of the Wi-Fi scan results"
 
Is there any sample to calling this api?
 
Kindy advise.
Thank you.

 

Please use plain text.
BlackBerry Development Advisor
jomurray
Posts: 118
Registered: ‎09-06-2010
My Device: Z30
My Carrier: Vodafone UK

Re: Get Wifi Scan Result

There is more information in this page: http://developer.blackberry.com/native/reference/core/com.qnx.doc.wifi_service.lib_ref/topic/wifi_ge... -- 

 

"The scan result entries can be decoded by looping from 1 to num_scan_entries and calling one of the functions prefixed with wifi_get_scan_result_ to extract the details of each scan result entry."

 

So, for example, you could extract the signal level using wifi_get_scan_result_signal_level()http://developer.blackberry.com/native/reference/core/com.qnx.doc.wifi_service.lib_ref/topic/wifi_ge...

---------------------------------------
Please refrain from posting new questions in solved threads.
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Found a bug? Report it here
Follow me on Twitter @jcmrim
Please use plain text.
New Contributor
yoginih
Posts: 9
Registered: ‎08-22-2011
My Device: 9700
My Carrier: 9700

Re: Get Wifi Scan Result

Hi jomurray,

Thank you.. I got that.. I missed that one.

 

Anyway berfore calling wifi_get_scan_results(), the docs said that 

" It should be called after a scan result event notification is received to retrieve the scan result list."

How can i receive those notification?

 

Is it using wifi_service_get_event_type() ?

If is it, how do i call that function? I dont understand how to pass the second parameter wifi_event_t

 

 

Kindly advise,

Thanks before.

Please use plain text.
BlackBerry Development Advisor
jomurray
Posts: 118
Registered: ‎09-06-2010
My Device: Z30
My Carrier: Vodafone UK

Re: Get Wifi Scan Result

This seems to be the basic pattern:

 

  1. Use wifi_service_initialize() to connect your application to the WiFi service - you get a handle to the WiFi servide that you use in subsequent calls
  2. Use the service handle and wifi_service_get_fd() to obtain a file descriptor for WiFi service events
  3. Use any of the standard techniques such as select(), poll() etc., to be notified of WiFi events
  4. When you receive a WiFi event use wifi_service_read_event() to get the event
  5. Use wifi_servce_get_event_type() to figure out what type of event it is ( http://developer.blackberry.com/native/reference/core/com.qnx.doc.wifi_service.lib_ref/topic/wifi_ev...)
  6. If it's a WIFI_EVENT_SCAN_RESULTS (http://developer.blackberry.com/native/reference/core/com.qnx.doc.wifi_service.lib_ref/topic/wifi_ev...) then you can retrieve the scan results
  7. Use wifi_get_scan_results() to obtain the scan results list
  8. Use wifi_get_scan_result_XXX() to get specific information
  9. Use wifi_free_scan_results() to free the result list
  10. Use wifi_service_shutdown() to clean up and release the handle to the WiFi service this also closes the file descriptor

 

---------------------------------------
Please refrain from posting new questions in solved threads.
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Found a bug? Report it here
Follow me on Twitter @jcmrim
Please use plain text.
New Contributor
yoginih
Posts: 9
Registered: ‎08-22-2011
My Device: 9700
My Carrier: 9700

Re: Get Wifi Scan Result

Thank you very much Jomurray, really appreciate the steps that you have given.
I have been trying that steps, but i'm stuck at step number 3.

 

I tried to use poll, the documentation shows:

 

			struct pollfd fds;
			fds.fd = fd;
			fds.events = POLLRDNORM;
			for (;;) {
			      if ((ret = poll(&fds, 1, -1)) == -1) {
			         perror("poll");
			         break;
			      }

			      else if (ret != 1 || (fds.revents & POLLRDNORM) == 0) {
			         break;
			      }

			      if (done_accept) {
			         if ((ret = read(s2, buf, sizeof(buf))) <= 0) {
			            break;
			         }

			         printf("%s", buf);

			      }
			      else {
			         if ((s2 = accept(s, NULL, 0)) == -1) {
			            perror("accept");
			            break;
			         }

			         fds.fd = s2;
			         done_accept = 1;
			      }
			   }

 

 

What fds.event that i should use? The sample is using 

fds.events = POLLRDNORM;

And when should i call

wifi_service_read_event() ?

 

Kindly advise,

I'am really new in cascades native programming.

 

Please use plain text.
BlackBerry Development Advisor
jomurray
Posts: 118
Registered: ‎09-06-2010
My Device: Z30
My Carrier: Vodafone UK

Re: Get Wifi Scan Result

Glad you've found this useful. I don't have a specific example related to WiFi but I've used the select() pattern in some other examples. The one that might be closest to what you're looking for is here in GitHub: 

 

https://github.com/blackberry/Cascades-Community-Samples/blob/master/Mqtt/src/MqttClientImpl.cpp

 

It's a library that I wrote that listens in a sub-thread on two file descriptors: 1) is a  TCP/IP socket() for network I/O, and; 2) the other is a  pipe() for interprocess communications. The same principle is involved as in the WiFi example where you get a file descriptor. I want to wake up when there is activity on either file descriptor and I use the select() API to wait for an event in the child thread.

 

You'll find the appropriate code around line 253. You can make use of the standard FD_SET and FD_ISSET macros to make it simpler to figure out what's woken you up in addition to the return code from select().

 

Hope this helps.

---------------------------------------
Please refrain from posting new questions in solved threads.
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Found a bug? Report it here
Follow me on Twitter @jcmrim
Please use plain text.