Ciao a 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:
//call and 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 your setup code here, to run once:
Serial.begin(9600);
pinMode(ledPin1, OUTPUT);
Serial.println("GSM Shield testing.");
//Start configuration of shield with baudrate.
//For http uses is raccomanded to 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 the incoming call is from an authorized number
//saved on SIM in the positions range from 1 to 3.
if(stato==CALL_INCOM_VOICE_AUTH) {
//Hang up the call.
call.PickUp();
delay(2000);
//Check the value of the input.
digitalWrite(ledPin1,HIGH);
delay(5000);
digitalWrite(ledPin1,LOW);
//Send an SMS to the previous number with
//the value_str.
//sms.SendSMS(number,value_str);
}
}
void read_sms(){
//Read if there are messages on SIM card and 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?