Il mio obiettivo è di far eseguire una get dopo aver ricevuto una chiamata telefonica.
Ho preso come spunto lo sketch seguente che funziona correttamente:
#include "SIM900.h"
#include <SoftwareSerial.h>
//We don't need the http functions. So we can disable the next line.
//#include "inetGSM.h"
#include "sms.h"
#include "call.h"
//To change pins for Software Serial, use the two lines in GSM.cpp.
//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs.
//Simple sketch to check if an incoming call is from an authorized
//number and in this case, send to this number an SMS with the value
//of a digital input.
//We have to create the classes for SMSs and calls.
CallGSM call;
SMSGSM sms;
char number[20];
byte stat=0;
int value=0;
int pin=1;
char value_str[5];
void setup()
{
pinMode(pin,INPUT);
//Serial connection.
Serial.begin(9600);
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()
{
//Chekcs status of call
stat=call.CallStatusWithAuth(number,0,0);
//If the incoming call is from an authorized number
if(stat==CALL_INCOM_VOICE_AUTH){
//Hang up the call.
call.HangUp();
delay(2000);
//Check the value of the input.
value=digitalRead(1);
//Convert the int to a string.
itoa(value,value_str,10);
//Send an SMS to the previous number with
//the value read previously.
sms.SendSMS(number,value_str);
}
delay(1000);
};
Ho modificato il codice in modo che invece di inviare un sms esegua la get
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "inetGSM.h"
//#include "sms.h"
#include "call.h"
//To change pins for Software Serial, use the two lines in GSM.cpp.
//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs.
//Simple sketch to start a connection as client.
InetGSM inet;
CallGSM call;
//SMSGSM sms;
char msg[50];
int numdata;
char inSerial[50];
int i=0;
boolean started=true;
int pin=1;
byte stat=0;
char number[20];
void setup()
{
pinMode(pin,INPUT);
//Serial connection.
Serial.begin(9600);
Serial.println("GSM Shield testing.");
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(4800)){
Serial.println("\nstatus=READY");
}
else Serial.println("\nstatus=IDLE");
};
void loop()
{
stat=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(stat==CALL_INCOM_VOICE_AUTH){
//Hang up the call.
call.HangUp();
delay(2000);
started=true;
if(started){
started=false;
// //GPRS attach, put in order APN, username and password.
// //If no needed auth let them blank.
if (inet.attachGPRS("wap.tim.it", "", ""))
Serial.println("status=ATTACHED");
else Serial.println("status=ERROR");
delay(1000);
//
// //Read IP address.
gsm.SimpleWriteln("AT+CIFSR");
delay(5000);
// //Read until serial buffer is empty.
gsm.WhileSimpleRead();
//
// //TCP Client GET, send a GET request to the server and
// //save the reply.
numdata=inet.httpGET("www.google.com", 80, "/", msg, 50);
// //Print the results.
Serial.println("\nNumber of data received:");
Serial.println(numdata);
Serial.println(msg);
}
}
delay(1000);
};
Purtroppo sul monitor seriale mi appaiono una serie di gggggg .
Se provo a commentare la parte che si occupa di ricevere la chiamata, la get viene eseguita, viceversa se commento la parte relativa alla
inet.attachGPRS e quindi della get , il codice che si occupa di attendere le chiamate viene eseguito.
Non riesco a trovare un modo per far convivere e funzionare le due attività insieme, come avviene invece per lo sketch attesa chiamate e invio sms.
Spero in un vostro aiuto