Error communicating with mobile phone

A friend has used a UNO3 and mobile to report back to his mobile. He has written a test programme for me which should send information back to my mobile when I text Report. There clearly is communication between my receiving mobile and the UNO but when it receives a the text message it does not provide the information. This can be seen from the abstract of the serial monitor I have included below from my PC.

Example test code for Ray Rogers

Received from phone: "+CMGL=1" Received from phone: "OK" Received from phone: "+CMGL=1" Received from phone: "+CMGL: 1,1,,25" SMS details received MsgID: 1 MsgSender:0C91449746894732 Received from phone: "+CMGL: 1,1,,25" MsgText:+CMGL: 1,1,,25 Received from phone: "+CMGL=1" Received from phone: "OK" Received from phone: "+CMGL=1"

The sketch is included in a seperate post due to length.

Is anyone able to help regarding the errors I am receiving please? I am very new to the subject.

#include <SoftwareSerial.h> // This adds in the libray for the serial port used to connect to phone. Ensure _SS_MAX_RX_BUFF is set to 100 in SoftwareSerial.cpp - this is just to limit memory usage as we only have 1K

//Phone setup stuff
boolean SMSReceived = false;
SoftwareSerial phone(2, 3); // Phone serial port connected to pins 2 and 3
char PhoneBattery[4], PhoneSignal[4];
char SMSBuffer[170];
String NextPhoneSerialLine=""; // Temporary string used while parsing phone response
char MsgSender[17]; // Encoded SMS number of the sender of the SMS (used again for replying)
String MsgText=""; // Content of SMS
char MsgID[3]; // ID of SMS in phone memory. Needed to be able to delete it after reading

//routines for sending septets - this is part of the conversion from plain text to PDU for sending a text
#define num_to_char(number)   ((number) < 10 ?                           \
                                               ('0' + (number)) :        \
                                               (('A' - 10) + (number)) )
/* To select the 4 bits we do this */
#define first_four(byte)       (0x0F & (byte))
/* Last four: Shift left to get to a number < 16 */
#define  last_four(byte)      ((0xF0 & (byte)) >> 4)
/* The MSB goes first. */
#define hexdump_a(byte)  num_to_char( last_four(byte))
#define hexdump_b(byte)  num_to_char(first_four(byte))

//Define Arduino pins
int LEDPin = 13; // Use this LED to flash just to show things are still happening! 


void setup() // This code runs once on start-up and then control passes to loop()
{
  Serial.begin(9600); //Open debug serial port (i.e. USB debug)

  Serial.println(F("Example test code for Ray Rogers")); // Output program version
  
  phone.begin(9600); // Start the serial port to the phone at 9600 baud
  phone.flush(); // Clear any messages in the buffer just to be sure

  // Set up LED output pin
  pinMode(LEDPin, OUTPUT); // Needed to tell the Arduino to use this pin as an output and not an input
  
}

void loop() // This code now runs repeatedly
{
  // Turn on built-in Arduino LED so we can have a visual idea of things happening
  digitalWrite(LEDPin, HIGH);
  
      // Call the SMS check routine which will call SMS send/clear if required
      CheckPhone();

      // Now check message to see if it contains any commands
      if (MsgText.substring(0,10) == "04C8321B0E") // SMS message = "Help"
          {
            Serial.println(F("Help"));
             send_sms(MsgSender,"Try texting Report to me :)"); // Respond back to the sender with a fixed text string
          }
        if (MsgText.substring(0,14) == "06D232FC2DA703") // SMS message = "Report"
          {
            Serial.println(F("Report"));
            GetPhoneData(); // Get the phone battery and signal strength
            sprintf(SMSBuffer, "PhoneBatt:%s\nPhoneSig:%s",  PhoneBattery, PhoneSignal); // Build text string for the SMS
            send_sms(MsgSender,SMSBuffer); // Respond back to the sender with a string that we have just created
          }
       //Clear MsgText ready for next check
       MsgText="";

  // Turn off LED to show we have finished our checks
  digitalWrite(LEDPin, LOW);
  
  //Now wait 10 seconds and the loop() routine will then start again
  delay (10000);
}

void GetPhoneData(void)
{
  Serial.println(F("Getting Phone Data"));
  
  // Get Phone signal strength
  phone.println("AT+CSQ"); // Send request to phone
  delay(1000); // Wait for response to be available
  while (phone.available()) // Now check through the response to get the data needed
  {
    ReadPhoneSerialLine();
    if (NextPhoneSerialLine.startsWith("+CSQ:")) // This identifies that this is the response line we need.
    {
       PhoneSignal[0] = NextPhoneSerialLine[6];  // Copy first character
       if (NextPhoneSerialLine[7] == ',') // If the next character is "," then the signal strength is ony one character anyway...
       {
         PhoneSignal[1] = '\0'; // so terminate the string...
       }
     else
     {
       PhoneSignal[1] = NextPhoneSerialLine[7];  // otherwise add the next character...
       PhoneSignal[2] = '\0'; // and then terminate the string
     }
    }
  }

  // Get Phone Battery
phone.println("AT+CBC"); // Send request to phone
delay(1000); // Give time for response
while (phone.available()) // Parse phone response
{
  ReadPhoneSerialLine();
  if (NextPhoneSerialLine.startsWith("+CBC:"))// This identifies that this is the response line we need. 
    {
      // Copy battery level string over
     PhoneBattery[0] = NextPhoneSerialLine[8];  
     PhoneBattery[1] = NextPhoneSerialLine[9];  
     PhoneBattery[2] = NextPhoneSerialLine[10];  
     PhoneBattery[3] = '\0';
     //remove spaces at end
    if  (PhoneBattery[2] == ' ') {PhoneBattery[2] = '\0';}
    if  (PhoneBattery[1] == ' ') {PhoneBattery[1] = '\0';}
     }
     
}
}

