Turning Multiple ASCII Values into a variable

Hi I have a problem in Arduino programming. as the title suggest I want to be able to convert multiple ascii representation into a single vairable so that i could used that variable in my gsm module to text it what that certain variable shows. Plss I need help in this

Here is my sample code:

Serial.println();
        for (int i= 0; i < rx.getDataLength(); i++){
          Serial.write(' ');
          if (iscntrl(rx.getData()[i]))
            Serial.write(' ');
          else
            Serial.write(rx.getData()[i]);
          Serial.write(' ');
        }

from the code I clearly got a data wirelessly from an xbee transmitter, the problem is its output is all in Hexadecimal and ascii representation using the for loop to obtain the data, I do not know how to convert this result into a variable so that I could use it in my output in this case in my gsm module to text that certain data to my subscribers plss I need help in this

Here is the Output of my code in Serial monitor:

avoid images of screen dumps
could you upload the serial monitor output as text ?
of the sample output what value do you wish to extract into a variable

1 Like

This is the output in Text

Received Data:
43 72 69 74 69 63 61 6C 21 20 4E 6F 64 65 20 31 3A 20 38 37
C r i t i c a l ! N o d e 1 : 62 Setting the GSM in text mode

Of the sample Output I just wanted to extract Critical ! Node 1: 62 which I believe was obtain using the for loop code shown above. Convert this into a variable or a string so that I could use it in my gsm Module.

looking at the XBee documentation getData() method

	// Returns the payload array.  This may be accessed from index 0 to getDataLength() - 1
        uint8_t* getData();

you therefor have the text "Critical!Node1:62" in an array variable pointed to by rx.getData()
try

   Serial.println(rx.getData());

should print "Critical!Node1:62" to the Serial Monitor
you can then pass it to the GSM modem

what do you want to convert to a "variable"? the Node values: the 1 and the 62?

if so, consider
Output:

Critical! Node 1: 87
 a 1, b 87
const char t [] = {
    0x43, 0x72, 0x69, 0x74,  0x69, 0x63, 0x61, 0x6C,
    0x21, 0x20, 0x4E, 0x6F,  0x64, 0x65, 0x20, 0x31,
    0x3A, 0x20, 0x38, 0x37,  0 };

void
setup (void)
{
    Serial.begin (9600);
    Serial.println (t);

    int a;
    int b;
    sscanf (t, "Critical! Node%d:%d", &a, &b);

    Serial.print   (" a ");
    Serial.print   (a);
    Serial.print   (", b ");
    Serial.println (b);
}

void loop (void) { }

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.