Go Down

Topic: COnvert const char to hex (Read 3988 times) previous topic - next topic


Dude. post some code. for God's sake.

if you actually are sending Xbee commands in the format you speficied in your last comment-


Then that's wrong. I can't speak from personal experience as I have never used an XBee, but I've used a couple of other arduino shields that recieve AT commands (3G shield, cell shield) and I know that those commands have to be enclosed in quotes within the serial.println command
Code: [Select]



So, you can write

#define ATCMD "ATxxx"

and if a password is required as HEX you can write in define as hex
#define ATPWD "0A5E86"
my name is IGOR, not AIGOR


nid69ita your code works well. Just have some fails if you use number instead characters for password, something like this: "password11". I will try to solve it. Thank you.

I wrote XBee.println(ATKYWORD);, I already know it fails because it has not enclosure for ATKYWORD.

I have no problems to write password in define in hexadecimal but my program will be use by people who doesn't know what hexadecimal is, so I cannot do that. They can be able to write a word as their password and after that, program will convert it.

I have all my commands in defines so ATKY represents "atky" actually. WORD will be the password... I just meaned the way commands are sent to XBee.

I didn't post code just because I didn't have any code for that. I was trying to convert the sentence to start to do a function for that but I haven't the program yet.

Thank you.


Problem can be implicit conversion made by compiler.
Try with password with also number, like ABC123
Then add a simple Serial.println(c);
Code: [Select]

#include <stdio.h>  // for sprintf
MySend(WORD);    // c compiler see   MySend("textToConvert");
void MySend(char *pWord)
{ char buf[2];
  for(int i=0;i<=strlen(pWORD);i++)
  {  char c=*(pWord+i);  // single ascii value
     sprintf(buf,"%0x",c);// convert ascii value in hex
     obj.SendByte(buf[0]);    // I don't know command for send byte to xbee but I think you can send byte

If you see problems when show one numeric char, try using unsigned char or unsigned byte or also unsigned int.
Sample on internet about sprintf use only integer value.
my name is IGOR, not AIGOR


Nid69ita, I solved deleting '=' before strlen(pWord). Maybe it helps others...

Go Up