Go Down

Topic: Change Power Level Xbee (series1) (Read 2 times) previous topic - next topic

acintra

Ok I will change that, but yet the command +++ is not returning the "OK", even if a only use that in void setup(), like it:

void setup()
{
Serial.begin(9600);
Serial.print("+++");
}

Checking it on T Term the command OK isn't returned.

acintra

I did the modiications on the code:
Code: [Select]

char str[5] = "OK";

void setup ()
{
  Serial.begin(9600);
 
  Serial.print("+++");
  delay(3000);
  if((int)Serial.read()==(int)str){
  Serial.println("ATPL");
  delay(1000);
  if(Serial.read()>=3){
  Serial.println("ATPL 2");
  delay(1000);
  Serial.println("ATPL");
  }
  }
}

void loop ()
{

 
}



Still... Not working =/

PaulS

Code: [Select]
  if((int)Serial.read()==(int)str){
There are so many problems with this one statement...

str is a character array, containing "OK". How can you possibly cast that to an int?

Serial.read() reads ONE byte. That might be 'O'. It might be 'K'. Or, because you haven't made sure that there is actually anything to read, it might return -1. In any case, (-1, 'O', or 'K', or something other SINGLE character), it is impossible for that to equal "OK", no matter how you plead with the compiler to make it so.

faludi

This won't fix anything but it will make your code run faster. The guard time around the +++ is 1000ms by default. So I usually only delay for 1010ms (an extra 10 just to be safe) before moving on. This works fine.

Also, check some of my pretty old sample code for a kinda dumb but easy to read function for checking the OK in command mode: http://www.faludi.com/itp_coursework/meshnetworking/XBee/XBee_Send_Example.pde

acintra

Faludi I tried to do one function to see if the xbee returns "OK" based on your code (char returnedOK () ).
But i'm still don't receiving the ok, and when I connect the xbee to the Xbee Xplorer USB to check in X-CTU if something have changed, I didn't see any change of the previously configuration.
The code is that:
Code: [Select]

void setup ()
{
  Serial.begin(9600);
 
  Serial.print("X");
  delay(1100);
 
  Serial.print("+++");
  delay(1100);
   if (returnedOK() == 'T') {
  }
  else {
    setup();
  }
 
  Serial.println("ATPL3");

  Serial.println("ATPL");

  }

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;
}


I'm really in doubt now if the xbee connected to an xbee shield could change your configurations without I have to use a Xbee Xplorer USB.

PaulS

Code: [Select]
    if (Serial.available() > 1) {
   
      for (int i=0; i<3; i++) {
        incomingChar[i] = Serial.read();
      }

If there is 1 character to read, read all 3 of them. Not a good idea.

Go Up