blob: 14dbc5ee1533c0f076b1d8206b7942b78f0e0ef0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
/*
Receive Voice Call
This sketch, for the Arduino GSM shield, receives voice calls,
displays the calling number, waits a few seconds then hangs up.
Circuit:
* GSM shield
* Voice circuit. Refer to to the GSM shield getting started guide
at http://arduino.cc/en/Guide/ArduinoGSMShield#toc11
* SIM card that can accept voice calls
With no voice circuit the call will connect, but will not send or receive sound
created Mar 2012
by Javier Zorzano
This example is in the public domain.
http://arduino.cc/en/Tutorial/GSMExamplesReceiveVoiceCall
*/
// Include the GSM library
#include <GSM.h>
// PIN Number
#define PINNUMBER ""
// initialize the library instance
GSM gsmAccess;
GSMVoiceCall vcs;
// Array to hold the number for the incoming call
char numtel[20];
void setup()
{
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("Receive Voice Call");
// connection state
boolean notConnected = true;
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while(notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
// This makes sure the modem correctly reports incoming events
vcs.hangCall();
Serial.println("Waiting for a call");
}
void loop()
{
// Check the status of the voice call
switch (vcs.getvoiceCallStatus())
{
case IDLE_CALL: // Nothing is happening
break;
case RECEIVINGCALL: // Yes! Someone is calling us
Serial.println("RECEIVING CALL");
// Retrieve the calling number
vcs.retrieveCallingNumber(numtel, 20);
// Print the calling number
Serial.print("Number:");
Serial.println(numtel);
// Answer the call, establish the call
vcs.answerCall();
break;
case TALKING: // In this case the call would be established
Serial.println("TALKING. Press enter to hang up.");
while(Serial.read()!='\n')
delay(100);
vcs.hangCall();
Serial.println("Hanging up and waiting for the next call.");
break;
}
delay(1000);
}
|