SIM900 won't read message

the sending of message from the module seems to be working fine but when I send a message to the module it does not seem to read the content, it just receives.

// number of analog samples to take per reading
#define NUM_SAMPLES 10
#define VOLTAGE_SAMPLES 10
#define VOLTAGE_OCCURENCE_MAX 5 // maximum consecutive result of voltage threshhold reached
#define WINDSPEED_THRESHOLD 30 // windspeed threshold in km/h
#define ANEMOMETETER_VOLTAGE_OUTPUT 5 

// ARDUINO SIM CARD NUMBER = +639231385775
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);

int sum = 0; // sum of samples taken
int voltage_sum = 0; // sum of voltage samples taken

unsigned char sample_count = 0; // current sample number
unsigned char voltage_count = 0; // current voltage sample number

float voltage = 0.0; // calculated voltage
float average = 0.0; // average voltage

float voltageMin = 0; // Mininum output voltage from anemometer in mV.
float windSpeedMin = 0; // Wind speed in meters/sec corresponding to minimum voltage

float voltageMax = 5.0; // Maximum output voltage from anemometer in mV.
float windSpeedMax = 50; // Wind speed in meters/sec corresponding to maximum voltage
float windSpeed = 0; // Wind speed in meters per second (m/s)


float occurence_of_voltage_threshhold = 0;

char incoming_char = 0;

void setup()
{
    Serial.begin(115200);
    SIM900.begin(115200);
    SIM900power();  
    pinMode(9,OUTPUT);
    pinMode(10,OUTPUT);
    digitalWrite(10,LOW);
    digitalWrite(9,LOW);
    delay(5000);  // give time to log on to network. // 5 seconds
    
    SIM900.print("AT+CMGF=1\r");  // set SMS mode to text and ready to receive text
    SIM900.print("AT+CNMI=2,2,0,0,0\r"); 
    // blurt out contents of new SMS upon receipt to the GSM shield's serial out
    delay(100);

}

void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
  digitalWrite(9, HIGH);
  delay(1000);
  digitalWrite(9, LOW);
  delay(5000);
}

void loop()
{
  
  int firstR = 1;
    //check if there is new sms message
    if(SIM900.available() > 0) {
          
      readSMS(firstR);
       firstR=2; 
    } else {
        // take a number of analog samples and add them up
        while (sample_count < NUM_SAMPLES) {
            // calculate sample voltage for read analog signal in A0 pin
            float read_analog = analogRead(A0);
            sum += read_analog * ((float)ANEMOMETETER_VOLTAGE_OUTPUT / 1024);
            sample_count++;
            delay(250);
        }
    
        if(voltage == 0){
        voltage = (float)sum / (float)NUM_SAMPLES;
        Serial.println(voltage);
        }
        
        // take a number of voltage samples and add them up
        if(voltage_count < VOLTAGE_SAMPLES) {
          voltage_sum += voltage;
          voltage_count++;
          sum = 0;
          voltage = 0;
          sample_count = 0;
        } else {
          
        // calculate average voltage ouput from voltage samples  
        average = (float)voltage_sum / (float)VOLTAGE_SAMPLES;
        Serial.println("VOLTAGE ");
        Serial.print(average);
        
        // calculate windspeed based on anemometer specs
        windSpeed = (average - voltageMin)*windSpeedMax/(voltageMax - voltageMin); //For voltages above minimum value, use the linear relationship to calculate wind speed.
        windSpeed = windSpeed * 3.6;
        Serial.println("WINDSPEED ");
        Serial.print(windSpeed);
        Serial.print( " kph");
        delay(2000);
        
        if(windSpeed > (float)WINDSPEED_THRESHOLD) {
          occurence_of_voltage_threshhold ++;
          if(occurence_of_voltage_threshhold == VOLTAGE_OCCURENCE_MAX) {
            Serial.print("SEND TEXT ");
            sendSMS();
            occurence_of_voltage_threshhold = 0;
          }
        } else {
          occurence_of_voltage_threshhold = 0;
        }
        voltage_count = 0;;
        voltage_sum = 0;
      }
    }
}  

void sendSMS()

{
  SIM900.print("AT+CMGF=1\r"); // AT command to send SMS message
  SIM900.println("AT + CMGS = \"+639428636419\"\r"); // recipient's mobile number, in international format
  // recipient's mobile number, in international format
  delay(100);
  SIM900.println("You have reached your threshold, Retraction on process"); // message to send
  delay(100);
   digitalWrite(9, LOW);   
   digitalWrite(10, HIGH);
   delay(5000); // Amount of time to complete roll down (in milliseconds)
   // TURN OFF TRIGGER
   digitalWrite(9, LOW);   
   digitalWrite(10, LOW);
  SIM900.println((char)26);  // Standard AT Command for Send Text
  delay(100); 
  SIM900.println();
  delay(5000); // give module time to send SMS
}

void readSMS(int firstR)
{
  
    
   String SmsTxt; 
   // String fString = 0;
    char c=0;
  
   Serial.println("before loop");
for (int i = 0 ; i < 20 ; i++)
{
  incoming_char = SIM900.read();
  //SmsTxt.concat(SIM900.read());  
  Serial.println(incoming_char);
    if (SIM900.read() == 'R')
    SmsTxt.concat('R');
   else if (SIM900.read() == 'O')
    SmsTxt.concat('O');
   else if (SIM900.read() == 'L')
    SmsTxt.concat('L');
     else if (SIM900.read() == 'L')
    SmsTxt.concat('L');
     else if (SIM900.read() == ' ')
    SmsTxt.concat(' ');
   else if (SIM900.read() == 'U')
    SmsTxt.concat('U');
   else if (SIM900.read() == 'P')
    SmsTxt.concat('P');
}

 Serial.println("after loop");
 Serial.println(SmsTxt);
   digitalWrite(9, HIGH);
   digitalWrite(10, LOW); 
   delay(5000); // Amount of time to complete roll up (in milliseconds)
   // TURN OFF TRIGGER
   digitalWrite(9, LOW);   
   digitalWrite(10, LOW);

   Serial.println("before loop");
for (int i = 0 ; i < 20 ; i++)
{
  incoming_char = SIM900.read();
  //SmsTxt.concat(SIM900.read());

Why do you assume that there are 20 characters to read?

that's just for testing, if the arduino does read the text message. :blush:

nicayat: that's just for testing, if the arduino does read the text message. :blush:

So, then:

but when I send a message to the module it does not seem to read the content, it just receives.

that output is not unexpected.

As soon as one character arrives, you loop 20 times, reading as many as 160 characters, printing only 1 of up to 8 read on an given iteration of the loop.

Quit trying to make any sense of the data. Simply read WHAT IS AVAILABLE and print it. Do NOT even attempt to use the data UNTIL AFTER you can read it successfully (and store it WITHOUT needing to use the String crutches).

It may come a little late, but I still thougt I’d post it. I needed a function to look for a “codeword” in any incoming SMS with the SIM900. Here is how I made it work:

boolean findWord(String message, String keyword){
    for (int i=0; i<160; i++) //Only the first 160 chars. Could do message.length()
    {
      if(message.substring(i,i+keyword.length())==keyword)
      {
        SMSinn = ""; //empty the global var. when the codeword is found
        return true;
      }
    }
    return false;
}


// main loop
void loop()
{
  // Any incoming SMS
  if(Serial.available() > 0){
    while(Serial.available() > 0)
    {
      incoming_char = Serial.read(); //Get the character from the SIM900 serial port.
      SMSinn = SMSinn + incoming_char;
    }
    
    if(SMSinn != "" && Serial.available()==0){ //Got SMS and empty serial buffer?
      if(findWord(SMSinn, "Status")) //Status is the word I'm looking for
      {
        Serial.print("AT+CMGD=1,4\r"); //Delete SMS inbox on SIM900
        delay(100); //this delay might be stupid... try omitting it.
        Serial.println((char)26);//End AT command with a ^Z, ASCII code 26
        
        /*
        Here you cando whatever you
        want to have done, whenever
        the keyword is found.
        */

      }  // end findWord
    }  // end Got SMS and empty serial buffer?
  }  // end Serial.available 
} //end loop

Is this maybe what you are trying to accomplish?