1. #include <Servo.h>
  2. #include "SIM900.h"
  3. #include <SoftwareSerial.h>
  4. //If not used, is better to exclude the HTTP library,
  5. //for RAM saving.
  6. //If your sketch reboots itself proprably you have finished,
  7. //your memory available.
  8. //#include "inetGSM.h"
  9.  
  10. //If you want to use the Arduino functions to manage SMS, uncomment the lines below.
  11. #include "sms.h"
  12. SMSGSM sms;
  13.  
  14.  
  15. //To change pins for Software Serial, use the two lines in GSM.cpp.
  16.  
  17. //GSM Shield for Arduino
  18. //www.open-electronics.org
  19. //this code is based on the example of Arduino Labs.
  20.  
  21. //Simple sketch to send and receive SMS.
  22.  char usr[]="@usr";        
  23.  char adm[]="@adm";
  24.  char del[]="@del";
  25.  char on[]="@on";
  26.  char off[]="@off";
  27.  
  28. int numdata;
  29. boolean started=false;
  30. char position;  
  31. char phone_number[20]; // array for the phone number string
  32. char sms_text[13];
  33. Servo s1;
  34.  
  35.  
  36. void setup()
  37. {
  38.   //Serial connection.
  39.  
  40.   Serial.begin(9600);
  41.   Serial.println("GSM Shield testing.");
  42.  
  43.   //Start configuration of shield with baudrate.
  44.   //For http uses is raccomanded to use 4800 or slower.
  45.   if (gsm.begin(2400)){
  46.     Serial.println("\nstatus=READY");
  47.     started=true;  
  48.   }
  49.   else Serial.println("\nstatus=IDLE");
  50.  
  51.   if(started){
  52.      }
  53.  
  54. };
  55.  
  56. void loop()
  57. {
  58.  
  59.   Serial.println("No new sms!");
  60.   delay(1000);
  61.   s1.attach(6);
  62.   s1.detach();
  63.   position = sms.IsSMSPresent(SMS_UNREAD);
  64.  if (position) {
  65.           // read new SMS
  66.      sms.GetSMS(position, phone_number, sms_text, 15);
  67.      Serial.println("SMS recieved");
  68.      Serial.println(sms_text);
  69.      
  70.                        /* if(has_command(sms_text,usr,sizeof(usr))&& has_number(sms_text,usr,sizeof(usr)))
  71.                 {
  72.                     Serial.println("Added user entry");
  73.                            
  74.                 }
  75.             if(has_command(sms_text,adm,sizeof(adm))&& has_number(sms_text,adm,sizeof(adm)))
  76.                 {
  77.                     Serial.println("Added admin entry");
  78.                            
  79.                 }
  80.                        
  81.             if(has_command(sms_text,del,sizeof(del))&& has_number(sms_text,del,sizeof(del)))
  82.                 {
  83.                     Serial.println("\nDeleted entry\n");
  84.                                    
  85.                 }*/
  86.             if(has_command(sms_text,on,sizeof(on)))
  87.                 {
  88.                     Serial.println("On");
  89.                                           s1.attach(6);
  90.                                          s1.write(118);
  91.                                          delay(1000);
  92.                                          s1.detach();
  93.                     //log who opened   
  94.                 }  
  95.                               if(has_command(sms_text,off,sizeof(off)))
  96.                 {
  97.  
  98.                     Serial.println("Off");
  99.                                            s1.attach(6);
  100.                                          s1.write(80);
  101.                                          delay(1000);
  102.                                          s1.detach();
  103.                     //log who opened   
  104.                 }
  105.  
  106.         }
  107. }
  108.  
  109. bool has_command(char command[], char type[], int com_size)
  110. {
  111.  
  112. for(int i=1;i<com_size-1;i++) //el I para determinar el tamano de los comandos
  113. {
  114.     if(type[i]!=command[i]) //si alguno no es igual que el comando se devuelve false
  115.         {
  116.         return false;
  117.         }
  118. }
  119. return true;
  120. }
  121.  
  122. bool has_number(char command[],char type[], int com_size)
  123. {
  124. for(int i=com_size+1;i<com_size+7;i++) //el I para determinar el tamano de los comandos
  125. {
  126.     if(!isdigit(command[i]))
  127.         {
  128.         return false;
  129.         }
  130. }
  131. return true;
  132. }