Type encoding issue when sending data

Dear All,

I'm trying to make a Mega ADK speak with my Galaxy Tablet 7", Android 4.1.2, following the instructions provided by the WROX book "professional Android Open Accessory with Arduino", explaining the explementation on the Android Open Accessory (AOA). After several mail exchange with the author (aoabook · GitHub) and original bug fixing, I'm arrived at the point that the Mega ADK "send sometrhing" via USB to Android, and the tablet "shows something" on the screen. The headaching issue have now is the correct way of encoding / entyping the data I want to send from the ADK via USB and to have it shown on the tablet screen. Please give a look to the code below, with focus on the payload field (pub is of a variable type P2PMQTTpublish):

    pub.fixedHeader = 48;
    pub.length = 5;
    pub.lengthTopicMSB = 0;
    pub.lengthTopicLSB = 2;
    pub.topic = (byte*) "ts";
//    pub.payload = (byte*) "ciao";
//    pub.payload = (byte*)  char(analogRead(A2)>>2);
    mqtt.publish(pub);

where the fields of the P2PMQTTpublish data type are defined in an .h file as follows:

  // P2PMQTT PUBLISH package
  typedef struct {
    // Fixed header
    byte fixedHeader;
    byte length; // this has to change to be a byte array
    // Variable Header
    byte lengthTopicMSB;
    byte lengthTopicLSB;
    byte * topic;
    byte * payload;
  } P2PMQTTpublish;

My problem is this one. I want to read a potentiometer on, for instance A2 input, and pass the red value to the tablet via USB; The only data type that I manage to pass succesfully is char in the form pub.payload = (byte*) "ciao";. Here for instance,, the "ciao" passes nicely (here I'm only interested in the first character, the 'c'). Even in this format char(analogRead(A2)>>2), it doesn't pass correctly. If I cast the analogRead(A2) to int, byte or anything else, what passes is wrong.
I wrote down some lines to see which array of char is passed through the Serial. The payload that I see on teh Serial is the same one that I se on the Tablet. So I think the problem is in the encodicg on the Arduino side.
I think for now it's enough, then I have anothe "cherry" I will take for the next post. Any Idea Sirs?
tnx
Andrea

Convert the analog value to a character string, for example using the function itoa() http://www.cplusplus.com/reference/cstdlib/itoa/

Tnx a lot, I'll try and make you know