Go Down

Topic: Need help on SoftwareSerial (+SIND:0) (Read 1 time) previous topic - next topic

pierrot10

Quote
Hello
I have some big trouble to understand how work SoftwareSerial.

I understood that I have to add those line:
Code: [Select]
SoftwareSerial cell(GPRS_TX, GPRS_RX); //int GPRS_TX = 2; int GPRS_RX = 3;

Then I can run taht condition:
Code: [Select]

if (cell.available() > 0) {
     
     incoming_char = cell.read();
}

But now I have big difficulties ti understand how to store and work specialy with those value
Quote
+SIND: 1
+SIND: 10,"SM",1,"FD",1,"LD",1,"MC",1,"RC",1,"ME",1
+SIND: 3
+SIND: 4
+SIND: 7
+SIND: 11


I am trying to do something like this:
if (incoming_char == "+SIND:0") Serial.print("SIM card remove");
if (incoming_char =="+SIND:1") Serial.print("SIM card inserted");
if (incoming_char == "+SIND:3") Serial.print("AT module is partially ready");
if (incoming_char == "+SIND:4") Serial.print("AT module is totaly ready");
if (incoming_char == "+SIND:10") Serial.print("message");
if (incoming_char == "+SIND:11") Serial.print("Registered to network");


My goal is on myLoop() function.
Each 10 sec, it start the loop, check the GPRS connetion and display the error (or a red led), if there are errors.

I would really really appreciate if you can provide me some help. I am totaly lost.

I hope my post was clear, but feel you free to ask me question for more detail

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

tocpcs

Quote
But now I have big difficulties ti understand how to store and work specialy with those value

Your post definitely needs some clarity added to it (more of the code), and perhaps some of what you have tried?

The first thing you need to test is the result of 'incoming_char'- so Serial.print it. I bet it's not the string you are testing for, I'd suggest it's just one of the characters of the string you are expecting.

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

pierrot10

#8
Jan 05, 2013, 01:59 pm Last Edit: Jan 05, 2013, 02:01 pm by pierrot10 Reason: 1
Here are more code
Code: [Select]

void setup() {
   
  pinMode(LED_STATUS, OUTPUT); //int LED_STATUS = 13;
  pinMode(LED_ERROR, OUTPUT); // int LED_ERROR = 12;
  pinMode(GPS_RELAY, OUTPUT); // int GPS_RELAY = 9;
 
  ////Initialize serial ports for communication.
  Serial.begin(4800);
  cell.begin(9600);
 
  //Let's get started!
  Serial.println("Power on");
  // Check LEDS
  blinkLed(LED_ERROR, 5, 25);
  blinkLed(LED_STATUS, 5, 25); // Pin, flashtime, delay
}

// Main Loop
void loop() {
  /*
  if (firstTimeInLoop) {
    firstTimeInLoop = false;
  }
  */
  readATString();

 
 
  Serial.println("Delay of 10 sec");
  delay(10000);
}

readATString is called and ...
Code: [Select]

static void readATString(boolean watchTimeout = false) {
const int BUFFSIZE = 180;
char at_buffer[BUFFSIZE];
//char buffidx;
char buffer[BUFFSIZE];

  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) {
  int i = 0;
  while (1) {
    i++;
    Serial.print(i);
   
    if (cell.available() > 0) {
     
      incoming_char = cell.read();
     
      if (incoming_char == -1) {
        at_buffer[buffidx] = '\0';
        Serial.print("--------------------------1");
        return;
      }
     
      if (incoming_char == '\n') {
        Serial.println("continue");
        continue;
      }
           
      if ((buffidx == BUFFSIZE - 1) || incoming_char == '\r') {
        at_buffer[buffidx] = '\0';
        Serial.println("return");
        return;
      }
     
      at_buffer[buffidx++] = incoming_char;

    }else{
      Serial.println("toto");
      return;
    }
  }
}

... and I would like that at_buffer collect the code as +SIND+ 0, >SUND+ 1 etc in order to display the marching message, as for exemple
Code: [Select]

if (at_buffer == "+SIND:0") Serial.print("SIM card remove");
if (at_buffer =="+SIND:1") Serial.print("SIM card inserted");
if (at_buffer == "+SIND:3") Serial.print("AT module is partially ready");
if (at_buffer == "+SIND:4") Serial.print("AT module is totaly ready");
if (at_buffer == "+SIND:10") Serial.print("message");
if (at_buffer == "+SIND:11") Serial.print("Registered to network");

Is it no array in sketch?

I do not really understanf the readATString function, how the caracter are "compiled" in at_buffer.

I am very block at this point.

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

tocpcs


Is it no array in sketch?

I do not really understanf the readATString function, how the caracter are "compiled" in at_buffer.

I am very block at this point.

Many thankf for your help


You aren't using an array with this line of code:
Code: [Select]
if (at_buffer == "+SIND:0") Serial.print("SIM card remove");


You were given a valid answer earlier:
Quote
You need to look at "strcmp"


What did you find when you looked into strcmp?

Go Up