void ReadPhoneSerialLine() // Read a whole line from the phone
{
  int i=0;
  byte NextByte;
    if(phone.available())
    {
      NextPhoneSerialLine="";
      NextByte=phone.read();      
     while( phone.available() && (NextByte != '\n') && i< 99)
       {
        NextPhoneSerialLine = NextPhoneSerialLine + char(NextByte);
        NextByte=phone.read();
        i++;
       }
    }
  Serial.print(F("Received from phone: \""));
  Serial.print(NextPhoneSerialLine);
  Serial.println("\"");
}

void DiscardXBytes(int X) // Get rid of the next X bytes from the phone buffer. This is used when parsing the SMS data to get to the bits we need.
{
 for (int x=0; x < X; x++)
  {
     phone.read(); // Simply reads the next x characters to get them out of the buffer
  } 
}

void hexdump_byte(unsigned char byte) // Part of the SMS PDU octet conversion
{
  phone.write(hexdump_a(byte));
  phone.write(hexdump_b(byte));
}


void send_sms(char *PhoneNumber, char *data) // Main routine to send SMS
{
// Clear buffers just in case  
  phone.flush();
  
// Set up temporary variables
  size_t data_length, x;
  char c, l;
  long i;
  long n;

  data_length = strlen(data); // Get length of message to send
  Serial.print(F("PhoneNumber length:"));
  Serial.println((strlen(PhoneNumber) / 2),DEC);

Moderator edit: thanks for the object lesson in why we ask you to post code in CODE TAGS.

Serial.print(F(“SMS data length:”));
Serial.println(data_length,DEC);
i = data_length * 7; // This gives us the length of the data needed with 7 bits per character (instead of the normal 8)

// Round i up to a multiple of 8 as it needs to be packed in to the 8 bit serial message
if (i & 0x07) i = (i & ~0x07) + 0x08;
// Calculate the number of message octets
i = i / 8;

// Start sending SMS command(s)
phone.println(“AT+CMGF=0”); // Set SMS mode
delay(1000);
ShowAllPhoneResponse(); // Clear out the response
phone.print(“AT+CMGS=”); // This is the main SMS command and is followed by the message length
delay(1000);
phone.println(i + 6 + (strlen(PhoneNumber) / 2) ); // = data octet number + 6 + length of number (in octets)
delay(1000);
ShowAllPhoneResponse(); // Clear out the response and then we need to send the actual data
phone.print(“001100”); // Initial part of SMS command - fixed data
phone.print(PhoneNumber); // Add phone number to SMS command
phone.print(“0000AA”); // Fixed SMS command data

// Now step through the data, convert it to septets and send that to the phone as part of the AT+CMGS command
hexdump_byte(data_length & 0xFF);

l = 0;
n = 0;

for (x = 0; x < data_length; x++)
{
if (data == ‘$’) data = 0x02;

n |= (data & 0x7F) << l;
l += 7;

if (l >= 8)
{
hexdump_byte(n & 0xFF);
l -= 8;
n >>= 8;
}
}

if (l != 0)
{
hexdump_byte(n & 0xFF);
}
phone.write((byte)26); // ASCII equivalent of Ctrl-Z which indicates that the message content is finished
phone.println(); // Finishes off serial command

Serial.print(data);
Serial.print(F(" sent to "));
Serial.println(PhoneNumber);

delay(1000);
ShowAllPhoneResponse(); // Clear out the response

}

void ShowAllPhoneResponse() // Routine to keep reading lines from the phone until no more. Useful as some commands return more than one line
{
while (phone.available())
{
ReadPhoneSerialLine();
}
}

void CheckPhone()
{

SMSReceived = false; // Reset flag for checking if SMS has been received

//Check for SMS
delay(1000);
phone.println(“AT+CPMS=“ME””); // Ensure phone SMS storage is used
delay(1000);phone.flush(); // Wait and flush as we don’t need the answer

phone.println(“AT+CMGL=0”); // List all new phone messages to make them unread
delay(1000);phone.flush(); // Discard data

phone.println(“AT+CMGL=1”); // List all read messages now
delay(1000);
while (phone.available())
{
ReadPhoneSerialLine();
if (NextPhoneSerialLine.startsWith("+CMGL:")) //Message details received
{
SMSReceived = true; // Set SMSReceived to ensure CheckPhone is called again
Serial.println(F(“SMS details received”));
//Store the MsgID for deletion etc later
MsgID[0] = NextPhoneSerialLine[6];
MsgID[1] = NextPhoneSerialLine[7];
MsgID[2] = ‘\0’;
Serial.print(F(“MsgID:”));
Serial.println(MsgID);

//Get next line of data and extract Sender details and message
DiscardXBytes(18); //Jump to fixed position for Sender number
for (int x=0; x < 16; x++)
{
MsgSender = phone.read(); // Read out sender number
}
Serial.print(F(“MsgSender:”));
Serial.println(MsgSender);
DiscardXBytes(18); // Jump to text message content
ReadPhoneSerialLine(); //Read text message from here to the end of the line
MsgText = NextPhoneSerialLine;
Serial.print(F(“MsgText:”));
Serial.println(MsgText);

// Delete the message using the MsgID read earlier
phone.print(“AT+CMGD=”);
phone.println(MsgID);// Delete the message
delay(1000);phone.flush(); // Discard data

}
}

}