using two softwareserial in the code..!

Hi everyone!
I need to use two softwareserial object but when I run it, I cannot recieve anything from the last created softwareserial object…
What should I do?
I have already read examples but its just working technically not in practise…

I tried to take coordinates for 6 times then start the gsm modem but It is not working too…

My code is trying to communicate with a GPS and GSM Modem…

Pls help, I need some advice or solution… ??? :astonished: :astonished:

#include <TinyGPS.h>
#include <EEPROM.h>
#include <SoftwareSerial.h>

#define  inDataLENTGTH 128
//--------------------------------------------
// Bora Ciner -- GSM Modem Home Control System
//--------------------------------------------

TinyGPS gps;

SoftwareSerial gsmSerial(2, 3); //SoftwareSerial(rxPin, txPin);
SoftwareSerial ss(5,6);

boolean debug = true;

const int SICAKLIK_PORT =12; 

const int ROLEPin1 = 6;     // isiklarin bagli oldugu pin
const int ROLEPin2 = 7;     // isiklarin bagli oldugu pin
const int ROLEPin3 = 8;     // isiklarin bagli oldugu pin
const int ROLEPin4 = 9;     // isiklarin bagli oldugu pin
const int ROLEPin5 = 10;     // isiklarin bagli oldugu pin
const int ROLEPin6 = 11;     // isiklarin bagli oldugu pin


String inData = String(inDataLENTGTH); // Allocate some space for the string
boolean inputAvailable = false;
String strWhichMsg = String(1);
String NewMessageDEF = String(15);
String MessageReadString = String(10);
String readingFromInbox = String(10);
String sendReadRequest = String(10);
String PASSWORD = String();
String RemoveCommand = String("AT+CMGD=");
String ADMIN_PHONE_NUMBER = String(11);
String DurumBilgisiStr = String(150);

int gpsoku=true;

void setup()  
{
  Serial.begin(9600);
  gsmSerial.begin(9600);
  ss.begin(9600);
  
  
  pinMode(ROLEPin1, OUTPUT); 
  pinMode(ROLEPin2, OUTPUT); 
  pinMode(ROLEPin3, OUTPUT); 
  pinMode(ROLEPin4, OUTPUT); 
  pinMode(ROLEPin5, OUTPUT); 
  pinMode(ROLEPin6, OUTPUT); 

  digitalWrite(ROLEPin1,HIGH); 
  digitalWrite(ROLEPin2,HIGH); 
  digitalWrite(ROLEPin3,HIGH); 
  digitalWrite(ROLEPin4,HIGH); 
  digitalWrite(ROLEPin5,HIGH); 
  digitalWrite(ROLEPin6,HIGH); 
  

  NewMessageDEF = "+CMTI: \"SM\",";
  strWhichMsg = "";
  MessageReadString = "at+cmgr=";
  readingFromInbox = "REC UNREAD";

  ReadPasswordFromEEPROM();
  
  Serial.print("PASSWORD =");
  Serial.println(PASSWORD);
  
  if(debug)
  Serial.println("Setup..! wait for 1 sec");
  delay(1000);
  Serial.print("_SS_MAX_RX_BUFF = ");
  Serial.println(_SS_MAX_RX_BUFF);
}

void loop() // run over and over
{


bool newData = false;
  unsigned long chars;
  unsigned short sentences, failed;
 
 if(gpsoku <=5)
   { 
    while (ss.available())
    {
      char c = ss.read();
      //Serial.write(c); // uncomment this line if you want to see the GPS data flowing
      if (gps.encode(c)) // Did a new valid sentence come in?
        { 
          printGPSDATA();
          gpsoku++;
        }
    }
             
   }
  else{
    
  //-------------------GSM---------------------
  while(gsmSerial.available() > 0 )
  {
    inputAvailable = true;
    int tmp = gsmSerial.read();
    inData += (char) tmp;
    delay(7);
  }
  
  if(inputAvailable){
    inputAvailable=false;
    processData();
  }
  inData="";
  //-------------------GSM---------------------
  
  }
}
void printGPSDATA(){
  
    float flat, flon;
    unsigned long age;
    gps.f_get_position(&flat, &flon, &age);
    Serial.print("LAT=");
    Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
    Serial.print(" LON=");
    Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
    Serial.print(" SAT=");
    Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
    Serial.print(" PREC=");
    Serial.println(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop()); 
  
  
}
void processData(){
  if(debug){
  Serial.println("OKUDUGUM VERI");
  Serial.println(inData);  
  } 
  if(thereIsNewMessage())
  { // yeni mesaj var
    if(debug)Serial.println("yeni mesaj var");
    String sendReadRequest = "";
    sendReadRequest += MessageReadString;
    
    int indexofMsgStr = inData.indexOf(NewMessageDEF);
    indexofMsgStr += NewMessageDEF.length();
    strWhichMsg = inData.substring(indexofMsgStr , indexofMsgStr+1); 
    sendReadRequest +=strWhichMsg;
    
    if(debug){
    Serial.print("gonderilen komut = ");
    Serial.println(sendReadRequest);
    }
    //gsmSerial.println(sendReadRequest); // xxxx inci mesaji oku
    
    
  }else if(IsRinging())
  { // telefon caliyor
    if(debug)Serial.println("telefon caliyor");
    AramayiMesguleCevir();    
    removeSms();
    
  }else if(ReadFromInbox())
  {
    takeMessageBody();
    processMessageBody();
    removeSms();
  }else
  {
    if(debug)Serial.println("ELSE");  
  }
  

}

void AramayiMesguleCevir(){
  //gsmSerial.println("AT H");
  delay(50);
}


void takeMessageBody(){
if(debug)Serial.println("---->takeMessageBody");  
int index_of_NewLine = 0;

int indexofPhoneStr = inData.indexOf("\",\"+9");
indexofPhoneStr += 5;
ADMIN_PHONE_NUMBER = inData.substring(indexofPhoneStr , indexofPhoneStr+11); 
if(debug)
{
  Serial.print("ADMIN PHONE NUMBER ");
  Serial.println(ADMIN_PHONE_NUMBER);
}
  index_of_NewLine = inData.indexOf("REC UNREAD");  
  index_of_NewLine += 53;
  inData = inData.substring(index_of_NewLine,index_of_NewLine+29);

if(debug)
{
  Serial.println("Message Body ===>");
  Serial.println(inData);
  Serial.println("<----takeMessageBody");   
}
}

void processMessageBody(){
....
..
.
..
..
.
String inData = String(inDataLENTGTH); // Allocate some space for the string

You really should spend some time looking at the String class. This does not do what the comment says.

const int ROLEPin1 = 6;     // isiklarin bagli oldugu pin
const int ROLEPin2 = 7;     // isiklarin bagli oldugu pin
const int ROLEPin3 = 8;     // isiklarin bagli oldugu pin
const int ROLEPin4 = 9;     // isiklarin bagli oldugu pin
const int ROLEPin5 = 10;     // isiklarin bagli oldugu pin
const int ROLEPin6 = 11;     // isiklarin bagli oldugu pin

You ever heard of arrays?

Only one instance of the SoftwareSerial class can listen at a time. You are never changing the instance that is listening.

You really need a Mega.

There's a function called myserial.listen() that you should look at.

thanks for the advices ... I'll spend many time on strings an review for the code...