Even TimerEvent stops working if GSM shield is *off* (why?)

This simple aplication fail.
GSM shield have a simple on/off push and hold button.
if - upon application start, the GSM shield is ON, then it will be switched off by setup, so I tried to see if setup commands were acknowledged by OK, -problem is that is GSM shield is OFF, timerEvent() is never reached.

//for Arduino UNO
//Serial terminal at 57600baud
//todo , proper handling of GSM module being off.


#include <SoftwareSerial.h>
#include <string.h>
#include <Wire.h>
#include <MsTimer2.h>
#define DEV_ID 0x48 //0x90 >> 1 // shift required by wire.h  (address for DS1621)

int8_t firstByte;  //temp
int8_t secondByte; //temp.decimal
float temp = 0;
int POW = 0; //used to store heater status
String warn = "";  //warning string
SoftwareSerial Sim900Serial(7, 8);  
int SIM900_init_sent = 0; //set to 1 after commands are issued, so we know if there was an error or it was off.
int SIM900_responding = 0;  // remember if we ever got a response.
int loopcount = 0;  
int readline(int readch, char *buffer, int len)
{
  static int pos = 0;
  int rpos;

  if (readch > 0) {
    switch (readch) {
    case '\n': // Ignore new-lines
      break;
    case '\r': // Return on CR
      rpos = pos;
      pos = 0;  // Reset position index ready for next time
      return rpos;
    default:
      if (pos < len - 1) {
        buffer[pos++] = readch;
        buffer[pos] = 0;
      }
    }
  }
  // No end of line has been found, so return -1.
  return -1;
}


void readtemp(){
    //Get temperature
    Wire.beginTransmission(DEV_ID);
    Wire.write(0xAA); // read temperature command
    Wire.endTransmission();
    Wire.requestFrom(DEV_ID, 2);	// request two bytes from DS1621 (0.5 deg. resolution)

    firstByte = Wire.read();	// get first byte
    secondByte = Wire.read();	// get second byte

    temp = firstByte;
    if (secondByte)	// if temperature ends with .5 deg 
    temp += 0.5;  //set temperature variable
}


void setup()
{
  Serial.begin(57600);  // Serial port of Arduino board, used for debugging
  pinMode(9, OUTPUT);   // start by turning on SIM900
  digitalWrite(9, LOW);
  delay(1000);
  digitalWrite(9, HIGH);
  delay(2500);
  digitalWrite(9, LOW);
  delay(3500);

  Serial.println("Init 1621");
  // init DS1621
  Wire.begin();
  Wire.beginTransmission(DEV_ID); // connect to DS1621 (#0)
  Wire.write(0xAC); // Access Config
  Wire.write(0x02); // set for continuous conversion
  Wire.beginTransmission(DEV_ID); // restart
  Wire.write(0xEE); // start conversions
  Wire.endTransmission();

  Serial.println("Init IO");
  //Define IO
  pinMode(10, OUTPUT);   // Pin starts heater when high
  digitalWrite(10, LOW);

  pinMode(11, INPUT);    // senses heater LED

  Sim900Serial.begin(19200);     // the SIM900 baud rate
  //  GPS.begin(9600);           // GPS module baud rate

  Sim900Serial.println("AT+CMGF=1");    // Set GSM shield to sms mode   
  Serial.println("AT+CMGF=1");
  delay(500);
  Sim900Serial.println("AT+CNMI=2,2");
  Serial.println("AT+CNMI=2,2");
  delay(500);
  SIM900_init_sent = 1;
  
  /* initialize interupt timer for events */
  MsTimer2::set(10000, timerEvent);  /* set timer to 10s interval */
  MsTimer2::start();
}


void timerEvent(){
        Serial.println("Timerevent");
        if (SIM900_init_sent == 1 && SIM900_responding == 0 ){            //have not seen OK yet, GSM must be off, switch on.
        Serial.println("No OK from SIM900 , starting setup.");
        delay(2000);
        setup();
      }
}



void loop(){  
  
  static char buffer[80];
  if (readline(Sim900Serial.read(), buffer, 80) > 0) {  
    Serial.print(buffer);    //Send text from SIM900 to serial interface for debug.
    readtemp();
    Serial.print("        temp: ");
    Serial.print(temp);
    Serial.println("degC"); 

    if (strstr(buffer, "Status"))      //Check output for text from received SMS
    {
      Serial.println("Command Status Receieved.");
      SendStatusMessage();
    }

    if (strstr(buffer, "Heater on"))   //Check output for text from received SMS
    {
      Serial.println("Command Heater on Receieved.");
      HeaterON(1);
      SendStatusMessage();
    }

    if (strstr(buffer, "Heater off"))   //Check output for text from received SMS
    {
      Serial.println("Command Heater off Receieved.");
      HeaterON(0);
      SendStatusMessage();
    }

    if (strstr(buffer, "OK"))   //Check output for OK
    {
      SIM900_responding = 1;
    }    



  }
}



