Pages: 1 [2]   Go Down
Author Topic: COnvert const char to hex  (Read 1047 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

if you actually are sending Xbee commands in the format you speficied in your last comment-
Quote
XBee.println(ATKYWORD);

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
i.e.
Code:
XBee.println("ATKYWORD");
Logged

ivrea (to)
Offline Offline
Faraday Member
**
Karma: 86
Posts: 4946
miaaao ^-^
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, you can write

#define ATCMD "ATxxx"
...
XBee.println(ATCMD);

and if a password is required as HEX you can write in define as hex
#define ATPWD "0A5E86"
XBee.println(ATPWD);
Logged

my name is IGOR, not AIGOR

Offline Offline
Full Member
***
Karma: 1
Posts: 104
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

ivrea (to)
Offline Offline
Faraday Member
**
Karma: 86
Posts: 4946
miaaao ^-^
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Problem can be implicit conversion made by compiler.
Try with password with also number, like ABC123
Then add a simple Serial.println(c);
Code:
#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
     Serial.println(c);
     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
     obj.SendByte(buf[1]);
  }
}
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.
Logged

my name is IGOR, not AIGOR

Offline Offline
Full Member
***
Karma: 1
Posts: 104
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: 1 [2]   Go Up
Jump to: