I'm trying to make automatic SMS message resender with Arduino UNO and A GSM SIM900 module.
I've run into a problem when I try to read the incoming data, the sent command to GSMmodule also gets read. It is not a big problem but id like to know why this happens and how to solve it. I tried to use Serial.flush() command after sending data but it did not help. I have a creeping suspicion that the problem is that I use the Serial.readString() comand. but I could not find anything on the nets about it. here is my code
#include <SoftwareSerial.h>
SoftwareSerial GSM(9,10);
String red;
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
GSM.begin(9600);
Serial.begin(9600);
GSM.println("AT+CMGR=3"); //i send comand to gsm to read 3 message
}
void loop()
{
if (GSM.available()>0) // Check if serial available
{
red = GSM.readString(); // read the incoming data
}
Serial.print(red); // print the String to serial
}
Yes I had red through it but I did not find anything on using String variable and at least for me it looks easier to use it. I cant use end and start markers because the of the commands I send and data I receive from GSM. That's why I turned for help in here.
For String based read solutions see my tutorial Arduino Software Solutions
Re 'efficiency', the slowest and most inefficient part of software is the coder, use whatever you find easest.
For Arduino String usage and tips see my tutorial Taming Arduino Strings
Strings are very very safe to use in UNO.
For GSM there are often an number of sequences of cmd/response complicated by the delays inbetween. I seem to remember someone has a simple library for handling 'send cmd' wait for response. Any one have the link?