Send data to xbee (SE firmware)

I have a program (C language) to send and receive a string to the serial port.

I create too a list of commands I have to send and obtain in order to create the network and join a end device to it.
For example, I need to get the SH and SL value of the end device in order to joining to the network, sending a ATcommand to the end device.

struct ATcommand_get_SH{
unsigned char start_delimiter = 0x7E;
unsigned char length = 0x0004;
unsigned char frame_type = 0x08;
unsigned char frame_ID = 0x01;
unsigned char at_command = 0x5348;
unsigned char checksum = 0x5B;
};

char *ATcommand_get_SH= “7E0004080153485B”

My question is:
The ATcommand I need to send is a string right? which format I have to send it?
“7E0004080153485B”
“0x7E0004080153485B”

Thanks in advance.

It needs Intel Hex so the 0x data.

2 Likes

I built this code using a proper functions.
This code works if:
1- I send to the arduino a char *ATcommand_set_ID;
2- Arduino replies what he receives;
3- I receive (on PC) what arduino sends in variavel *ler.

So If I try to send this char *ATcommand_set_ID and he really change the ID, he should return “0x7E00058801494400E9” indicating that everything is ok. The ID do not change because I see on the XCTU software and the variable ler does not return anything useful.

int main()
{
int ser;
int i=0,j=0,len=0;
int w=0,r=0,c=0,conf=0;
char *ATcommand_set_ID= “0x7E000608014944223512”;
int length = strlen (ATcommand_set_ID);
char *ler= calloc(18, sizeof(char));
const char *serialdevice=“/dev/ttyS7”; //COM8

// Open serial port
ser=serial_open(serialdevice);
printf("serial:%d

",ser);

// Config
conf=serial_config(ser,DEF_BAUDRATE,DEF_CHAR_SIZE,DEF_STOP_BITS,DEF_PARITY);
printf("config:%d

",conf);

usleep(1500000);

// Write
w=serial_write(ser,ATcommand_set_ID,length);
printf("write_size:%d|%d

",w,length);

usleep(1500000);

while (i<3)
{
	printf("i=%d

",i);

	// Read serial_read(ser,ler,length_MAX,timeout);
	r=serial_read(ser,ler,30,2);
	len= strlen(ler);
	ler[len]=0; // end string
	if (r>0)
		printf("read: %s | r: %d | len=%d

",ler,r,len);
else
printf("not read
");
i++;
usleep(1000000);

}

// close serial port
c=serial_close(ser);
printf("close:%d

",c);
}

Are there anything wrong? Or simply I need to send a (int *) instead a string?

Thanks

You need to issue the WR comamnd or the AC command for the change to take effect.