void SendStatusMessage()
{
  Sim900Serial.print("AT+CMGF=1\r");    //1 = Sending the SMS in text mode  , 0=PDU mode
  delay(100);
  Sim900Serial.println("AT+CMGS = \"+47000000\"");//The predefined phone number
  delay(100);
  Sim900Serial.print(temp);
  Sim900Serial.println("C"); 


  POW = digitalRead(11);
  if (POW == HIGH)    
  {
    Sim900Serial.println("Heater ON");
  }
  else
  {
    Sim900Serial.println("Heater OFF");
  }


  if (warn != "")    //if there is a warning, attach it
  { 
    Sim900Serial.println(warn);
    warn = "";
  }

  delay(100);
  Sim900Serial.println((char)26);//the ASCII code of the ctrl z is 26  (END of SMS)
  delay(100);

}


int HeaterON(int s)   //s=1 switch on , 0=switch off
{
  if (s == 1)   //if wish to switch on
  {
    POW = digitalRead(11);
    if (POW == HIGH)    //Comparing command
    { 
      Serial.print("Warning: Heater already ON");
      warn = "Warning: Heater was already ON, command aborted";
    }
    else
    {
      for (int i=0; i <= 4; i++)
      {
        Serial.println("Heater starting.");
        POW = digitalRead(11);
        if (POW == LOW)  digitalWrite(10, HIGH);  //only press button if heater is off
        delay(500);
        digitalWrite(10, LOW);
        delay(300);
      }
    }
  }
  else
  {
    POW = digitalRead(11);
    if (POW == LOW)    //Comparing command
    { 
      Serial.print("Warning: Heater already OFF");
      warn = "Warning: Heater was already OFF, command aborted";
    }
    else
    {
      {
        for (int i=0; i <= 4; i++)
        {
          Serial.println("Switching heater off.");
          POW = digitalRead(11);
          if (POW == HIGH)  digitalWrite(10, HIGH);  //only press button heater is on
          delay(500);
          digitalWrite(10, LOW);
          delay(300);
        }
      }
    }   

    delay(200);
  }
}

You are doing several Serial.println. How far do you get when the shield is off?

in debug terminal, I see result of Serial.println("AT+CNMI=2,2");

I suspected that if (readline(Sim900Serial.read(), buffer, 80) > 0) { hing it until teh RX pin on Uno went low/high , but adding a if (Sim900Serial.available ..... before read did not help. I still suspect that disabled GSM shield leaves a pin in a state that SoftwareSerial does not handle well. - softwareserial may disable timer interrupt because it's time critical itself ?

that would explain it..

I've also tried to add after " SIM900_init_sent = 1;" Serial.println(digitalRead(7)); Serial.println(digitalRead(8));

not sure about the read capability after these pins are assigned to softwareserial, but both return 1 in both on and off state of the gsm shield.

void timerEvent(){
        Serial.println("Timerevent");
        if (SIM900_init_sent == 1 && SIM900_responding == 0 ){            //have not seen OK yet, GSM must be off, switch on.
        Serial.println("No OK from SIM900 , starting setup.");
        delay(2000);
        setup();
      }
}

You can't do Serial.print() in an ISR. That might not be obvious to everybody. You can't do delay() in an ISR. That one is plain stupid.

ok, it looks stupid, but it it's right before setup() - which will actually turn on the device. - no no harm done. I do (still) not know why I can't print from it. - or if print and delay does not work - wht setup() does not get trigged.

PaulS isn't saying that it looks stupid - he's saying that you cannot do these things in an Interrupt service routine. You should make them as brief as possible, usually setting or incrementing a variable (declared volatile) and then exiting the routine. Your main code should then take action, if necessary, based on the setting that has been changed.

ok, it looks stupid, but it it's right before setup() - which will actually turn on the device. - no no harm done. I do (still) not know why I can't print from it. - or if print and delay does not work - wht setup() does not get trigged.

delay() waits until the clock has ticked some number of times. Let's imagine that we are in your ISR. Do you hear the clock ticking? NO! The clock does not tick while the ISR is running. So, delay() will never end, because it isn't hearing the correct number of ticks.

The setup() function will be called when the correct number of ticks happens. But, that will be a long time after the sun fades to oblivion.