Issues with GSM Shield 2

Hey guys,

I bought an Arduino GSM Shield 2 with an Arduino Mega. I combined it with some relais and put it in parallel to the ignition lock in my car to be able to start it via SMS. After a while of grinding and finally beating the immobilizer I got everything to work, but I keep having issues with the GSM module.

  1. I can only use the GSM library in the Arduino IDE 1.5.8.
    newer IDEs fail during building, which is pretty annoying

  2. the sms.flush() doesn´t seem to fully work. I create SMS inbox jams constantly and have to reset the SIM in my normal mobile phone, which is pretty annoying since the Arduino is mounted hidden and its not very easy to reach. Once I cleared the SIM everything works again, but at some point the GSM will just stop receiving SMS.

Does one of you know how to resolve the issue with the GSM library in newer IDE´s or can recommend me another programming enviroment?
I heard the Atmel Studio is supposed to be quite good, but I haven´t really worked my way into it.

Do you know what´s wrong with the sms.flush()?
I read somewhere it only clears outgoing messages, not the inbox, but that feels weird. It should just clear the whole memory.

Here is the code:
Sorry, it got a bit messy, I included a power saving mode.

Thanks in advance for the help :slight_smile:
Andre

Edit: I attached the source file and shortened the code below. It exceeded the character limit.

// include the GSM library
#include <GSM.h>
// include power saving library
#include <LowPower.h>
#include <avr/power.h>
#include <avr/sleep.h>
#include <avr/wdt.h>

// PIN Number for the SIM
#define PINNUMBER 0000

// Outputs Arduino
#define IG1 4 // 8 - BY 
#define IG2 5 // 1 - LR - not used, both run through IG1
#define ST2 6 // 3 - R 

// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;

//SMS
// Array to hold the number a SMS is retreived from
char senderNumber[20];
// SMS Command
char Kommando [6] = "Fuck!";
// buffer to read SMS
char c;
// Letter Index
byte smsIndex = 0;
// connection state
boolean notConnected = true;

// Engine Management
// State of Engine State Machine
// 0 - Engine turned off, system in idle
// 1 - Turn Ignition on
// 2 - Start Engine
// 3 - Engine Running
byte State = 0;
// Time stamp when the engine has been started in ms
uint32_t Startzeit_ms = 0;
// Systemclock ms counter
uint32_t VIOS_msCounter = 0;
// How long should the engine run
uint32_t RuntimeEngine = 6000000; //6 000 000 = 20 min

// Power Management
// Sleepcycle counter
byte wait = 26;
// Save Mode
boolean SaveMode = 0;
// Serial Communication activated
boolean SerialOn = 1; 

/* Measured electric power consumption 
in SaveE Mode with 25 sleep cycles
current time power Work           Ah
85 mA 20 s 0,425 W 8,5 W/s        0,47 mAh
63 mA 31 s 0,315 W 9,75 W/s       0,54 mAh
27 mA 3:52 = 232 s 0,135 W 31,32 W/s      1,74 mAh 
______________________________________________________________
 283 s 49,57 W/s      2,75 mAh
 24 h 15 133, 7 W/s = 0,0042 kW/h = 0,839 Ah

in Standby Mode
Ready
current time power Work
63 mA const 0,315 W 0,00756 kW/h/d = 1,512 Ah 
*/


//*********************DECLARE FUNCTIONS**********************************************************//

void initializeGSM()
{
  //activate power supply
  digitalWrite(10, HIGH);

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

  uint32_t stamp = millis();

  while (!sms.available() && VIOS_msCounter < (stamp + 30000))
    {VIOS_msCounter = millis();}
}

void disableGSM()
{
  while (notConnected == false) {
    if (gsmAccess.shutdown()) {
      delay(1000);
      digitalWrite(10, LOW);
      notConnected = true;
    }
    else {
      delay(1000);
    }
  }
  if(SerialOn)
    {Serial.println("GSM disabled");}
}

// Read SMS and set Kommando
char* ReadSMS(char *_Kommando)
{
  if(SerialOn)
    {Serial.println("Message received from:");}

  // Get remote number
  sms.remoteNumber(senderNumber, 20);
  if(SerialOn)
    {Serial.println(senderNumber);}

  // Only accept numbers from my phone
  // Nummer Auto +46 76 589 52 37
  if (strcmp(senderNumber, "+46763050615")   != 0   &&
      strcmp(senderNumber, "+4915757935197") != 0)
  {
    if(SerialOn)
      {Serial.println("Discarded SMS");}
    sms.flush();
  }

  // Read message bytes and construct the array Kommando
  // only 5 letter commands (Start/ Stopp) are accepted
  while (c = sms.read())
  {
    if(SerialOn)
      {Serial.print(c);}
    _Kommando [smsIndex++] = c;
    _Kommando [smsIndex] = '\0';
  }

  if(SerialOn)
  {
    Serial.println("\nKommando ist:");
    Serial.println(_Kommando);
    Serial.println("\nEND OF MESSAGE");
  }

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

  return _Kommando;
}


//************************************************************************************************//

void setup() {
  // initialize serial communications and wait for port to open:
  if(SerialOn)
  {
    Serial.begin(9600);
  //while (!Serial) {
  //  ; // wait for serial port to connect. Needed for native USB port only
  //}
  
    Serial.println("Standheizung V1.0");
  }
}

//*************************************************************************************************************//

void loop() {

  if (wait > 25  || State != 0 || SaveMode == 0)
  {
    if (notConnected)
    {
      initializeGSM();
    }

    VIOS_msCounter = millis();

    // If there are any SMSs available()
    if (sms.available())
    {
      ReadSMS(Kommando);
      
      if(SerialOn)
      {
        Serial.println("\nKommando von function ist:");
        Serial.println(Kommando);
      }
    }

    // Set State
    if (strcmp(Kommando, "Start") == 0)
    {
      State = 1;
      Startzeit_ms = VIOS_msCounter;
    }
    else if (strcmp(Kommando, "Stopp") == 0 ||
             VIOS_msCounter > Startzeit_ms + RuntimeEngine)
    {
      State = 0;
    }
    
    // go to energy save mode
    if (strcmp(Kommando, "SaveE") == 0)
    {
      SaveMode = 1;
      if(SerialOn)
        {Serial.println("\nEnergiesparmodus aktiviert");}
    }
    else if (strcmp(Kommando, "Ready") == 0)
    {
      SaveMode = 0;
      if(SerialOn)
        {Serial.println("\nEnergiesparmodus deaktiviert");}
    }    
      

    // State Machine
    switch (State)
    {
      case 1:
        digitalWrite(IG1, LOW);
        if(SerialOn)
          {Serial.println("\nZuendung an");}
        delay(1000);
        State++;
        break;
      case 2:
        digitalWrite(ST2, LOW);
        if(SerialOn)
          {Serial.println("\nStart Motor");}
        delay(2000);
        State++;
        break;
      case 3:
        digitalWrite(ST2, HIGH);
        if(SerialOn)
          {Serial.println("\nMotor laeuft");}
        break;
      case 0:
        digitalWrite(IG1, HIGH);
        if (SaveMode == 1)
          {disableGSM();}
        break;
    }

    // Reset SMS read out
    Kommando [1] = '0';
    smsIndex = 0;
    wait = 0; 
    //Serial.println(VIOS_msCounter);
    //Serial.println(Startzeit_ms);
  }
  else
  {
    if(SerialOn)
      {Serial.flush();}
    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_ON);
    wait++;
  }
}

Standheizung.ino (7.27 KB)

The “else” condition of the sandard GSM sample doensn´t work either…

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