bag in sketch accendi/spegni led con sms


ciao tutti,

ho realizzato uno sketch che mi permette di accendere e spegnere un led mandando un sms ("led on" per accenderlo e "led off" per spegnerlo).
sto utilizzando arduino mega 2560 con modulo gsm-gprs e modulo sim908.
questo è lo sketch:

code: [select]
//call , sms
#include "sim900.h"
#include <softwareserial.h>
#include "sms.h"
#include "call.h"

//#define ledpin1 11
const byte ledpin1=11;

callgsm call;
smsgsm sms;

char number[20];
char smsbuffer[160];
byte stato=0;
char url[100];

void setup() {
  // put setup code here, run once:
  serial.begin(9600);
  pinmode(ledpin1, output);
  serial.println("gsm shield testing.");
     //start configuration of shield baudrate.
     //for http uses raccomanded use 4800 or slower.
     if (gsm.begin(2400))
          serial.println("\nstatus=ready");
     else serial.println("\nstatus=idle");
}

void loop() {
  check_call_incoming();
  read_sms();
  delay(1000);

}



void check_call_incoming() {
 
  //chekcs status of call
     stato=call.callstatuswithauth(number,0,0);
     //if incoming call authorized number
     //saved on sim in positions range 1 3.
     if(stato==call_incom_voice_auth) {
          //hang call.
          call.pickup();
          delay(2000);
          //check value of input.
          digitalwrite(ledpin1,high);
          delay(5000);
          digitalwrite(ledpin1,low);
          //send sms previous number with
          //the value_str.
          //sms.sendsms(number,value_str);
     }
}


void read_sms(){

  //read if there messages on sim card , print them.
  char position_sms = sms.issmspresent(sms_unread);
        if (position_sms) {
          // read new sms
           sms.getsms(position_sms, number, smsbuffer, 160); 
           serial.println(number);
           serial.println(smsbuffer);
           if(strncmp(smsbuffer,"led on",6)==0){
             digitalwrite(ledpin1, high);
           }
           else if(strncmp(smsbuffer,"led off",7)==0){
             digitalwrite(ledpin1, low);
           }   
        }
}


dal monitor seriale vedo che arduino riceve correttamente tutti gli sms che invio, ma non sempre il led si accende o si spegne.

da cosa potrebbe dipendere?



Arduino Forum > International > Italiano > Software (Moderator: leo72) > bag in sketch accendi/spegni led con sms


arduino

Comments