Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Sample android App that sends a message

Rank

Total Posts: 4

Joined 2014-09-30

PM

Hi everyone,

I'm new to ANT. I am trying to write a simple Android app that sends a simple message to a custom ANT enabled device that has nothing to do with fitness or GPS. I have downloaded the ANT Android SDK and have looked at some sample apps. They all seems to focus on fitness or GPS. I am wondering if there is other sample code around or if anyone can point me to good direction?

Many thanks!

Joanna      
Avatar
RankRankRankRank

Total Posts: 129

Joined 2010-11-30

PM

Hi Joanna,

Note that there is both an Android ANT SDK and an Android ANT+ SDK - in this case you want the Android ANT SDK.

In the Samples directory you will find the Acquire Channels Sample with source. This app shows how to acquire channels, configure them, and read/write messages. In this case it is the most basic form of messaging, broadcasting one byte from a master channel and receiving on a slave channel on a different phone. You can open as many channels (master or slave) as are available. A slave will search for a master with the same "channel number". The "Creating ANT Android Applications" document in the SDK provides more details.      
Rank

Total Posts: 4

Joined 2014-09-30

PM

Thanks so much rohan!      
Rank

Total Posts: 7

Joined 2014-10-13

PM

I am also trying to get this going, but ANTware is not picking up any transmissions and etc.

I have a microcontroller with ANT AP2. Currently ANTware picks up transmissions from the device.


I am using these settings:

//Establishing a Channel (Pg. 21 of ANT Message and Protocol 5.1)
 //Unassign Channel, just to be sure
 
data[0] 0x41//DATA  (Unassign Channel)
 
data[1] 0x01//DATA  (Channel Number)
 
ANT_SendPacket(data4);

 
//Assign Channel (type 0x10, 0x30, or 0x50)
 
data[0] 0x42//MSG ID (Assign Channel)
 
data[1] 0x01//DATA  (Channel Number)
 
data[2] 0x20//DATA  (Channel Type)
 
data[3] 0x00//DATA  (Network Number)
 
ANT_SendPacket(data4);

 
//Set Channel ID (Device#=1, Device type=1, Tran' type=1, Chan type = 0x10)
 
data[0] 0x51//MSG ID (Set Channel ID)
 
data[1] 0x01//DATA  (Channel Number)
 
data[2] 0x03//DATA  (Device Number LSB)
 
data[3] 0x00//DATA  (Device Number MSB)
 
data[4] 0x03//DATA  (Device Type)
 
data[5] 0x03//DATA  (Transmission type)
 
ANT_SendPacket(data6);
 
//ANT_SendPacket(data, 5);
 
 //Set Channel PERIOD
 
data[0] 0x43//MSG ID (Set Channel ID)
 
data[1] 0x01//DATA  (Channel Number)
 
data[3] 0x40//DATA  (Channel Period LSB)
 
data[2] 0x00//DATA  (Channel Period MSB)
 
ANT_SendPacket(data4);
 

 
//Open Channel
 
data[0] 0x4B//MSG ID (Open Channel)
 
data[1] 0x01//DATA  (Channel = 1)
 
ANT_SendPacket(data2); 


I am using the sample app described above, and I have tried to reconfigure it for myself:

// The device type and transmission type to be part of the channel ID message
    
private static final int CHANNEL_PROOF_DEVICE_TYPE 0x03;
    private static final 
int CHANNEL_PROOF_TRANSMISSION_TYPE 3;
    
    
// The period and frequency values the channel will be configured to
    
private static final int CHANNEL_PROOF_PERIOD 16384// 2 Hz
    
private static final int CHANNEL_PROOF_FREQUENCY 66


I should note that I am trying to configure a shared channel with the phone as my master.      
Rank

Total Posts: 7

Joined 2014-10-13

PM

I found part of my issue: I am using 2 byte shared addressing and the sample app was incrementing my address byte.

Now, I am able to pick up the packets from the phone in ANTware, but I can no longer see the data coming from my AP2 module. If I configure ANTware as a Master, it works again. I will set the phone to master again and try.

It appears as though setting it to master fails; it gives the message"!:No Device Found".

I included my log files, but I can't work on this any more tonight! Thanks for any help you can offer.      

File Attachments

Avatar
RankRankRankRank

Total Posts: 129

Joined 2010-11-30

PM

I'm not sure I understand your setup. Can you explain what you are trying to do with your AP2 device, ANTware and the modified Acquire Channels Sample on the phone? Are you trying to connect them all at the same time?

If the Acquire Channels Sample on the phone is configured as a slave it will show "!:No Device Found" when the search has timed out if there is no matching master. If the phone is configured as the master, it is not possible to get this as it is not searching for any devices.

The device number in your sample code (3) and logcat (2) do not match up.      
Rank

Total Posts: 7

Joined 2014-10-13

PM

AP2 is on a breadboard with an Atmega324P. ANTware I have set up in scanning mode so I could see what was going on while I try to use the phone, but I use it for testing(as a master) until I get the phone app working.

I want to make the AP2 the slave, and the phone as the shared channel master. with 2 address bytes. I may be misunderstanding, but I thought the phone was configured as a master when I switch the app to Rx mode? The device type is tied to the isMaster, and I was unable to find the code to set isMaster. There is the trivial manually setting it, but I wanted to keep the code "in tact" for reference and robustness.

I did not notice that, deviceNumber should be 03 I believe.

     
Rank

Total Posts: 7

Joined 2014-10-13

PM

I fixed deviceNumber, added a log on the phone so I could see what was going on. It is still not actually doing anything when I toggle to RX and open channel. Just times out, every single time.


Any ideas?

ninja edit: Had to rotate the picture because the forums don't allow 600x800... just 800x600.      

Image Attachments

Screenshot_2014-10-30-16-32-09.png

Click thumbnail to see full-size image

Avatar
RankRankRankRank

Total Posts: 129

Joined 2010-11-30

PM

Ddf.rathb - 30 October 2014 11:20 AM

I want to make the AP2 the slave, and the phone as the shared channel master. with 2 address bytes. I may be misunderstanding, but I thought the phone was configured as a master when I switch the app to Rx mode? The device type is tied to the isMaster, and I was unable to find the code to set isMaster. There is the trivial manually setting it, but I wanted to keep the code "in tact" for reference and robustness.


That is backwards. This app has a very simple communication protocol, where Tx is a master that broadcasts new data every message, and Rx is a slave that searches for a matching device number and displays what is received.

isMaster is based on the Tx/Rx button setting.

The shared channel setup you will need to add yourself.      
Rank

Total Posts: 7

Joined 2014-10-13

PM

Ah yes, sorry I forgot to correct that earlier. I have tried to set up the shared channel. I set the devicetype to 0x03, with transmission type to 0x03.

Not sure what I am missing here, sorry Rohan! I find it strange that even though I have set it as shared, the phone is able to communicate when not in shared mode.

Also, I have changed the ChannelType to Bidrectional shared master manually in the isMaster query. Still at a loss, I think it may be something small I am missing.


Edit: Solved my issue! It was something ridiculous. I was misrepresenting the address field and had the address in the first byte rather than the second byte in my shared address field. Thanks for your help Rohan, apologies for the simple problem!