Sim800l

hey everyone.
can someone help me to understand how can I save the recived input to a string?
I use this example code but it’s only print it in the screen.
thank u

#include <SoftwareSerial.h>

//Create software serial object to communicate with SIM800L
SoftwareSerial mySerial(4, 5); //SIM800L Tx & Rx is connected to Arduino #3 & #2

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

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

  mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
  updateSerial();
  
  mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
  updateSerial();
  mySerial.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()) 
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
    char inp=Serial.read();
    Serial.print ("hey");
    Serial.println(inp);
  }
  while(mySerial.available()) 
  {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
    
  }

}

while (Serial.available())
{
mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
char inp=Serial.read();
Serial.print ("hey");
Serial.println(inp);
}

So this code says that if ther is one or more bytes in the serial buffer read two bytes from the serial buffer. See where this could go wrong? What if you only have one byte in the buffer but you read two?

OK thanks.
but my problem is that I want to save the data to a string and i dont know how to do it.

but my problem is that I want to save the data to a string and i dont know how to do it.

No your problem is what I said. Once you have fixed that you can consider the next stage of assembling these into a string. There are two types of string, a string and a String, note the capital letter at the start meand these are two different things. Using Strings, while possible is not recommended because every string you create uses memory that is not recovered when that String is removed so you code could appear to work but crash in the long term.

The string on the other hand is sometimes called a C string is a character array terminated by a null (0x00).

As you read in the valid bytes just add then to the next place in a char array. If you start off by setting every place in that array to zero the terminating null will appear automatically at the end provide you have not over run the array's allotted length.

see:- https://forum.arduino.cc/index.php?topic=516472.0

im not sure that I got you…
still doesnt work

void updateSerial()
{
  delay(500);
  while (Serial.available())
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
    for (int i = 0; ((String)(Serial.read()).length < 30); i++) {
    Serial.println(myStrings[i]);
    delay(500);
     }
  }
  while(mySerial.available())
  {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
   
  }

}

Hi meitaldn,

you can go on asking for little details and post code-snippets. Though this will not help very much.

your answer was

OK thanks.
but my problem is that I want to save the data to a string and i dont know how to do it.

I'm not sure what you mean by "data". If I try to guess you mean what you receive over the serial-interface
inside the function updateSerial

char inp=Serial.read();

So if I give a quick and short answer use the concenate-strings function.

In this short it does not help very much. You still will have a lot of questions.

If others should help you in a better way than such short answers you have to provide more information.

Your subject is just "** Sim800l**" what is that? could be a device with serial interface. Provide a datasheet as attachment.
From somehwere you do receive bytes over a serial connection. How many bytes? post a typical sequence of the bytes you do receive.

Write a description of the whole project to give your potential helpers an overview of what you try to achive.
storing.data into a string is not the end-purpose. It is just a detail.

best regards Stefan

Hi Mike ,
Still doesn’t save

#include <SoftwareSerial.h>
//#include <GSM.h>
//Create software serial object to communicate with SIM800L
SoftwareSerial mySerial(4, 5); //SIM800L Tx & Rx is connected to Arduino #3 & #2
//GSM_SMS sms;

char inDataStr[100]="";

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

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

  mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
  updateSerial();
  
  mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
  updateSerial();
  mySerial.println("AT+CNMI=1,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
  updateSerial();
}
void loop()
{
  updateSerial();
  
}

void updateSerial()
{
 // char c;
  //delay(500);
  while (Serial.available()) 
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
    //char data=Serial.read();
    //Serial.println(data,DEC);
  }
  if(int h = mySerial.available() > 50) 
  {
    //Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
   delay(100);
    for(int i=0;i<h;i++)
    {
       inDataStr[i] = (char)mySerial.read();
       Serial.write(inDataStr[i]);
    }


  
  }

}

You have still not got it.

mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port

That byte you are reading from the serial port is being transferred to the software serial port, it is now lost and gone forever you can never recover it or transfer it into a string.

if(int h = mySerial.available() > 50)

That contains two mistakes first you declare in int called h which has no value. Then you make that value equal to h but the the compiler doesn't know what to do with the > 50 so it is ignored.]

Did you mean to do a == not a = if so why is it initialised.

Now suppose you had that line as

if(mySerial.available() > 50) {

Then if it is not > 50 which there is no likely hood of it being then the statement fails and you wip round the loop and cheery pick to top byte again.

And WTF are you doing putting a delay in all this?

I can't see where you are printing out the string you are assembling so how do you know it doesn't work?

some people seem to need weeks or maybe months and hundreds of postings to learn
if you want it real quick it turns out to grow real slow.

nop,
it is that simple : a guy (OP) needs help on SIM800L, and expects from someone who know what is a SIM800L to guide him to solve the problem. If the helper keeps asking why do you need this and that THEN there is no guidance. If whoever tries to help doesn;t know what is a SIM800L, he can ask for it or not answer at all.

To OP :
Absolutely important1: read “Read this before posting a programming question …” , on main "Programming Question " page.

Absolutely important2: read “Serial input basics”. Understand the diff between String and string. You can use the String type - methodology (perhaps it is easier than string methodology) but there is a risk on that, as told before.

very often I had had the case that after looking inside a datasheet for the very first time I was able to help based on my experience with other datasheets and different kind of devices. Thow something that the TO can easily provide he should provide it. Providing the datasheet will rise the possability that more people can help
best regards Stefan

StefanL38:
very often I had had the case that after looking inside a datasheet for the very first time I was able to help based on my experience with other datasheets and different kind of devices. Thow something that the TO can easily provide he should provide it. Providing the datasheet will rise the possability that more people can help
best regards Stefan

ok,
if you insist, just look for these files (~400 pages total)

sim800_series_at_command_manual
SIM800L_Hardware_Design

best regards Dimitri

Look we want links and clickable ones if you can read how to do them.
Do you go to a doctor and say I have this pain and the doctor says where is it? And you reply here is the telephone number of someone who might know? No you don’t, you tell him, just like we expect you to tell us where these documents are.