Seeed Studio GSM/GPRS Shield , Arduino UNO R3, SoftwareSerial -> crash/reset

Hi everyone!

This is my first post here ( actually ,I am more used to digg than to post, but sometimes it seems that I can't overcome some issues I'm facing ... .. so here I am .. )

I am experiencing some issues ( unconsistency, and even "reboot" of the Arduino ( actually printing over Serial stuff from 'setup()', when it should just continue to loop gently ? ) and I can't find the exact reason of it.

I tried several different manners of futfilling my needs ( -> few implementations ), but it seems that somehow "a part of my code / my comments / stuff I do with Serial / SoftwareSerial prints " provoques the issue, wich in turn, seems to act weirdly /randomly with my program (..)

I noticed it seems to happen more or less when I was around 200 lines of codes, wich lead to the following guess [ wich might be TOTALLY WRONG, again, I just don't know why it is doing so .. )

I am posting below the actual code of my last attempt;
-> Nb: the code has been working as it, but it seems something keeps messing sometimes (..)

My last guess is that I have too much Strings [ wasting RAM for nothing ], and that it may somehow provoque a SRAM overflow (?!)

Last [ but not least], I have modified the SoftwareSerial library. (Shipped with Arduino ) up to 128 for the SS_MAX_BUFF ( -> that's the name,right ? (..) )

Also, I am currently on Arduino 1.01 IDE, and I 'm pretty sure I read somewhere that there were:

  • some 20ms delay somewhere, wich could be downed to speed up the serial comm ? ( even if it is not related to my problem )
  • maybe kind of a bogus in some lib files for that particular IDE version (?)

Thanks in advance, any help is very [ very ] much appreciated ( I'm struggling with this for over 2 days now .. )

Nb: the sketch variables used to set / get the stuff were previously using the GPRS phonebook entry, but I removed the code during the "debugging [ debunking? :confused: ] process" (..)
Nb2: and Yup, Toy Story was a great movie ;p
Nb3: I collected some useful AT commands while digging what that shield could actually do & I am willing to post them below if it's of any help to anyone (..)

Have a nice day, while I do need some sleep (..)
Thx again ;p

Code:

#include <SoftwareSerial.h>

SoftwareSerial GPRS(7, 8);

String theMsgStuff= "I am woody the cowboy";

void setup(){
GPRS.begin(19200); // Start the SoftwareSerial wich is using the GPRS UART
Serial.begin(19200); // Start the HardwareSerial wich is using the Arduino UART ( DEBUG OR WHEN CONNECTED TO A COMPUTER .. )
delay(1000);
Serial.println();
Serial.println("[ DEBUG ] mini gprs responder v0.1a");
}

void loop(){
handleIncomingMessages();
}

// main Fcns

void handleIncomingMessages(){
if( GPRS.available() ){ // if new data is coming from the GPRS UART
String content= "";
char character;
while( GPRS.available() ){ // while there's still data in serial ..
character = GPRS.read(); // read a char from the serial to the char
content.concat( character ); // use concat to append the new character to the content
}
// after that, display content if not empty or NULL
if( content != "" ){
//Serial.println( content );
handleMessage( content ); // parse message coming the GPRS UART
content = ""; // empty content
}
}
}

void handleMessage(String aMessage){
if( aMessage.startsWith("\r\n+CMTI: "SM"") ){ // message received from GPRS UART
Serial.println("[ DEBUG ] The SIM900 received a new message");
initMessageRead();
} else {
// I don't fuck*** care (..)
}
}

void initMessageRead(){
GPRS.print("AT+CMGR=1\r"); // write the "read last message" request to the GPRS UART
delay(1000); // let the GPRS print back the response to our request
String messageReceived = getResponseFromGPRS();
Serial.println("[ DEBUG ] Message content from 'initMessageRead()' : ");
Serial.println("[ raw message start ] " + messageReceived + " [ raw message end ] " );

GPRS.print("AT+CMGD=1,4\r"); // write the "delete all messages" request to the GPRS UART
delay(1000); // give it a little bit of time to execute ( and normally return '+CMGR:' )
String messageDeleteSuccFail = getResponseFromGPRS();
Serial.println("[ DEBUG ] Delete all messages received request from 'initMessageRead()' : ");
Serial.println("[ code start ] " + messageDeleteSuccFail + " [ code end ] " );

Serial.println("[ DEBUG ] Infos parsed from message : ");
// get infos from message:
// sender number
String messageOrigin = getMessageOrigin( messageReceived );
Serial.println("[ DEBUG ] Message origin : ");
Serial.println("[ origin start ] " + messageOrigin + " [ origin end ] " );
// actual message ( parsed )
String actualMessage = getActualMessage( messageReceived );
Serial.println("[ DEBUG ] Actual message : ");
Serial.println("[ message start ] " + actualMessage + " [ message end ] " );
// user auth code
String userAuthCode = getAuthCode( actualMessage );
Serial.println("[ DEBUG ] User authentication code : ");
Serial.println("[ auth code start ]" + userAuthCode + "[ auth code end ] " );

userAuthCode = userAuthCode.substring( 1, 5);
Serial.println("[ DEBUG ] User authentication code value is now : " + userAuthCode );

// if user code is admin, set a var of the sketch
Serial.println();
if( userAuthCode.equals("y33b") ){
Serial.println("[ DEBUG ] USER AUTHENTICATION ");
delay(500);
String theMessageToSend = getMessageTocompStuff();
sendMessage( messageOrigin, theMsgStuff );
} else if( userAuthCode.equals("z34a") ){
Serial.println("[ DEBUG ] ADMIN AUTHENTICATION ");
delay(500);

// get the new data from the admin
String theNewNum = getNewNumber( actualMessage );
Serial.println("[ DEBUG ] New number from Admin is : ");
Serial.println("[ new number start ]" + theNewNum + "[ new number end ] " );

//setMessageTocompStuff("ton num est: " + messageOrigin);
setMessageTocompStuff( theNewNum );
delay(500);
String theMessageToSend = getMessageTocompStuff();
sendMessage( messageOrigin, theMsgStuff );

} else if( userAuthCode.equals("unauthorized") ){
Serial.println("[ DEBUG ] UNKOWN AUTHENTICATION ");
} else {
// should not happen (..)
}
}

// Fcn to send text messages
void sendMessage(String number, String dataToSend){
//Serial.println("[ DEBUG ] Composing message for :" + number + " with: " + dataToSend + " as message content");
//delay(500);
String composeMsgCmd = "AT+CMGS="" + number + """; // build the 'compose new text message' AT command
GPRS.print( composeMsgCmd + "\r"); // write the "compose new text message" request to the GPRS UART
delay(1000); // give it a little bit of time to execute ( and normally return '> ' )

// add content to the message
GPRS.print( dataToSend );
delay(1000);
GPRS.print( (char)26 ); //the ASCII code of the ctrl+z is 26
delay(1000); // give it a little bit of time to execute ( and normally return '+CMGS: ' )
// THE MESSAGE SHOULD HAVE BEEN SENT TO WHOEVER REQUESTED THE NEW NUMBER BY NOW
Serial.println("[ DEBUG ] Message sent!");

}

// Test Fcn
String getResponseFromGPRS(){
if( GPRS.available() ){ // if new data is coming from the GPRS UART
String responseContent= "";
char responseChar;
while( GPRS.available() ){ // while there's still data in serial ..
responseChar = GPRS.read(); // read a char from the serial to the char
responseContent.concat( responseChar ); // use concat to append the new character to the content
}
return responseContent; // return the responseContent
}
}

// Fcn to set the message stuff
void setMessageTocompStuff(String theNewMessageStuff){
theMsgStuff = theNewMessageStuff;
}

// Fcn to get the message stuff
String getMessageTocompStuff(){
return theMsgStuff;
}

// HELPER FCNS FOR STRING PARSING //

// to get the number of the sender of the message
String getMessageOrigin(String theMessageFromGPRS){
//String theMsgOrigin = theMessageFromGPRS.substring(21,33); // extract what is between index 21 and index 33, wich hould be the number the message originated from
String theMsgOrigin = theMessageFromGPRS.substring(33,45);
return theMsgOrigin; // return it
}

// Fcn to trimm Strings
String trimmThat(String stuffToTrimm){
stuffToTrimm.trim();
return stuffToTrimm;
}

// to get the actual message out of a message received from the GPRS UART
String getActualMessage(String theMessageFromGPRS){
//String theActualMsg = theMessageFromGPRS.substring(61,78); // extract what is between index 61 and index 78, wich hould be the actual message
//String theActualMsg = theMessageFromGPRS.substring(73,90);
//String theActualMsg = theMessageFromGPRS.substring(81,98);
//String theActualMsg = theMessageFromGPRS.substring(81,140); // 30 more than necessary ;p but seems to leave the \r\n before the real content
String theActualMsg = theMessageFromGPRS.substring(83,110); // fixed :stuck_out_tongue: 110 cause i am afraid it could cause some leaks ..
//theActualMsg.trim(); // the actual message has a \r\n in front of it (..)
return theActualMsg; // return it
}

// to get the authentication code from the actual message
String getAuthCode(String theActualMessage){
String theAuthCode = theActualMessage.substring(0,7); // extract what is between index 0 and index 6, wich should be the authentication code
return theAuthCode; // return it
}

// to get the new number from the actual message
String getNewNumber(String theActualMessage){
//String theNewNumber = theActualMessage.substring(7,17); // extract what is between index 8 and index 17, wich should be the new number
String theNewNumber = theActualMessage.substring(7,18);
return theNewNumber; // return it
}

// to get the number out of the phonebook entry
String getNumberFromPhonebookEntry(String theMessageFromGPRS){
String theCurrentNumber = theMessageFromGPRS.substring(10,20); // extract what is between index 10 and index 20, wich should be the current number held by the phonebook entry
return theCurrentNumber; // return it
}

I would kindly suggest that you do not use expletives in your code, as this site is used by people of all ages, and such language is highly inappropriate.

You may also find that people are more willing to help you....