Read messagge with Sim800L v.2

Hi all i need to read messagge reiceved using a Sim800L v.2.

I have setup the sim800l v.2 and i can recevie and send message.

When i receive messages this is what i receive:

12:20:14.969 -> +CMT: "+39XXXXXXXXXX","","22/09/19,11:20:08+04"
12:20:15.017 -> 86
12:20:15.017 ->

i need only to read the "86" (it could be another number it is not always 86) and put it in a variable.

This is how i read message:

void loop()
{
  updateSerial();
}

void updateSerial()
{

  delay(500);
  while (Serial.available())
  {
    sim.write(Serial.read());//Forward what Serial received to Software Serial Port

  }
  while (sim.available())
  {
    String sms = sim.readString();
    Serial.println(sms);
     }
 }
Please can someone help me?

Thank you

Welcome to the forum

Read the serial input and discard it until you get a Carriage Return, then use Serial.parseInt() or Serial.parseFloat() depending in data type, to read the value into a String

In general, it would be more correct to come up with some kind of protocol instead of sending a bare number. Something like "value=86" instead of just 86
Single number is very easy to confuse with some service message

Hi, this is what i try:

{

  delay(500);
  while (Serial.available())
  {
    sim.write(Serial.read());//Forward what Serial received to Software Serial Port

  }
  while (sim.available())
  {
    Serial.write(sim.read());
    String sms = sim.readString();
    Serial.println(sms);
    {
        str = sim.readStringUntil('\n');
        x = Serial.parseInt();
    }
    Serial.println(str);


  }
}
`but i don't receive nothing str and x``

All of this:
sim.read()
sim.readString()
sim.readStringUntil()

read from port... So you try to extract one message three times. You should select ONLY ONE method for it.

And this

x = Serial.parseInt();

is fully non-understandable for me
Why do you try to extract value from Serial, if you receive it from "sim" port?

I would recommend that you read this guide first:

I would speculate that the SIM899 is connected to a Serial port of some kind but as @Riccio99 has not posted a complete sketch let alone a schematic we can only gutess

Thank you all for your time.

this is the full sketch:

#include <SoftwareSerial.h>

SoftwareSerial sim(10, 11);

void setup()
{
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(9600);
 
  //Begin serial communication with Arduino and SIM800L
  sim.begin(9600);

  Serial.println("Initializing...");
  delay(1000);

  sim.println("AT"); //Once the handshake test is successful, it will back to OK
  updateSerial();
  sim.println("AT+CSQ"); //Signal quality test, value range is 0-31 , 31 is the best
  updateSerial();
  sim.println("AT+CCID"); //Read SIM information to confirm whether the SIM is plugged
  updateSerial();
  sim.println("AT+CREG?"); //Check whether it has registered in the network
  updateSerial();

  sim.println("AT+CMGF=1"); // Configuring TEXT mode
  updateSerial();
  sim.println("AT+CNMI=1,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
  updateSerial();

}

void loop()
{
  updateSerial();


}

void updateSerial()
{

  delay(500);
  while (Serial.available())
  {
    sim.write(Serial.read());//Forward what Serial received to Software Serial Port

  }
  while (sim.available())
  {
    String sms = sim.readStringUntil('\n');
    Serial.println(sms);
    //int index = sms.indexOf(';');
    //String message = sms.substring(index);
    //Serial.println(message);

  }
}

Thank you all for your time i solved the problem using the gsm library.

Thnak you

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.