Pages: [1]   Go Down
Author Topic: Don't receiving confirmation of the changes from the xbee  (Read 495 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

   Hello guys, some time ago I did a post about of changing the power level of the xbee. Now I want to prove that changing.
   I'm using one xbee series 1 connected to one xbee shield and one arduino duemilanove.
   And I use one Xbee USB Xplorer to do readings on the X-CTU.

   I'm using the following code to change the power level of the xbee:

Code:
void setup ()
{
  Serial.begin(9600);
 
  Serial.print("X");
  delay(1100);
 
  Serial.print("+++");
  delay(1100);
   if (returnedOK() == 'T') {
  }
  else {
    setup();
  }
 
  while(returnedOK() != 'T'){
  Serial.println("ATPL 3");
  delay (1000);
  }
  Serial.println("ATPL");
  delay(1000);
 
  Serial.println("CN");

  }

void loop ()
{
 
 
}


char returnedOK () {
  char incomingChar[3];
  char okString[] = "OK";
  char result = 'n';
  int startTime = millis();
  while (millis() - startTime < 2000 && result == 'n') { 
    if (Serial.available() > 1) {
   
      for (int i=0; i<3; i++) {
        incomingChar[i] = Serial.read();
      }
      if ( strstr(incomingChar, okString) != NULL ) {

        result = 'T';
      } 
      else {
        result = 'F';
      }
    }
  }
  return result;
}

   As can be seen by the code I'm using the function returnedOK to test if the byte was received and continue the changes.
   But after all the steps have been completed, I disconnect the xbee from the shield and I connect the xbee to the USB xplorer and I look in the X-CTU to see the power level change. But that isn't changed (continues 4 - standard).
    I want to know why it isn't changing since I'm receiving the confirmation byte.
Thanks
Logged

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

Code:
    if (Serial.available() > 1) {
   
      for (int i=0; i<3; i++) {
        incomingChar[i] = Serial.read();
      }
If there are 2 bytes, read all three of them. Hmmm... Fail!

Code:
      if ( strstr(incomingChar, okString) != NULL ) {
You can't pass a non-string to a string function. Fail!

A string is a NULL terminated array of chars. All you have is an array of chars, which is NOT a string.
Logged

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


When you disconnect the XBee shield and connect it to the USB explorer, you power cycle the XBee.  When you power cycle the XBee everything reverts to what is stored in NVRam.  If you want to make the values permanent, use the WR command.  However, the NVRam on the XBee can only handle a limited number of writes.  So be sure you want to write the data before you do so.  Usually, you only do a write once during initial provisioning.
Logged

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

I was thinking that we need to count the null character so i put 3, "o"+"k"+"NULL".
But now i changed to 2.
And the incomingchar is filled in with O+K so it became a String.
Logged

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

Quote
And the incomingchar is filled in with O+K so it became a String.
No, it doesn't. You don't append the NULL, so you don't have a string.
Logged

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

Thanks rossb I put the ATWR command on the end of input and it worked well.
Thanks all of you guys, you helped me a lot.
Logged

Pages: [1]   Go Up
Jump to: