Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Android: Have app control discovery & desired pairing using new ANT+ Plugins?

Rank

Total Posts: 2

Joined 2013-09-07

PM

Hello,

starting work on an eduction/research project (an Android sports app that deals with multiple athletes each using multiple ANT+ sensors) , I am still trying to understand the basics regarding approach and feasibility:

1) Are the new ANT+ Plugins the preferred go-foward method for developing ANT+ apps for Android?

2) If yes, how can we control discovery and pairing from "_within_" our app (using the Plugins)?

a) Is the recommended method to use the AntPluginPcc ("ANT+ Plugin Manager")? Will this allow the athlete to rescan and re-pair if required, but on the other hand allow auto-pairing unobtrusively when the desired pairing has been achieved initially or repeatedly due to a sensor exchange (imagine there are 6 heart rate Monitors in close proximity...)? Is there a way (sample code?) to integrate the pairing more seamlessly into the app UI flow? Perhaps an API to manage saved/preferred sensors (is there doc on this?)?

b) Or do we need to do this the "old" (much more complex) way ... in that case, please, where could I find the source for the ANT+ Demo" app that is on the Play Store (coudn't find it in the SDK)?

Thanks a lot and apologies for this wordy post.

Regards,
Mat      
Avatar
RankRankRankRank

Total Posts: 745

Joined 2012-09-14

PM

Hi,

Is your main limitation that you need to save multiple devices of the same type?

1) Yes, the ANT+ Plugins are the preferred method to go as besides offering a much higher level interface, they also confer other advantages such as concurrent multi app access to ANT+ devices and dramatic simplification of ANT+ Certification.

2) There are a few methods in the plugins to handle device discovery and pairing.
i) requestAccess() by default will load the built-in pairing screen from which users can select devices and save the device they always want to pair to. This default pairing screen also includes a proximity search option so users can use relative distance to find nearby devices.
ii) If you need to implement your own pairing UI, you may use the AsyncScanController to receive connected/found devices and display them as you wish. A sample on how to use this method is provided for heart rate in the Plugin Sampler.

a) The ANTPluginPcc class itself is not intended for direct use, and is the base class for the AntPlus___Pcc classes, which provide your interface to each specific ANT+ device (heart rate, SDM, etc).
If you cannot use the in-built pairing UI/saved devices database, then you may overload the requestAccess() using a specified device number which you save from previous pairing attempts using your own better integrated pairing UI to tell the PCC which device it should attempt to connect to, bypassing the in-built pairing UI.
There is an in-built Plugin Manager which the user can use to change paired devices in the database and which ones are preferred (to connect automatically to if requested). Currently there is no programmatic way to access the device database directly, but this functionality is on the roadmap to be added in a future update.

If you're attempting to save multiple device numbers of the same type(s), the easiest approach at the moment would be to initially let the user connect to the devices through the pairing screen, use getDeviceNumber() and store the device numbers, and when the user wants to re-connect, either use the AsyncScanController to find the devices, and call requestAccess(...,deviceNumberToPairTo) (or just call this without the AsyncScanController, but you will only know if the device is not present when there is a search timeout).

Cheers      
Rank

Total Posts: 2

Joined 2013-09-07

PM

Hi - this is indeed a helpful reply (and good news, I gather from a quick read) - allow us to look into the provided detail and test it in the coming weeks.

And, yes, we do face the situation were we may have multiple similar sensors.

Thanks,
best regards,
Mat      
Rank

Total Posts: 8

Joined 2013-09-09

PM

Hello,

I'm also working on that eduction/research project and I'm trying to understand the thing with the AsyncScanController.

Harrison - 12 September 2013 11:37 AM

ii) If you need to implement your own pairing UI, you may use the AsyncScanController to receive connected/found devices and display them as you wish. A sample on how to use this method is provided for heart rate in the Plugin Sampler.


Does that mean that I can build my own UI with that? If so, where can I find an example code because I really don't understand how the AsyncScanController works and how to implement it into my UI.

Regards,
Armin      
Avatar
RankRankRankRank

Total Posts: 745

Joined 2012-09-14

PM

Hi,

Yes, you may find example code in the ANT+ Plugin Sampler called the "Async Scan Demo" in the main UI.
The ANT+ Plugin Sampler source code can be found in the Android ANT+ SDK on the Downloads page.

The pertinent package would be under com.dsi.ant.antplus.pluginsampler.heartrate and you will be most interested in the Activity_AsyncScanHeartRateSampler.java source file.

Effectively, instead of requestAccess which would call the built-in UI, you call requestAsyncScanController, in which you implement your own IAsyncScanResultReceiver. You can then do whatever you like with the search results, in the example case it adds them to a list of scanned devices which is displayed to the user to click on.

Cheers      
Rank

Total Posts: 8

Joined 2013-09-09

PM

Hi,

Thanks for the information!
But when I try to run the AntPlusPluginSampler the program crashes with this:
09-28 12:04:30.060W/dalvikvm(2082): threadid=1thread exiting with uncaught exception (group=0x2b542210)
09-28 12:04:30.070E/AndroidRuntime(2082): FATAL EXCEPTIONmain
09
-28 12:04:30.070E/AndroidRuntime(2082): java.lang.NoClassDefFoundErrorcom.dsi.ant.plugins.antplus.pccbase.AntPluginPcc
09
-28 12:04:30.070E/AndroidRuntime(2082):  at com.dsi.ant.antplus.pluginsampler.Activity_Dashboard.onCreate(Activity_Dashboard.java:91)
09-28 12:04:30.070E/AndroidRuntime(2082):  at android.app.Activity.performCreate(Activity.java:4465)
09-28 12:04:30.070E/AndroidRuntime(2082):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
09-28 12:04:30.070E/AndroidRuntime(2082):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
09-28 12:04:30.070E/AndroidRuntime(2082):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
09-28 12:04:30.070E/AndroidRuntime(2082):  at android.app.ActivityThread.access$600(ActivityThread.java:127)
09-28 12:04:30.070E/AndroidRuntime(2082):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
09-28 12:04:30.070E/AndroidRuntime(2082):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-28 12:04:30.070E/AndroidRuntime(2082):  at android.os.Looper.loop(Looper.java:137)
09-28 12:04:30.070E/AndroidRuntime(2082):  at android.app.ActivityThread.main(ActivityThread.java:4441)
09-28 12:04:30.070E/AndroidRuntime(2082):  at java.lang.reflect.Method.invokeNative(Native Method)
09-28 12:04:30.070E/AndroidRuntime(2082):  at java.lang.reflect.Method.invoke(Method.java:511)
09-28 12:04:30.070E/AndroidRuntime(2082):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-28 12:04:30.070E/AndroidRuntime(2082):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-28 12:04:30.070E/AndroidRuntime(2082):  at dalvik.system.NativeStart.main(Native Method

How can I fix this error?

Best regards,
Armin      
Avatar
RankRankRankRank

Total Posts: 129

Joined 2010-11-30

PM

The info in this post should help.      
Rank

Total Posts: 8

Joined 2013-09-09

PM

I'm able to connect to a HeartRate sensor.

Does the same sample code work also for a Footpod?
Can I do a search action for a heartrate and a footpod at the same time? (usefull for autoconnect to more than one device at the startup for example)

Best regards,
Armin      
Avatar
RankRankRankRank

Total Posts: 745

Joined 2012-09-14

PM

Hi,

The sample code will work for all of the search based PCC's (except Controllable Devices as they do not search but broadcast instead).

Yes, you may search for any number of ANT+ devices simultaneously including on Android as explained in app note AN15 - Multi Channel Design Considerations.

ANT has the ability to perform parallel searches on multiple channels, but only if all the searches are on the same network and the same RF frequency.


Cheers      
Rank

Total Posts: 8

Joined 2013-09-09

PM

Hi,

thanks for the help!

I have another question: Is there a possibility to get the range/distance of how a far away the device is from my phone? (For the searching UI, to show the user which device is the closest to the phone)

Best regards,
Armin      
Avatar
RankRankRankRank

Total Posts: 745

Joined 2012-09-14

PM

Hi Armin,

You are very welcome.

At this moment the only way to set relative proximity or range is through the requestAccess function, where you can set proximity bins. In this case you'd have to call requestAccess with incrementally larger proximity bins to acquire devices closest to the user.

The AsyncScanController does not currently pass proximity/RSSI information but is planned to be added in a future release.

Cheers      
Rank

Total Posts: 8

Joined 2013-09-09

PM

Hi Harrison,

thank you so far!
If I run into another problem or question I'll report it here.

Best regards,
Armin      
Rank

Total Posts: 3

Joined 2016-11-08

PM

Hi, I encountered the same problem as you.

log as follow:

FATAL EXCEPTION: main
09-28 12:04:30.070: E/AndroidRuntime(2082): java.lang.NoClassDefFoundError: com.dsi.ant.plugins.antplus.pccbase.AntPluginPcc
09-28 12:04:30.070: E/AndroidRuntime(2082): at com.dsi.ant.antplus.pluginsampler.Activity_Dashboard.onCreate(Activity_Dashboard.java:91)
09-28 12:04:30.070: E/AndroidRuntime(2082): at android.app.Activity.performCreate(Activity.java:4465)
09-28 12:04:30.070: E/AndroidRuntime(2082): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
09-28 12:04:30.070: E/AndroidRuntime(2082): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
09-28 12:04:30.070: E/AndroidRuntime(2082): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
09-28 12:04:30.070: E/AndroidRuntime(2082): at android.app.ActivityThread.access$600(ActivityThread.java:127)
09-28 12:04:30.070: E/AndroidRuntime(2082): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
09-28 12:04:30.070: E/AndroidRuntime(2082): at android.os.Handler.dispatchMessage(Handler.java:99)
09-28 12:04:30.070: E/AndroidRuntime(2082): at android.os.Looper.loop(Looper.java:137)
09-28 12:04:30.070: E/AndroidRuntime(2082): at android.app.ActivityThread.main(ActivityThread.java:4441)
09-28 12:04:30.070: E/AndroidRuntime(2082): at java.lang.reflect.Method.invokeNative(Native Method)
09-28 12:04:30.070: E/AndroidRuntime(2082): at java.lang.reflect.Method.invoke(Method.java:511)
09-28 12:04:30.070: E/AndroidRuntime(2082): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-28 12:04:30.070: E/AndroidRuntime(2082): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-28 12:04:30.070: E/AndroidRuntime(2082): at dalvik.system.NativeStart.main(Native Method)



How do you solve this problem? would you provide some solutions?

best regards!
thank you