Pages: 1 [2]   Go Down
Author Topic: Change Power Level Xbee (series1)  (Read 2274 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

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.
Logged

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

I did the modiications on the code:
Code:
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 =/
Logged

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

Code:
  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.
Logged

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

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
Logged

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

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:
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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
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 is 1 character to read, read all 3 of them. Not a good idea.
Logged

Pages: 1 [2]   Go Up
Jump to: