Need to change XBee destination address
SEL
Posts: 80
I am new to using GCC. Perhaps someone would be kind enough to help me.
I am using an activity board with a series 1 xbee. The other is a propdemo board using sip xbee adapter, also series 1.
I can not change MY or DL address. Out of the box the two are communication; both are set to address 0. I need to change the DL address.
I have gone through the Learning GCC series of tutorials.
Any Help here would be great.
Here is my c code:
/*****************************************************************
*......File: SEL_Base_Node_v1_1.c
*
*...Purpose: Control a remote XBee Module
*
*......Date: 03/20/2014
*..Modified: 03/21/2014
*
*.....Notes:
*
*****************************************************************/
#include "simpletools.h" // Include simple tools
#include "fdserial.h" // Full-Duplex Serial
fdserial *xbee;
static void xbeeSetup();
int myAddr = 0x0;
int dlAddr = 0x3;
int main() // Main function
{
xbee = fdserial_open(1,0,0,9600);
pause(1000);
xbeeSetup(myAddr, dlAddr);
fdserial_txChar(xbee,'!');
fdserial_txChar(xbee,'1');
writeDec(xbee,13);
pause(5000);
fdserial_txChar(xbee,'!');
fdserial_txChar(xbee,'2');
writeDec(xbee,13);
pause(5000);
fdserial_txChar(xbee,'!');
fdserial_txChar(xbee,'3');
writeDec(xbee,13);
pause(100);
}
static void xbeeSetup(int myAddr, int dlAddr)
{
pause(3000);
fdserial_txChar(xbee,"+++");
pause(2000);
fdserial_rxFlush;
fdserial_txChar(xbee,"ATGT 3, CN");
writeDec(xbee,13);
pause(500);
fdserial_rxFlush;
pause(100);
fdserial_txChar(xbee,"+++");
pause(100);
fdserial_txChar(xbee,"ATMY\r");
writeHexDigits(xbee,myAddr,4);
writeDec(xbee,13);
fdserial_txChar(xbee,"ATCN\r");
writeDec(xbee,13);
pause(100);
fdserial_txChar(xbee,"+++");
pause(100);
fdserial_rxFlush;
fdserial_txChar(xbee,"ATDL\r");
writeHexDigits(xbee,dlAddr,4);
writeDec(xbee,13);
fdserial_txChar(xbee,"ATCN\r");
writeDec(xbee,13);
pause(100);
}
I am using an activity board with a series 1 xbee. The other is a propdemo board using sip xbee adapter, also series 1.
I can not change MY or DL address. Out of the box the two are communication; both are set to address 0. I need to change the DL address.
I have gone through the Learning GCC series of tutorials.
Any Help here would be great.
Here is my c code:
/*****************************************************************
*......File: SEL_Base_Node_v1_1.c
*
*...Purpose: Control a remote XBee Module
*
*......Date: 03/20/2014
*..Modified: 03/21/2014
*
*.....Notes:
*
*****************************************************************/
#include "simpletools.h" // Include simple tools
#include "fdserial.h" // Full-Duplex Serial
fdserial *xbee;
static void xbeeSetup();
int myAddr = 0x0;
int dlAddr = 0x3;
int main() // Main function
{
xbee = fdserial_open(1,0,0,9600);
pause(1000);
xbeeSetup(myAddr, dlAddr);
fdserial_txChar(xbee,'!');
fdserial_txChar(xbee,'1');
writeDec(xbee,13);
pause(5000);
fdserial_txChar(xbee,'!');
fdserial_txChar(xbee,'2');
writeDec(xbee,13);
pause(5000);
fdserial_txChar(xbee,'!');
fdserial_txChar(xbee,'3');
writeDec(xbee,13);
pause(100);
}
static void xbeeSetup(int myAddr, int dlAddr)
{
pause(3000);
fdserial_txChar(xbee,"+++");
pause(2000);
fdserial_rxFlush;
fdserial_txChar(xbee,"ATGT 3, CN");
writeDec(xbee,13);
pause(500);
fdserial_rxFlush;
pause(100);
fdserial_txChar(xbee,"+++");
pause(100);
fdserial_txChar(xbee,"ATMY\r");
writeHexDigits(xbee,myAddr,4);
writeDec(xbee,13);
fdserial_txChar(xbee,"ATCN\r");
writeDec(xbee,13);
pause(100);
fdserial_txChar(xbee,"+++");
pause(100);
fdserial_rxFlush;
fdserial_txChar(xbee,"ATDL\r");
writeHexDigits(xbee,dlAddr,4);
writeDec(xbee,13);
fdserial_txChar(xbee,"ATCN\r");
writeDec(xbee,13);
pause(100);
}
Comments
I think the following is incorrect (and the same for setting MY):
That will actually send the two ascii chars \r that shouldn't be there. To set DL=$abcd, the modem has to receive the string just as if you had typed it in on a terminal.
ATDL abcd <CR>
Don't send the 13=<CR> as a decimal value. It has to be the single byte of value decimal 13.
In Spin the following would set MY=1, DL=2, writes it to the XBee eeprom so that it will be restored after power cycling.
fds.str(string("AT MY1 DL2 WR CN",13))
Separating individual AT commands with <CR> is optional, or with repeated +++.
I tried all your suggestions, but could not change address.
I need a code example written in C. I have googled for such an example and could find nothing. All wanted to us X-CTU. I have changed the address using that application. That is a hard wire solution. I need a software solution.
Once again any help would be so appreciated!
Stan
Here is the code:
static void xbeeSetup(myAddr, dlAddr)
{
char thisByte = 0;
dprint(xbee,"+++");
while(thisByte != 'K')
{
thisByte = fdserial_rxCheck(xbee);
if(thisByte != -1 )
{
thisByte = fdserial_rxChar(xbee);
}
}
dprint(xbee,"ATDL0\r");
dprint(xbee,"ATMY0\r");
dprint(xbee,"ATCN\r");
}
I have to work out: how to use itoa(xbee, myAddr, ?) or something like it. It is hard not knowing that much about C, but I am learning.
The third parameter of itoa I have no clue as what I need there.
char myA = itoa(xbee,myAddr, ?) ;
Stan
Serial-I-O-with-Propeller-C-code
Stan
#include "simpletools.h" // Include simple tools
#include "fdserial.h" // Full-Duplex Serial
fdserial *xbee;
static void xbeeSetup();
static void flashLeds(void);
char myAddr = 0x1;
char dlAddr = 0x0;
int main() // Main function
{
xbee = fdserial_open(1,0,0,9600);
int dataIn;
xbeeSetup(myAddr, dlAddr);
while(1)
{
dataIn = 0;
dataIn = fdserial_rxChar(xbee);
if (dataIn == '!')
{
dataIn = fdserial_rxChar(xbee);
switch(dataIn)
{
case '1':
high(23);
break;
case '2':
low(23);
break;
case '3':
flashLeds();
break;
}
}
}
}
static void xbeeSetup(int myAddr, int dlAddr)
{
char thisByte = 0;
char xx[10];
char my[10] = "ATMY";
char dl[10] = "ATDL";
itoa(myAddr,xx,10);
strcat(my,xx);
itoa(dlAddr,xx,10);
strcat(dl,xx);
strcat(dl,"\r");
strcat(my,"\r");
dprint(xbee,"+++");
while(thisByte != 'K')
{
thisByte = fdserial_rxCheck(xbee);
if(thisByte != -1 )
{
thisByte = fdserial_rxChar(xbee);
}
}
dprint(xbee,my);
dprint(xbee,dl);
dprint(xbee,"ATCN\r");
}
static void flashLeds(void)
{
for (int i=0; i<4; i++)
{
high(16);
pause(500);
low(16);
pause(500);
high(23);
pause(500);
low(23);
pause(500);
}
low(16); low(23);
}