Pages: [1]   Go Down
Author Topic: programming API frames  (Read 969 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi everyone

I want to control a LED on pin D1 of a remote XBEE via a coordinator on a arduino Etherten.

I put one xbee in router AT mode and the other xbee in coordinator API mode (api=1)

now I managed to construct the API frames I need to turn the routers D1 on and off and I confirmed it works using X-CTU

Router D1-on
7E 00 10 17 01 00 13 A2 00 40 79 5F 90 FF FE 02 44 31 05 11
router D1-off
7E 00 10 17 01 00 13 A2 00 40 79 5F 90 FF FE 02 44 31 04 12

I was sending those commands having the xbees attached to separate USB adapters and it worked flawlessly, the coordinator sends the frames and the router responds appropriately.

now the problem I am having is I wrote a arduino program to simply send those API frames via my Etherten to the coordinator that sits on top of a sparkfun xbee shield.

but it does nothing, I see the Din flashing on the xbee shield and Di05(associate) but the router is not getting anything and with the router plugged into a computer with X-CTU terminal monitoring open it shows no data coming in and the LED does not activate.

I have pasted my code below please if anyone can figure out what I have done wrong let me know


//#include <Wire.h>



String Router_on ="7E 00 10 17 01 00 13 A2 00 40 79 5F 90 FF FE 02 44 31 05 11 ";
String Router_off ="7E 00 10 17 01 00 13 A2 00 40 79 5F 90 FF FE 02 44 31 04 12 ";

void setup()
{
  Serial.begin(9600);
 delay(5000);
}

void loop(){
   
  Serial.println(Router_on);
  delay(2000);
  Serial.println(Router_off);
  delay(2000);
 
 
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46240
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The values in the packet are binary values, not ASCII values, and there are no spaces between the values. Ditch the String class, now.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The values in the packet are binary values, not ASCII values, and there are no spaces between the values. Ditch the String class, now.

thank you for the reply mate.

what would you recommend in place of the string class and am I to transmit those frames in its binary format? because using xctu they go through just fine and work.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46240
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
because using xctu they go through just fine and work.
Because X-CTU is converting the string to bytes and stripping the spaces. You need to do the same:

Code:
byte packet[] = { 0x7E, 0x00, 0x10, 0x17, 0x01, 0x00, 0x13, 0xA2, 0x00, 0x40,
                          0x79, 0x5F, 0x90, 0xFF, 0xFE, 0x 02, 0x44, 0x31, 0x05, 0x11 };
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

excellent thank you, i'lll give it a shot now

thanks for your help.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
because using xctu they go through just fine and work.
Because X-CTU is converting the string to bytes and stripping the spaces. You need to do the same:

Code:
byte packet[] = { 0x7E, 0x00, 0x10, 0x17, 0x01, 0x00, 0x13, 0xA2, 0x00, 0x40,
                          0x79, 0x5F, 0x90, 0xFF, 0xFE, 0x 02, 0x44, 0x31, 0x05, 0x11 };

hey I just tried that it and it generated an error "call of overloaded 'print(byte[20]' is ambiguous"

does that mean the byte class is too small for a array of that size?

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46240
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
does that mean the byte class is too small for a array of that size?
byte isn't a class.

Quote
"call of overloaded 'print(byte[20]' is ambiguous"
means that there was one or more methods that are not an exact match for the call you are trying to make. The compiler then showed you some options. The most likely one that you want to use is the one where you admit that the compiler can't figure out when to stop sending data in the array without you telling it how big the array is. So, tell it how big the array is.

Code:
Serial.print(packet, 20);
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OMG it works smiley-grin

at first I tried making it step through the array index and that worked but it was  unnecessarily complicated.

I had to use Serial.write(packet,20); instead as Serial.print(packet, 20) was still causing that problem.

Quote
//#include <Wire.h>

//frame for router D1 on 
byte Router_on[] = {0x7E,0x00,0x10,0x17,0x01,0x00,0x13,0xA2,0x00,0x40,0x79,0x5F,0x90,0xFF,0xFE,0x02,0x44,0x31,0x05,0x11};
//Frame for router D1 off
byte Router_off[] ={0x7E,0x00,0x10,0x17,0x01,0x00,0x13,0xA2,0x00,0x40,0x79,0x5F,0x90,0xFF,0xFE,0x02,0x44,0x31,0x04,0x12};


void setup()
{
  Serial.begin(9600);
 delay(5000);//delay of 5 seconds to ensure router and coordinator are joined to each other
 //delay not entirely necessary
}

void loop(){
   //after various trials serial.print(Router_on,20); kept causing the overloaded ambiguous error
   //Serial.write(Router_on,20); does it with no problems
   //the 20 tells the compiler how long the array is
   //Thank you PaulS from the Arduino forum for helping with this
   
  Serial.write(Router_on, 20);
  delay(2000);
  Serial.write(Router_off, 20);
  delay(2000);
  
  
}



Thank you very much PaulS you have saved me from alot of stress

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46240
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
OMG it works
Yeah!
Logged

India
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a lot Turkeybaster and PaulS....your Question and your answer respectively smiley-wink, helped me tremendously. thanks a LOT smiley-grin
Logged

Pages: [1]   Go Up
Jump to: