With my still lacking knowledge and Google, I still have not worked this out.
The code below is from a SIM900L GSM module demo I downloaded.
The loop runs fine, and nothing else is declared anywhere else.
But, it only ever recovers (and therefore Serial.prints) the first 76 characters of the message.
I can only think this is some kind of buffer over-run?
This is where the message is lost, as it never prints the whole message.
The baud is set at 9600 (which is standard for the Sim900l).
The RX buffer is only 64 bytes, you can change it within hwSerial, bbut you could also make the reception non-blocking an remove the delay(500);
Though for a more complete idea of how to fix 'your code' we do need the full sketch.
Yea, I know Strings are the devils work, but this is running on a Teensy at the moment, which doesn't suffer the same string issues (because they fixed it I believe).
The final project ideally will get put back on a Pro Mini where it started, but I need to get my head around it all first.
The code is HUGE (so it is probably too big now for a Pro Mini).
It's definitely that point of the code where it stumbles.
I have looked high and low for the command to increase the size of the RX buffer for AltSoftSerial with no luck.
There is no "command" to change them, but if you look in altasoftserial.cpp you will find these buffer settings. You will need to change them in the library. This solution will limit using your code on other computers.
You may do better to split the TX into pieces, and on the receiving end, read until the end of message rather than when the buffer is empty.
Well the incoming message is a text from a phone, and the first 62 characters are basically wasted as they are the phone number, date etc.
Can't really send the text in pieces, as it will always have those 62 header characters, which leaves next to none available for the rest of the message.
SteveRC2017:
Hmm. Increasing the RX buffer to 200 made no difference.
That is a bit odd, are you sure you changed it in the correct place ?
anyway what you could do is get the reception function to be triggered by a Serial event (just to make sure you don't overrun the buffer, though regular polling would also be OK at 9600 baud)
and do something like this
String ObtainSMSdata(){
String GSMAnswer;
while(GSMSerial.available())
{
char s = (char)GSMSerial.read();
Serial.print(s);
GSMAnswer += s;
if (!GSMSerial.available()) delay(2); // to make sure that if the buffer is empty but there
// is still something on the way it has enough time to get there
}
if(GSMAnswer==""){Sim_error=true;}
Serial.println(F(" "));
return GSMAnswer;
}
Well the increase in memory hasn't solved it, and neither has the bit of revised code above (but thanks for that - I will use that anyway).
I searched my pc, an I only have one instance of AltSoftSerial.cpp. And I changed the line to: #define RX_BUFFER_SIZE 200
Then restarted the IDE just in case.
I thought it might be that 500 delay, but the code does not work without it.
When I send a command to the module - say GSMSerial.println("AT+CREG?"); - this asks for the network Sim information, you need that 500 delay, otherwise it fails.
Odd.
I will keep investigating.
I would post the HUGE entire code, but if I do that, I need to edit a lot of it, as it is full of peoples addresses, phone numbers and some sensitive data.
If I can't make headway, then I will have to do that.
But... it's definitely in this loop where it fails to retrieve the whole message.
I can't give an example yet... not got the circuit here to fire up.
But, you texted a message to the Sim900L that says:
Texting test for Arduino 1234
You would receive something like (but not exactly and phone number hashed out)
+CMT ################ msg 05/11/2019 12.45pm Texting test for Ard
The entire things works fine, as long as the message is shorter than about 20 characters.
But, if you send a longer text message, it basically loses the end
It is possible that the sim memory in the modem itself is full, or partially full so that the last message is truncated.
Can you talk to the modem from your serial monitor using AT commands? I'm not certain what the line ending settings are for your modem, but it might be both NL and CR.
You can try send AT+CMGDA="DEL ALL"
You have not posted any code, nor said whether you are using a gsm library. It will be easier to help you if you provide more information about what you are doing.