My sketch displays GPS coordinates but does not respond to SMS commands

I'm writing a sketch to fetch GPS location and then send the GPS coordinates and turn on/off a relay switch. The coordinates are shown alright but doesn't respond to the SMS commands. What am I missing? I'm not sure if it's a buffer overflow but I'll be grateful if you could help me fix this. Thanks in advance.

#include <SoftwareSerial.h>

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


int Powerkey = 9;

long last_millis = 0;
const int delay_time = 5000;

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

char frame[200];

byte GNSSrunstatus;;
byte Fixstatus;
char UTCdatetime[18];
char latitude[10];
char longitude[11];
char date[16];
char time[7];
char altitude[8];
char speedOTG[6];
char course[6];
byte fixmode;
char HDOP[4];
char PDOP[4];
char VDOP[4];
char satellitesinview[2];
char satellites[2];
char GLONASSsatellitesused[2];
char cn0max[2];
char HPA[6];
char VPA[6];


//char latitude[]="5.577620";
//char longitude[]="-0.228933";


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

  pinMode(Powerkey, OUTPUT);

  mySerial.begin(9600);
  Serial.begin(9600);

   power_on();
  
   //delete all read SMS
 mySerial.print("AT+CMGF=1\r");  // set SMS mode to text
mySerial.println("AT+CMGD=1,4");
 
start_GPS(); 
 
}

void loop(){

//	get_GPS();
    sms();

}

void sms(){

  if ((millis() - last_millis) > delay_time ){
       mySerial.print("AT+CMGL=\"REC UNREAD\"\r\n");
   last_millis = millis();
   
     }
  

  if (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++; 
      delay(100);
      mySerial.println("AT+CMGD=1,4");
     } 
    

      switch (sms_control){
      case 1:
      
      if(inchar == 'O' || inchar == 'N'){
         digitalWrite(led1, HIGH);

      }
      
      if(inchar == 'O' || inchar == 'F'){
         digitalWrite(led1, LOW);

      }
    
    if(inchar == 'G' || inchar == 'P' || inchar == 'S'){
         send_SMS();
                  delay(100);
      }

     
      break;

    
      }  

  }
}


void send_SMS()
{
mySerial.print("AT+CMGS=\"+233261605308\"\r");    //Start accepting the text for the message
//to be sent to the number specified.
//Replace this number with the target mobile number.
delay(1000);
mySerial.print("The location of your vehicle is http://maps.google.com/?q=");   //The text for the message
mySerial.print(latitude);
mySerial.print(",");
mySerial.print(longitude);
delay(1000);
mySerial.write(0x1A);  //Equivalent to sending Ctrl+Z 
}



void ShowSerialData()
{
while(mySerial.available()!=0)
Serial.write(mySerial.read());
}

int8_t start_GPS() {

  mySerial.println("AT+CGPSPWR=1");
  delay(100);
  ShowSerialData();

  mySerial.println("AT+CGPSRST=1");
  delay(100);
  ShowSerialData();

  Serial.println("Turning on GPS");
  delay(15000);

  mySerial.println("AT+CGPSSTATUS?");
  delay(100);
  ShowSerialData();

}

int8_t get_GPS() {

  int8_t counter;
  long previous;
  
  while ( mySerial.available() > 0) mySerial.read();
  
  mySerial.println("AT+CGNSINF");

  counter = 0;
  memset(frame, '\0', sizeof(frame));   
  previous = millis();
 
  do {

    if (mySerial.available() != 0) {
      frame[counter] = mySerial.read();
      counter++;
    }
  }
  while ((millis() - previous) < 2000);

  frame[counter - 3] = '\0';

  // Parses the string
  strtok_single(frame, ": ");
  GNSSrunstatus = atoi(strtok_single(NULL, ","));;
  Fixstatus = atoi(strtok_single(NULL, ",")); 
  strcpy(date, strtok_single(NULL, ",")); 
  strcpy(latitude, strtok_single(NULL, ",")); 
  strcpy(longitude, strtok_single(NULL, ",")); 
  strcpy(altitude, strtok_single(NULL, ",")); 
  strcpy(speedOTG, strtok_single(NULL, ",")); 
  strcpy(course, strtok_single(NULL, ",")); 
  fixmode = atoi(strtok_single(NULL, ","));
  strtok_single(NULL, ",");
  strcpy(HDOP, strtok_single(NULL, ",")); 
  strcpy(PDOP, strtok_single(NULL, ","));
  strcpy(VDOP, strtok_single(NULL, ",")); 
  strtok_single(NULL, ",");
  strcpy(satellitesinview, strtok_single(NULL, ",")); 
  strcpy(satellites, strtok_single(NULL, ",")); 
  strcpy(GLONASSsatellitesused, strtok_single(NULL, ",")); 
  strtok_single(NULL, ",");
  strcpy(cn0max, strtok_single(NULL, ",")); 
  strcpy(HPA, strtok_single(NULL, ",")); 
  strcpy(VPA, strtok_single(NULL, "\r")); 


  delay(5000);

  Serial.println("latitude");
  Serial.println(latitude);
  Serial.println("longitude");
  Serial.println(longitude);


}


void power_on() {
  digitalWrite(Powerkey, HIGH);
  Serial.println("Powering On");
  delay(10000);
  Serial.println("Powered On");
}

/* strtok_fixed - fixed variation of strtok_single */
static char *strtok_single(char *str, char const *delims)
{
  static char  *src = NULL;
  char  *p,  *ret = 0;

  if (str != NULL)
    src = str;

  if (src == NULL || *src == '\0')    // Fix 1
    return NULL;

  ret = src;                          // Fix 2
  if ((p = strpbrk(src, delims)) != NULL)
  {
    *p  = 0;
    src = ++p;
  }
  else
    src += strlen(src);

  return ret;
}

One of the bad things about SoftwareSerial is that it cannot transmit and receive at the same time. It you send an AT command, it cannot receive data while that command is going out.

A secondary issue could be the delays. Anytime you use a delay, received characters are stacking up in the input buffer. There's only room for 64, so you could be losing characters any time you delay more than 64ms. (At 9600, 1ms is enough time to receive 1 character.)

You might try NeoSWSerial, a drop-in-replacement for SoftwareSerial. It can transmit and receive at the same time, and it does not disable interrupts for the entire 1ms that a character is received.

The best software serial library is AltSoftSerial, but you have to use it on pins 8 & 9. If you could put Powerkey on pin 7, you could put the SMS device on pins 8 & 9 and use AltSoftSerial. Strongly recommended.