I have resized the array to 100 carachters. The thing "interesting" its when i am sending the SMS from my mobile , the Serial repeat some AT commands from setup(). If i am not mistaken Setup function should run only once as loop :o . Take a look on Pictures Attached.
#include <SoftwareSerial.h>
SoftwareSerial MySerial(7, 8);
char incoming_byte[100]; // where to store
int incoming_byte_Index=0; // store the next empty space
char cleanbuffer[100];
int index=0;
int endindex=25;
void setup()
{
Serial.begin(19200); // for serial monitor
MySerial.begin(19200); // for GSM shield
delay(10000); // delay to network
MySerial.println("AT+CMGF=1\r"); // SMS mode totext
delay(100);
MySerial.println("AT+CNMI=2,2,0,0,0\r"); //blurt out contents of new SMS upon receipt to the GSM shield's serial out
delay(100);
MySerial.println("ATE=0"); //echo off
delay(150);
MySerial.println("AT+CMGD=1,4"); // delete the messages
if(MySerial.available()>0){ //"cleaning" buffer, just read all the values
cleanbuffer[index]=MySerial.read();
index++;
}
}
void loop(){
if(MySerial.available()>0) // display any value to serial
{
incoming_byte[incoming_byte_Index]=MySerial.read(); //Array
incoming_byte_Index++; //Index
Serial.println(incoming_byte); //print to serial values
if(strstr(incoming_byte,"TEST")){ //if values in Serial are = "TEST" than sendSMS
Serial.println(incoming_byte); // print again the incoming byte
sendSMS();
incoming_byte_Index=0;
}
}
}
// if display values from sms, should send sms..
void sendSMS()
{
MySerial.println("AT + CMGS = \"+000000000\""); // mobile number
delay(100);
MySerial.println("Hello!"); // message to send
delay(100);
MySerial.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(100);
MySerial.println();
delay(100); // give module time to send SM
}