SMS function is always skipped

This sketch works perfectly well on it’s own. I have two methods, getGPS and sendHTTP. when I list all these 3 functions in the loop, it always skips sms and does the others. When I place the getGPS and sendHTTP functions anywhere inside the sms function, it doesn’t work either. I changed from if to while and the results are the same

#include <SoftwareSerial.h>

SoftwareSerial mySerial(7, 8); // RX, TX
int led1 = 10;

byte led = 10;   // use "byte" instead of "int" to save memory.
byte led_on = 0;
byte led_off = 0;
byte sms_control = 0;

long last_millis = 0;
const int delay_time = 5000;

const int buff_size = 10;
char buffer[buff_size];


void setup()  
{
  pinMode(led, OUTPUT);
    digitalWrite(led1, HIGH);

  mySerial.begin(9600);
  Serial.begin(9600);
   
   //delete all read SMS
 mySerial.println("AT+CMGF=1");// set SMS mode to text
 delay(100); 
mySerial.println("AT+CMGD=1,4");
  delay(100); 

}

void loop(){

    //Serial.println("SMS function doesn't work here");

    sms();

}

void sms(){

 while ((millis() - last_millis) > delay_time ){
       mySerial.println("AT+CMGL=\"REC UNREAD\"\r\n");
   last_millis = millis();
  //  Serial.println("SMS function doesn't work here");
   
     }
  

  while (mySerial.available() > 0){

    char inchar = mySerial.read(); // print in data to  software serial port for debug perpose.
    Serial.print(inchar);

    if(inchar == '\r' || inchar == '\n'){
      sms_control = 0;
    }

    if(inchar == '#'){
      sms_control++; 
     } 
    

      switch (sms_control){
      case 1:
      
      if(inchar == 'O' || inchar == 'N'){
         digitalWrite(led1, HIGH);
     mySerial.println("AT+CMGD=1,4");

      }
      
      if(inchar == 'O' || inchar == 'F'){
         digitalWrite(led1, LOW);
     mySerial.println("AT+CMGD=1,4");

      }
    
    if(inchar == 'G' || inchar == 'P' || inchar == 'S'){
         digitalWrite(led1, LOW);
     mySerial.println("AT+CMGD=1,4");

      }
      
      break;
      
    
      }  
  }

 //   Serial.println("SMS function doesn't work here");

}
 while ((millis() - last_millis) > delay_time ){
       mySerial.println("AT+CMGL=\"REC UNREAD\"\r\n");
   last_millis = millis();
  //  Serial.println("SMS function doesn't work here");
   
     }

is only executed once every delay_time. Is that what you want?

....

Allan

No. I want a correction for my code. When I include other functions, it looks like the sms function is skipped and the other functions operate. I want to make the other functions run if there is no SMS.

Put every { on a line BY ITSELF.
Put every } on a line BY ITSELF.

Use Tools + Auto Format to fix that horrid indenting. Your code looks like it was typed by a drunken monkey.

I have two methods, getGPS and sendHTTP. when I list all these 3 functions in the loop

How can you call all three of the two functions?

Do you ever help people? You're always complaining about little errors people make despite the fact that you know their noobs. If you're here to assist the pros, I think you should do just that. I've seen your comments on other peoples posts and it's not just the best. Because of you I have to create new posts and hope someone else comments.

deekson: Do you ever help people? You're always complaining about little errors people make despite the fact that you know their noobs. If you're here to assist the pros, I think you should do just that. I've seen your comments on other peoples posts and it's not just the best. Because of you I have to create new posts and hope someone else comments.

Yeah, create a new post. See how that works out. AWOL will kick you off the board for a while if you do it too often.

PaulS brings a good point. It's hard to read your code. When people are trying to give you free help, do you really think it's a good idea to make that harder for them? Or would going to the IDE pressing Control-T and repasting the code here be that hard for you?

Take all the long stretches of blank lines out while you're at it. Let's make this readable and then someone can read it and try to help you.

Hello Delta, not create multiple posts necessarily. I made a proper formatting and pasted my code in the topic "Assistance on GPS tracker project - SMS function".

You write....

    if(inchar == '#'){
      sms_control++;
     }
   

      switch (sms_control){
      case 1:

etc etc...

When does sms_control ever get to == 1?

Allan

Hello Alan, this is why there's an issue with the sms function. I got that code from somewhere and made the integration into my project. I really don't know how to make it work. Which is why I'm here. How can make the sms function listen for sms and then perform the actions or skip if there's no sms?