gsm if statements controlling a transistor

hi. my name is Christoper Richard Alcantara from Catanduanes National High School, Philippines. my codes dont work. when i text off/on it doesnt do anything. please help. thank you. heres my code

/* This code is modified by Christoper Richard Alcantara and Jayson Tenerife for their project in Robotics

  • Project Title:
  • February 28, 2017
    */

#include <GSM.h>
#include <GSM3CircularBuffer.h>
#include <GSM3IO.h>
#include <GSM3MobileAccessProvider.h>
#include <GSM3MobileCellManagement.h>
#include <GSM3MobileClientProvider.h>
#include <GSM3MobileClientService.h>
#include <GSM3MobileDataNetworkProvider.h>
#include <GSM3MobileMockupProvider.h>
#include <GSM3MobileNetworkProvider.h>
#include <GSM3MobileNetworkRegistry.h>
#include <GSM3MobileServerProvider.h>
#include <GSM3MobileServerService.h>
#include <GSM3MobileSMSProvider.h>
#include <GSM3MobileVoiceProvider.h>
#include <GSM3ShieldV1.h>
#include <GSM3ShieldV1AccessProvider.h>
#include <GSM3ShieldV1BandManagement.h>
#include <GSM3ShieldV1BaseProvider.h>
#include <GSM3ShieldV1CellManagement.h>
#include <GSM3ShieldV1ClientProvider.h>
#include <GSM3ShieldV1DataNetworkProvider.h>
#include <GSM3ShieldV1DirectModemProvider.h>
#include <GSM3ShieldV1ModemCore.h>
#include <GSM3ShieldV1ModemVerification.h>
#include <GSM3ShieldV1MultiClientProvider.h>
#include <GSM3ShieldV1MultiServerProvider.h>
#include <GSM3ShieldV1PinManagement.h>
#include <GSM3ShieldV1ScanNetworks.h>
#include <GSM3ShieldV1ServerProvider.h>
#include <GSM3ShieldV1SMSProvider.h>
#include <GSM3ShieldV1VoiceProvider.h>
#include <GSM3SMSService.h>
#include <GSM3SoftSerial.h>
#include <GSM3VoiceCallService.h>
int transistorPin = 13;
#define PINNUMBER ""
char senderNumber[20];
GSM gsmAccess;
GSM_SMS sms;

void setup(){

// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

Serial.println("SMS Messages Receiver");

// connection state
boolean notConnected = true;

// Start GSM connection
while (notConnected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
notConnected = false;
} else {
Serial.println("Not connected");
delay(1000);
}
}

Serial.println("GSM initialized");
Serial.println("Waiting for messages");

pinMode(transistorPin, OUTPUT);
}

void loop(){
char c;
// If there are any SMSs available()
if (sms.available()) {
Serial.println("Message received from:");

// Get remote number
sms.remoteNumber(senderNumber, 20);
Serial.println(senderNumber);

// An example of message disposal
// Any messages starting with # should be discarded
if (sms.peek() == '#') {
Serial.println("Discarded SMS");
sms.flush();
}

// Read message bytes and print them
while (c = sms.read()) {
Serial.print(c);
}
char c;
String received = "";

while(c=sms.read())
received += c;

if(received.compareTo("on") == 0)
{
digitalWrite(transistorPin, HIGH);
}
else if(received.compareTo("off") == 0)
{
digitalWrite(transistorPin, LOW);
}
else
{
}
Serial.println("\nEND OF MESSAGE");

// Delete message from modem memory
sms.flush();
Serial.println("MESSAGE DELETED");
}

delay(1000);
}

What do you see if you print the received message ?

UKHeliBob:
What do you see if you print the received message ?

i can only see the texts through the serial monitor. What is really peculiar is that the LED connected to the transistor is not affected by texts messages although i tried my best to come up with the code given. Im really cross fingered if itll work. Is there something wrong with my codes? everyone? please. Maraming Salamat. Thank you!

   // Read message bytes and print them
     while (c = sms.read()) {
      Serial.print(c);
    }

Read each and every character from text message, and do nothing except print them to the serial port.

String received = "";

      while(c=sms.read())
      received += c;

Then, for some mysterious reason, think that you can do it again. Once you've read a character, it is gone. You can't read the same character again.

You need to ditch the first block of code, and print the value in received after the second while loop ends. The second while loop needs curly braces, too, to prove that YOU know the extent of the while loop.

char c;
String received = "";
{
while(c=sms.read())
{
Serial.print(c);
}
received += c;

if(c == received.compareTo("on") == 1)
{
digitalWrite(transistorPin, HIGH);
Serial.println("Device successfully turned on");
}

else(c == received.compareTo("off") == 0)
{
digitalWrite(transistorPin, LOW);
Serial.println("Device successfully turned off");
}
else <======= says expected ';' before '{' token heeeeeeeeelppppp
{
Serial.println("\nEND OF MESSAGE");
}

// Delete message from modem memory
sms.flush();
Serial.println("MESSAGE DELETED");
}
delay(1000);
}
}

please help huuhuhuhuhuhu

while(c=sms.read())
    {
    Serial.print(c);
    }
      received += c;

Exactly when do you want to add the damned character to the String? After reading the last character as you are doing here?

Or after reading EACH character?

    while(c=sms.read())
    {
       Serial.print(c);
       received += c;
    }

Your indenting sucks. Use Tools + Auto Format before posting code again.

And, damn it, start using code tags!