Pages: [1]   Go Down
Author Topic: Need sometime a reboot for receiving call/sms  (Read 966 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all!
I searched in this forum a problem like this, but i didn't found nothing.
I made a sketch for commanding 3 relays with a call or and sms.
I'm using Arduino UNO rev.3  with an original GSM Shield (with a Vodafone SIM that works correctly).
I don't understand why sometime i need to restart Arduino after the power on, because the "gsmSMS.available()" and "gsmCall.getvoiceCallStatus()" doesn't work (or 2 or 3 consecutive restart).
When i finally receive the first sms, Arduino starts to work correctly until the next Sketch upload or power OFF.


Code:
#include <GSM.h>

GSM gsmAccess;
GSMVoiceCall gsmCall;
//GSMScanner gsmNetwork;
GSM_SMS  gsmSMS;

const int intDefaultGSMDelay = 2000; // prima di ricontrollare un nuovo stato, devo attendere almeno un secondo
boolean blnGSMConnection = false;

char* lstAllowedPhone[3]={"123456","123456"};   //Contiene la linsta dei numeri abilitati ai comandi
char* lstAllowedPhonePlusNumber[2]={"+39123456,"+39123456"}; //Stessa lista di prima, ma con il carattere + iniziale

const int intPinGate = 8;
const int intPinSmallGate = 9;
const int intPinDoor = 10;
const int intPinGSMCom = 13;

const int intOpenSmallGate = 1;
const int intOpenGate = 2;
const int intOpenDoor = 3;

const int intDelayRelayCmd = 1500;
//-----------------------------------------------------------------------------------------------------CONFIGURAZIONE----------------------------------------------------------------------
void setup()
{
  //Serial.begin(9600);
  
  pinMode(intPinGate,OUTPUT);
  pinMode(intPinSmallGate,OUTPUT);
  pinMode(intPinDoor,OUTPUT);
  pinMode(intPinGSMCom,OUTPUT);
  
  digitalWrite(intPinGSMCom,LOW);  //Led di stato a Zero
  IniRelays();
  
  while(!blnGSMConnection)  
  {
    Serial.println(gsmAccess.getStatus());
    if (gsmAccess.begin("")==GSM_READY)  //gsmAccess.begin("",true,false), Inizializzazione Scheda SIM : PIN, Restart, Async
      blnGSMConnection = true;
    else
    {
      delay(1000);
    }  
  }
  
  gsmCall.hangCall();
  
  digitalWrite(intPinGSMCom,HIGH); //Set Up OK
}
//--------------------------------------------------------------------------------------------------------LOOP------------------------------------------------------------------------------------------      
void loop()
{
  OpenOutPut(intCheckIncomingAction());
  //gsmNetwork.getSignalStrength()); //Leggo la qualità del segnale [0-31]
}

//--------------------------------------------------------------------------------------------------------INVIO COMANDO----------------------------------------------------------------------------------------------
void OpenOutPut(int intType)
{
  switch (intType)
  {
    case intOpenSmallGate:
      SendCommand(intPinSmallGate);
      break;
    case intOpenGate:
      SendCommand(intPinGate);
      break;
    case intOpenDoor:
      SendCommand(intPinDoor);
      break;  
  }
}

//-------------------------------------------------------------------------------------------------------------GESTIONE RELE (PUSH BUTTON)---------------------------------------------------------------------------------------
void SendCommand(int intDevice)
{
  digitalWrite(intDevice,LOW);
  delay(intDelayRelayCmd);
  digitalWrite(intDevice,HIGH);  
}

//-------------------------------------------------------------------------------------------------------------INIZIALIZZAZIONE RELE (OFF)---------------------------------------------------------------------------------------
void IniRelays()
{
  digitalWrite(intPinSmallGate,HIGH);
  digitalWrite(intPinGate,HIGH);
  digitalWrite(intPinDoor,HIGH);  
}

//----------------------------------------------------------------------------------------------------------------SCANSIONE CHIAMATA/SMS----------------------------------------------------------------------------
int intCheckIncomingAction()
{
  int intResult = 0;
  boolean blnNumAllowed = false;
  char InComingNumtel[20]; //Contiene il numero del telefono chiamante o il mittente dell'sms
  
  if (gsmSMS.available())
  {
    gsmSMS.remoteNumber(InComingNumtel, 20);
    blnNumAllowed = blnCheckNumer(InComingNumtel);
     if (blnNumAllowed)
     {
       boolean blnFind = false;
       char chrSMSText;
       char strSMSText[255];
       int intIndex=0;
      
       while (chrSMSText = gsmSMS.read()) //devo compormi il messaggio, leggendo carattere per carattere
       {
         strSMSText[intIndex] = chrSMSText;
        intIndex = intIndex +1;
       }
      
       strlwr(strSMSText); // trasfromo la stringa in minuscolo
      
       if (strcmp(strSMSText,"cancelletto") == 0 || strcmp(strSMSText,"portina") == 0)
         intResult = intOpenSmallGate;
       else
       {
         if (strcmp(strSMSText,"cancello") == 0)
           intResult = intOpenGate;
         else
         {
           if (strcmp(strSMSText,"porta") == 0 || strcmp(strSMSText,"portone") == 0)
           intResult = intOpenDoor;
         }  
       }
        memset(strSMSText,0,sizeof(strSMSText)); //pulisco Array    
     }
     gsmSMS.flush(); //cancello l'sms
  }
  else
  {
    switch (gsmCall.getvoiceCallStatus())
    {
      case IDLE_CALL: // Nothing is happening  
        break;
        
      case RECEIVINGCALL: // Yes! Someone is calling us    
          gsmCall.retrieveCallingNumber(InComingNumtel, 20);  //Recupero il numero chiamante    
          blnNumAllowed = blnCheckNumer(InComingNumtel);
          if (blnNumAllowed)
            intResult = intOpenGate;            
          gsmCall.hangCall();  //Per rispondere alla chiamamta : gsmCall.answerCall()    
        break;
        
      case TALKING:  // In this case the call would be established  
        break;
    }
  }  
  
  delay(intDefaultGSMDelay);
  
  return intResult;
}


//-----------------------------------------------------------------------------------------AUTORIZZAZIONE UTENTE-----------------------------------------------------------------------------------
boolean blnCheckNumer(char* chNumber)
{
    boolean blnFind = false;
    for (int intIndex = 0; intIndex < sizeof(lstAllowedPhone)-1; intIndex++)
    {      
        if (strcmp(chNumber,lstAllowedPhone[intIndex]) == 0 || strcmp(chNumber,lstAllowedPhonePlusNumber[intIndex]) == 0)
        {
          blnFind = true;
          break;
        }        
    }
    
    return blnFind;    
}

note: if i enable the gsm debug it works correctly.  O_O'

this is the LOG:

00
AT%13%
0 9>AT%13%%13%%10%OK%13%%10%
AT+CGREG?%13%
9 40>AT+CGREG?%13%%13%%10%+CGREG: 0,2%13%%10%%13%%10%OK%13%%10%
AT+CGREG?%13%
40 71>AT+CGREG?%13%%13%%10%+CGREG: 0,2%13%%10%%13%%10%OK%13%%10%
AT+CGREG?%13%
71 102>AT+CGREG?%13%%13%%10%+CGREG: 0,2%13%%10%%13%%10%OK%13%%10%
AT+CGREG?%13%
102 5>AT+CGREG?%13%%13%%10%+CGREG: 0,1%13%%10%%13%%10%OK%13%%10%
AT+IFC=1,1%13%
5 22>AT+IFC=1,1%13%%13%%10%OK%13%%10%
AT+CMGF=1%13%
22 40>%19%%17%AT+CMGF=1%13%%13%%10%OK%13%%10%
AT+CLIP=1%13%
40 56>AT+CLIP=1%13%%13%%10%OK%13%%10%
ATE0%13%
56 67>ATE0%13%%13%%10%OK%13%%10%
AT+COLP=1%13%
67 73>%13%%10%OK%13%%10%
ATH%13%
73 79>%13%%10%OK%13%%10%
AT+CMGL="REC UNREAD",1%13%
79 85>%13%%10%OK%13%%10%
AT+CMGL="REC UNREAD",1%13%
85 91>%13%%10%OK%13%%10%
AT+CMGL="REC UNREAD",1%13%
91 97>%13%%10%OK%13%%10%
AT+CMGL="REC UNREAD",1%13%
97 103>%13%%10%OK%13%%10%
AT+CMGL="REC UNREAD",1%13%
103 109>%13%%10%OK%13%%10%
AT+CMGL="REC UNREAD",1%13%
109 4>%13%%10%OK%13%%10%%13%%10%+CMTI: "SM",1%13%%10%
AT+CMGL="REC UNREAD",1%13%
4 89>%13%%10%+CMGL: 1,"REC UNREAD","+393402631404","","2014/07/04 09:41:04+08"%13%%10%cancello%13%%10%%13%%10%OK%13%%10%
AT+CMGD=1%13%
89 95>%13%%10%OK%13%%10%
AT+CMGL="REC UNREAD",1%13%
95 101>%13%%10%OK%13%%10%
AT+CMGL="REC UNREAD",1%13%
101 107>%13%%10%OK%13%%10%
AT+CMGL="REC UNREAD",1%13%
107 113>%13%%10%OK%13%%10%


 
« Last Edit: July 04, 2014, 02:42:33 am by PierluigiRovere » Logged

Pages: [1]   Go Up
Jump to: