I want to send AT commands to SIM900 module through Serial terminal. This is driving me crazy, I've been stuck with this problem about 5 hours now.
I can communicate fine with the module(SoftwareSerial), for example:
SIM900.print("AT+COPS?\r");
I'm able to receive all the information. But I'd like to insert commands directly through the Serial terminal too.
This is what I have, but it's not working:
if (Serial.available()){
String inputString;
while (Serial.available())
{
char inChar = (char)Serial.read();
inputString += inChar;
}
SIM900.print(inputString);
}
Is it because all the characters are separated? If I use Serial.println, all the characters appear on different lines, thus they probably have carriage return after each character, so instead of "AT+COPS?\r" I'm sending "A\r\nT\r\n+\r\nC\r\nO\r\nP\r\nS\r\n?\r\n"
How can I truncate those characters to one piece of string?
I have tried strcat and various methods also with no avail.
!NOTE! If you add delay to receiving, buffer might fill out faster than you can read the characters, so everything longer than 64 characters will get cut.
Solution: remove the delay if possible or increase buffer size to 128 or 256(very high, takes away from SRAM).
It was about that little thing all the time. I was so sure that it should work with that code that it made me insane. It just needed some extra time.
If anyone knows a better workaround for this, please let us know. Delaying is never a good option, but in my case, I don't need super lightning fast transmissions.
Only if I add "delay(1)" to the loop, I'm able to send the packet as a whole!
Or you can use the method that I explained in the thread I mentioned ;). That was what I wanted to tell you, the library command is just sending the AT command over serial just like you do.
MathiasVDA:
Or you can use the method that I explained in the thread I mentioned ;). That was what I wanted to tell you, the library command is just sending the AT command over serial just like you do.
Yes, but you need to include GSM library files for that. I'm short on space and can't waste it on libraries.
The library performs this function, which is equivalent to my own written one:
if(trace)
Serial.println(ATcommand);
// Flush other texts
flush();
//Enter debug mode.
connect();
//Send the AT command.
println(ATcommand);
delay(responseDelay);
//Get response data from modem.
String result = "";
if(trace)
theGSM3ShieldV1ModemCore.gss.cb.debugBuffer();
while (available())
{
char c = read();
result += c;
}
if(trace)
Serial.println(result);
//Leave the debug mode.
disconnect();
return result;
}