Problems with Serial

Well, i’m doing a little proyect conecting a web server to an arduino with a ethernet shield and a xbee shield ( named gateway ) and then to another arduino with a xbee shield (named final )that just runs a led in… well i made that the server could send strings with information to the gateway perfectly, but when i try to make the gateway recieve information ( strings ) from the final and answer to it with another string, the Serial doesn’t allow me to send the new string… like in the next code:

if (Serial.available() > 0){ // if the serial has anything to recieve
char l = (char)Serial.read(); // get it into a char variable
if((l>=48 && l<=57) || (l>=65 && l<=90) || (l>=97 && l<=122) || l==58 || l==39){ // if the character is part of these parameters
st+=l; // concatenate it to a string
}

else if(l==10){ // if the character is a “\n”

Serial.flush(); // clean the Serial
String casa = tokenizer(st,2).trim(); // use the function tokenizer ( that i made ) and take just the paramter i want

if (casa.compareTo(hogar)==0){ // compare this parameter to a global variable

if(pack.compareTo(“201”)==0){ // if the package is “201”
pack=""; // clean the variable string “pack”
String macd = tokenizer(st,3).trim(); // take the mac of final
int panid = pan(macd); // take the an id that the gateway gave to all final dispositives
String trama = “202’”+hogar+"’"+macd+"’"+panid+"\n"; // make the string to answer
Serial.flush(); // open the Serial again
delay(250); // wait 1/4 of second
Serial.print(trama); // send the answer
}

The problem is that when i do “Serial.print(trama); // send the answer” the arduino just send " ’ " ( 39 in ascci )… so i don’t know why the Serial just send that cause, as you see, i make a whole String and put it in…

I tried to send it with a for bit by bit, but it makes the same result…

Who can help me?

if((l>=48 && l<=57) || (l>=65 && l<=90) || (l>=97 && l<=122) || l==58 || l==39){

This would be so much easier to read as:

if((l>='0' && l<='9') || (l>='A' && l<='Z') || (l>='a' && l<='z') || l==':' || l==39){
      Serial.flush();

You’re in the middle of reading some serial data, so throw the rest away. Got it. Why?

      String casa = tokenizer(st,2).trim();

No clue what this is doing, since the st variable is not defined, nor is the tokenizer function/class.

              Serial.flush(); // open the Serial again

The flush function does not do what the comment says. Not even close.

but when i try to make the gateway recieve information ( strings ) from the final and answer to it with another string, the Serial doesn’t allow me to send the new string

From the final what? Why doesn’t the Serial object allow you to send the String? What is it doing to prevent you from sending the String?

What version of the IDE are you using? What OS?

Well, all the variables that are on the example are declard, if i copy all the code here it will be more than 400 code lines :P… so let me explain myself better.

I have 2 devices made of:

Gateway: arduino duemilanove + ethernet shield + xbee shield

Final: arduino duemilanove + xbee shield

ok, the gateway is like a router but made by me, and the Final is a destiny, like an object on a xbee network. The gateway comunicates with a server made in java and the comunication its fine there… the problem is when the Gateway sends a String to the Final ( described before ) via Serial, but its seens that the final doesn’t recieves nothing… but when i monitor the messeges ( with the serial monitor of the Arduino 0022 IDE ) it says that i send it… but the final doesn’t recieve it…

Ignore the coments of the code before, it is just a piece of the entire code page… just read it and tell me if i’m doing a logical mistake… cause it compiles… and it used to work… but sudenly it stop sending informacion… :frowning:

Ignore the coments of the code before, it is just a piece of the entire code page.... just read it and tell me if i'm doing a logical mistake.

I did. You are. I pointed them out.

it used to work.... but sudenly it stop sending informacion.

Ahh, the classic "all I did was..." problem. What did you do?

ok.... i solved it.... the problem was that the moment when the final was capturing the data, was very fast and it just didn't has the time to percieve if there was any information.... i just make that it sends and inmediatly check if there is any information in serial.... :P, thanks anyways pauls