Go Down

Topic: Cant receive incoming data with RN-XV (Read 93 times) previous topic - next topic

aman345

Hello all,

I have the following setup.... RN-XV (ip add 192.168.1.2:2000) mounted on XBee shield with Arduino Uno..

The data printed on its serial is transmitted to a Java (server) app at 192.168.1.5:6666 frequently with each loop()...Every time it prints something on the serial a connection is made to this app..The data is delivered soundly..

Now, I have another Java app at 192.168.1.4 which tries to send some keywords back to the RN-XV/Arduino where it is intended to be parsed and further processed.

Here is my problem..

When I turn on my Arduino without turning on the Java (server) app (192.168.1.5:6666) to which the serial data is sent, and try to push the keywords from the other Java app (192.168.1.4), it works like a charm. Everything works well, the keywords msg can be seen, parsed and processed......However, however...when I turn on the Java server app and try this exercise again, the arduino doesn't respond to it or in other words the keywords message is lost in the wild...when I try to monitor the incoming keyword message with a telnet connection, the connection freezes...I receive this keywords only TWICE in a million tries with everything turned ON..

What I tried...

Because the code seems to be ok, I thought it would just be a matter of the time between each serial data the arduino prints and as it frequently sends the data so its port 2000 might be a lil busy...Now, I have changed this time taken during each loop but the problem is still laughing at me....BTW its not an active delay..I am using a counter to delay the connections made between each serial prints..

So I have to say it loud....HELP ME OUT...someone, anyone

pylon

You forgot to post your sketch and preferably either a photo or the schematics of the circuit.

Do you use SoftwareSerial? If so change to HardwareSerial and try again. The RN-XV is very picky about serial timing and often looses a few bits if SoftwareSerial is used.

aman345

Sorry, I thought explaining the problem would do...Anyways here is my sketch

Code: [Select]

void setup() {
  // initialize serial:
  Serial.begin(9600);
  key = fourthKey;
  keyIndex = "Fourth";
  // reserve 200 bytes for the inputString:
  inputString.reserve(100);
}

void loop() {
  
  temp= eHealth.getTemperature();
  
  // Execution After Adapting new action if it receives anything
  
  if (stringComplete) {
    adapt();
     inChar = 0;
     inputString = "";
     stringComplete = false;
  
  }// End Top IF Statement
 
 //Normal Execution---------
 
 else {  
  
  enc_temp = key^temp;
  
  if(counter%20000 == 0 ) {
    
       Serial.print(keyIndex);
       Serial.print(enc_temp);
    
       if((counter%200000)==0){
          
         generateEvent();
          
       }//end Inner IF
  
  }// End Outer IF
  
 } // end ELSE
 
 
  counter++;
 
  if (counter == 200001){
      counter = 1;
  }
  
}

//-------------Listening on Serial---------------

void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
   if (inChar == '!'){
     stringComplete = true;
    }
  }  
}


//---------------Adapting new action--------------------

void adapt(){
 
  property = inputString.substring(inputString.lastIndexOf(":")+2);
  
    if(property == a){
      keyIndex = "First";
      key = firstKey;
      getTemp();
      
    }  
    
    if(property == b){
     // Serial.println("New Property Received: "+property);
      keyIndex = "Second";
      key = secondKey;
      getTemp();
      
    }
    
    if(property == c){
      //Serial.println("New Property Received: "+property);
      keyIndex = "Third";
      key = thirdKey;
      getTemp();
      
    }
    
    if(property == d){
      //Serial.println("New Property Received: "+property);
      keyIndex = "Fourth";
      key = fourthKey;
      getTemp();

    }
  if(property == ""){
     // Serial.println("No Match Found");
  }

}

//----------Applying new action--------------------

void getTemp(){

  enc_temp = key^temp;

  Serial.print(keyIndex);
  Serial.print(enc_temp);
  Serial.print("#Level:I::Proc-Key:Key Changed::User:Waqas Aman::EventID:502");
  counter = 1;

}

// ------Battery Event Generation-----------

void generateEvent(){
  
  if (!flag){
    
    Serial.print("#Level:W::Proc-Battery:Low Battery Level "); Serial.print(levelIndex[eventCounter]); Serial.print("%::User:Waqas Aman::EventID:501");
    
    eventCounter++;
    if (eventCounter > 2){
      flag = true;
    }
 }
  
  else if (flag){
    
     eventCounter--;
     Serial.print("#Level:W::Proc-Battery:Battery Charging Up Level "); Serial.print(levelIndex[eventCounter]); Serial.print("%::User:Waqas Aman::EventID:503");
      
    if (eventCounter == 0){
      flag = false;
    }
  }


}


The Xbee Shield is mounted on Arduino, see attachment..

And honestly speaking I have no idea of what Software and Hardware Serial are..I just used the SerialEvent() function from one of Arduino's example..

Just to revise...The problem is that I cant receive any incoming data when Arduino's/RN-XV's target (server) ip (192.168.1.5:6666) is active, otherwise, when it is not active, things goes as programmed

pylon

#3
Oct 29, 2014, 02:35 pm Last Edit: Oct 30, 2014, 03:22 pm by pylon
Your sketch (you removed the header with the includes and global variables) implies that the RN-XV got configured before. How did you configure the module, what is the configuration?

Quote
Just to revise...The problem is that I cant receive any incoming data when Arduino's/RN-XV's target (server) ip (192.168.1.5:6666) is active, otherwise, when it is not active, things goes as programmed
When the target IP is inactive, how can things go as programmed? In that case nobody is able to send any command and nobody will see anything, so how can you tell?

aman345

The target IP is .5 and the commands are sent from .4. So if the RNXV (.2) is active, I can monitor whats happening on. i.e. I can see what is coming from .4..........Anyways...I figured it out

The problem was with the RNXV (at least in my case)...Once it opens a connection with the target .5, it does not entertain any other incoming connections from other IPs unless the connection it made is closed..
That was the reason why I could not see anything (keyword|command) coming from the .4 or couldnt make a telnet to it..But when the .5 is inactive, means there is no active connection, I could read whatever is sent to the RNXV

I was using an all time open socket with the .5 and so lost every other connection made to it.

So my conclusion is, RN XV can only make ONE active connection at a given time and one should close it if he want to talk to other sources

pylon

Does that mean you tried to configure the RN-XV to be a server and a client at the same time? As far as I know, this isn't possible.
How did you configure the RN-XV? Did you use the Arduino for that?
What do you want to achieve? Maybe there's a workaround for your problem.

Go Up