Go Down

Topic: How can use isListening() to detect signal as +SIND: 7 or +SIND:0 (Read 611 times) previous topic - next topic

pierrot10

Jan 05, 2013, 08:50 pm Last Edit: Jan 06, 2013, 10:21 am by pierrot10 Reason: 1
Dear All,
I am happy, my project goes ahed  :).

Thank for reading my post. it's a bit long, because I tried to be the more understanding.

I need to listnen my port in case of my SIMD card is removed of if the network is lost.

I found the function listnen() and isListening().

Could let me know if I ma wrong or on a good way. I am a bit septic. For this I will explain how my code work

First, I have a setup.
Second I have a loop(). My loop() is like this:
Code: [Select]

void loop() {
 //That value a set back to false in other to have a check of the network
 // Check network
 establishNetwork();

  // THis for debug
 //Serial.println("Loop() Delay of 2 sec");
 //delay(SEND_DELAY);
}

I call the function etablishNetwork()
Code: [Select]

static void establishNetwork() {
 while (GPRS_registered == false || GPRS_AT_ready == false) { // (+SIND 11 || +SIND 4)
   Serial.println("");
   Serial.println("EtablishNetwork (Pause 2sec)");
  delay(2000);
   readATString();
   ProcessATString();
 }
  // This is for debug
 Serial.print("********************************************");
}

When +SIND: 11 and +SIND:4 are received GRPS_registered and GPRS_AT_ready are turn to true, then the loop stop
That function call two other.

First, etablishNetwork() loops readATString() once and return +SIND:1, as GRPS_registered and GPRS_AT_ready are stile false, etablishNetwork() loop it again and return +SIND:3, and it continue looping until it get +SIND:11, and turn GPRS_registered true, again it continue until it get +SIND:4 and turn GRPS_AT_ready to true. Those values are turn to true in ProcessATString(). I will show the code later.
Code: [Select]

static void readATString() {

 char buffidx = 0;
 int time = millis();
 
 //while (strstr(at_buffer, "+SIND: 4") == 0 && strstr(at_buffer, "+SIND: 10,\"SM\",1,\"FD\",1,\"LD\",1,\"MC\",1,\"RC\",1,\"ME\",1") == 0) {

 while (1) {
   
   Serial.println("=> Loop start");  // For debug

   if (cell.available() > 0) {
     
     incoming_char = cell.read();
     
     if (incoming_char == -1) {
       at_buffer[buffidx] = '\0';
       Serial.print("--------------------------1");  // For debug
       return;
     }
     
     if (incoming_char == '\n') {
       Serial.println("continue");  // For debug
       continue;
     }
     
     if ((buffidx == BUFFSIZE - 1) || incoming_char == '\r') {
       at_buffer[buffidx] = '\0';
       Serial.println("return R");  // For debug
       return;
     }
     
     at_buffer[buffidx++] = incoming_char;

   }else{
      Serial.println("cell not available (RETURN)");
     //return;
   }
   Serial.println("=> Loop end");  // For debug
   Serial.println("");   // For debug
 }
}


When at_buffer get +SIND: 1 , ProcessATString() come in action and display the message for.
Same, when at_buffer get +SIND:4, ProcessATStrine come in action, display a message and turne GPRS_ready to true.

It seams to work well.
From that point, the loop() is looping...
Code: [Select]

void loop() {
 //That value a set back to false in other to have a check of the network
 // Check network
 establishNetwork();

  // THis for debug
 //Serial.println("Loop() Delay of 2 sec");
 //delay(SEND_DELAY);
}

... and at each time, etablishNetwrok() is calling, but nothing happen because GPRS_at_ready and GPRS_regostered are true.
Then if I remove the SIM card or, I do not know, if I lost the network, or something else, the function readATString() will never be called, because GPRS_at_ready and GPRS_registered are true.

My question, now  :).
I would like to listened this  SoftwareSerial cell(GPRS_TX, GPRS_RX); //int GPRS_TX = 2; int GPRS_RX = 3; or the ports, in case of incoming_char = cell.read(); return +SIND: 0, or +SIND: 7, or something else.

As I wrote, I found .listnen() and .isListing(). I saw that exemple
Code: [Select]

portOne.listen();

 if (portOne.isListening()) {
  Serial.println("Port One is listening!");
}else{
  Serial.println("Port One is not listening!");
}

 if (portTwo.isListening()) {
  Serial.println("Port Two is listening!");
}else{
  Serial.println("Port Two is not listening!");
}


but I am a bit confused. In my case, I suppose, I should adapt it like this
Code: [Select]

  cell.listen();
 if (cell.isListening()) {
  Serial.println("Port One is listening!");
}else{
  Serial.println("Port One is not listening!");
}


But now, if I am in the right way, how should I red cell, in order to cacht the code +SIND:0, +SIND:7 etc ????
The code should be catch from listnen() or from isListning()??

Thank for ready my long post. I hope I was clear and thank for your help and advise.

Cheers
Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

pierrot10

By the way, I have another question.

When GPRS_registered and GPRS_at_ready are true,
this
Code: [Select]
if (cell.available() > 0)
return false.
Why? It because, nothing is ready?
Because, at the being tresting, the network, is not lost, the GPRS connectioj is fine!!!

here is the code, for reminding.
Code: [Select]

static void readATString() {

  char buffidx = 0;
  int time = millis();
 
  //while (strstr(at_buffer, "+SIND: 4") == 0 && strstr(at_buffer, "+SIND: 10,\"SM\",1,\"FD\",1,\"LD\",1,\"MC\",1,\"RC\",1,\"ME\",1") == 0) {

  while (1) {
   
    Serial.println("=> Loop start");  // For debug

    if (cell.available() > 0) {
     
      incoming_char = cell.read();
     
      if (incoming_char == -1) {
        at_buffer[buffidx] = '\0';
        Serial.print("--------------------------1");  // For debug
        return;
      }
     
      if (incoming_char == '\n') {
        Serial.println("continue");  // For debug
        continue;
      }
     
      if ((buffidx == BUFFSIZE - 1) || incoming_char == '\r') {
        at_buffer[buffidx] = '\0';
        Serial.println("return R");  // For debug
        return;
      }
     
      at_buffer[buffidx++] = incoming_char;

    }else{
       Serial.println("cell not available (RETURN)");
      //return;
    }
    Serial.println("=> Loop end");  // For debug
    Serial.println("");   // For debug
  }
}
Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

pierrot10

Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

PaulS

Quote
Someone has an idea about my issue?

Yes. Either take your snippets off to snippets-r-us.com or post ALL of your code.

It appears that you are trying to use SoftwareSerial to listen to two different serial ports. The isListenting() method simply returns true (yes, this is the active instance) or false (no, some other instance is the active instance). You can not use it to collect data from the serial port.

Go Up