domenica 25 gennaio 2015

GSM Shield .Test

Dopo aver inserito la shield premere il pulsante Power Key.
Oltre al led pover si accende il led rosso Status led ed il led verde Net light.
Il led Net Ligh lampeggia a frequenza elevata quando ricerca la rete a frequenza bassa (un lampeggìo ogni 3 sec.) quando è agganciato alla rete.

Nel file GSM.cpp assicurarsi che :
#define _GSM_TXPIN_ 7
#define _GSM_RXPIN_ 8



      /* -----------------------------------------------------------------------------------
      Libreria--> GSMSHIELD---> GSM.CPP assicurarsi che i pin
      di trasmissione siano:
      #define _GSM_TXPIN_ 7
      #define _GSM_RXPIN_ 8
      
       Accende e spegne un LED a secondo dell'SMS inviato:
       ON  => Accende il LED
       OFF => Spegne il LED
       Altro => Messaggio di errore sul Serial Monitor
       ---------------------------------------------------------------------------------- */
      #include "SIM900.h"
      #include <SoftwareSerial.h> 
      #include "sms.h"            
      
      SMSGSM sms;
     
      int led = 13; // Il Pin 13 è quello connesso al LED
      int numdata;
      boolean started=false;
      char smsbuffer[160];
      char Mittente[20];
      
      void setup() 
           { Serial.begin(9600);
             Serial.println("ESEMPIO INVIO/RICEZIONE SMS");
             pinMode(led, OUTPUT);    
             digitalWrite(led, LOW);  
             if ( gsm.begin(2400) )
                { Serial.println("STATUS Modulo GSM = PRONTO");
                   started=true;   }
            else 
               Serial.println("STATUS Modulo GSM = INATTIVO"); }
  
           boolean SerialRead(char s[])
                   { int i=0;
                     if ( Serial.available() > 0)
                        { while ( Serial.available() > 0) 
                                { s[i]=Serial.read();
                                  delay(10);
                                  i++; } }
                                  
                     s[i]='\0';  
                     return (i!=0);}
     
      
      void loop()  {
        
        char inSerial[50];
        char position;
        if ( started)
           { position = sms.IsSMSPresent(SMS_ALL); 
          if ( position) 
             { sms.GetSMS(position, Mittente, smsbuffer, 160);
               Serial.print("Comando Ricevuto [tel. "+String(Mittente)+String("]: ") + String(smsbuffer));
               if (strcmp(smsbuffer,"ON")==0)
                  { digitalWrite(led, HIGH); 
                    Serial.println(" => Accendo il LED"); }
              
               else if (strcmp(smsbuffer,"OFF")==0)
                  { digitalWrite(led, LOW); 
                    Serial.println(" => Spengo il LED"); }
            
               else if (strcmp(smsbuffer,"STATUS")==0)
                   { if ( digitalRead(led)==HIGH)
                       { sms.SendSMS(Mittente, "STATUS: LED Acceso"); 
                         Serial.println(" => il LED e' Acceso");  }
                    else
                       { sms.SendSMS(Mittente, "STATUS: LED Spento"); 
                         Serial.println(" => il LED e' Spento"); }}
               else
                  Serial.println(" => non riconosciuto!");
                 sms.DeleteSMS(position);  }
           
        delay(1000); }
      }


NOTA: Ok, funziona.