Go Down

Topic: Parse Received SMS - SIM900 GSM (Read 146 times) previous topic - next topic

Thor2018

Hey guys,

I have a problem with the parsing of received sms via my sim900 module. I can't figure out since 6 hours how exactly this kind of process could be programmed.


It's a very easy task (i thought): I want to receive a sms and save it in a string for further usage. But i can't either print the sms via the serial port or save it in a string.

Do you know some functioning solutions?
Serial 1 is PC to/from Arduino and Serial 3 is to/from GSM module.

Would be thankful for every answer! :)

Here my Code:
Code: [Select]


unsigned char buffer[100] = "0"; // buffer array for data recieve over serial port
int count=0;     // counter for buffer array
char Benutzer1[] = "+436606587778";


void setup()
{
    Serial3.begin(19200);               // the GPRS baud rate
    Serial.begin(19200);             // the Serial port of Arduino baud rate.
    Serial3.flush();
    Serial.flush();
    delay(5000);   
}



void loop()
{
    if (Serial3.available())              // if date is comming from softwareserial port ==> data is comming from gprs shield
    {
        receivesms();                       // set counter of while loop to zero
    }

    if (Serial.available())            // if data is available on hardwareserial port ==> data is comming from PC or notebook
    Serial3.write(Serial.read());       // write it to the GPRS shield
}



void receivesms()
{
  Serial3.flush();
  Serial3.print("AT+CMGL=\"REC UNREAD\"\r");
  delay(1000);

  while(Serial3.available())          // reading data into char array
  {
    buffer[count++]=Serial3.read();     // writing data into array
    if(count == 100)break;
  }

  Serial.write(buffer,count);            // if no data transmission ends, write buffer to hardware serial port
    //for(int i=0;i<=100;i++)  //Also don't work, here i only get numbers in the array?
    //Serial.print(buffer[i]);
  count = 0;
}

Power_Broker

#1
Sep 21, 2019, 04:55 am Last Edit: Sep 21, 2019, 04:56 am by Power_Broker
Serial 1 is PC to/from Arduino and Serial 3 is to/from GSM module.
You are NOT using Serial1 for PC communication, you are using Serial.

Try getting rid of all your delay() and flush() calls. They are most likely unnecessary.

As an aside: I suggest learning about how to write code with consistent and easy to read formatting
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

Power_Broker

Also, change
Code: [Select]
unsigned char buffer[100] = "0";
to
Code: [Select]
unsigned char buffer[100] = '0';
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

Go Up