1 | /*
|
---|
2 | Receive Voice Call
|
---|
3 |
|
---|
4 | This sketch, for the Arduino GSM shield, receives voice calls,
|
---|
5 | displays the calling number, waits a few seconds then hangs up.
|
---|
6 |
|
---|
7 | Circuit:
|
---|
8 | * GSM shield
|
---|
9 | * Voice circuit. Refer to to the GSM shield getting started guide
|
---|
10 | at http://arduino.cc/en/Guide/ArduinoGSMShield#toc11
|
---|
11 | * SIM card that can accept voice calls
|
---|
12 |
|
---|
13 | ATTENTION: to work correctly with M0/M0 pro you have to connect pin 2 to pin 4 of the shield
|
---|
14 |
|
---|
15 | With no voice circuit the call will connect, but will not send or receive sound
|
---|
16 |
|
---|
17 | created Mar 2012
|
---|
18 | by Javier Zorzano
|
---|
19 |
|
---|
20 | This example is in the public domain.
|
---|
21 |
|
---|
22 |
|
---|
23 | Added Arduino GSM Shield 2 features
|
---|
24 | modified Feb 2016
|
---|
25 | by Arduino.org team (http://arduino.org)
|
---|
26 |
|
---|
27 | */
|
---|
28 |
|
---|
29 | // Include the GSM library
|
---|
30 | #include <GSM.h>
|
---|
31 |
|
---|
32 | // PIN Number
|
---|
33 | #define PINNUMBER ""
|
---|
34 |
|
---|
35 | // initialize the library instance
|
---|
36 | GSM gsmAccess;
|
---|
37 | GSM2 gsmAccessV2;
|
---|
38 | GSMVoiceCall vcs;
|
---|
39 |
|
---|
40 | #define number_len 20 // define incoming call number lenght
|
---|
41 |
|
---|
42 | // Array to hold the number for the incoming call
|
---|
43 | char number[number_len];
|
---|
44 |
|
---|
45 | void setup()
|
---|
46 | {
|
---|
47 | // initialize serial communications and wait for port to open:
|
---|
48 | SerialUSB.begin(9600);
|
---|
49 | while (!SerialUSB) {
|
---|
50 | ; // wait for serial port to connect. Needed for Leonardo only
|
---|
51 | }
|
---|
52 |
|
---|
53 | SerialUSB.println("Receive Voice Call");
|
---|
54 |
|
---|
55 | // connection state
|
---|
56 | boolean notConnected = true;
|
---|
57 |
|
---|
58 | // Start GSM shield
|
---|
59 | // If your SIM has PIN, pass it as a parameter of begin() in quotes
|
---|
60 | while (notConnected)
|
---|
61 | {
|
---|
62 | if (gsmAccess.begin(PINNUMBER) == GSM_READY)
|
---|
63 | notConnected = false;
|
---|
64 | else
|
---|
65 | {
|
---|
66 | SerialUSB.println("Not connected");
|
---|
67 | delay(1000);
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | // This makes sure the modem correctly reports incoming events
|
---|
72 | vcs.hangCall();
|
---|
73 | gsmAccessV2.muteControl(0); //not allowed by the module
|
---|
74 | gsmAccessV2.CommandEcho(1); // set echo
|
---|
75 | gsmAccessV2.speakerMode(1); //set speaker mode
|
---|
76 | gsmAccessV2.speakerLoudness(3); //set speaker loudness
|
---|
77 | gsmAccessV2.swapAudioChannel(1); //set audio channel
|
---|
78 | gsmAccessV2.microphoneGainLevel(1,13); //set microphone gain level
|
---|
79 | gsmAccessV2.ringerSoundLevel(20); //set ring sound level
|
---|
80 | gsmAccessV2.alertSoundMode(0); //set alert sound mode (sound)
|
---|
81 | gsmAccessV2.loudSpeakerVolumeLevel(20); //set loudspeaker volume level
|
---|
82 |
|
---|
83 | SerialUSB.println("Waiting for a call");
|
---|
84 | }
|
---|
85 |
|
---|
86 | void loop()
|
---|
87 | {
|
---|
88 | // Check the status of the voice call
|
---|
89 | switch (vcs.getvoiceCallStatus())
|
---|
90 | {
|
---|
91 | case IDLE_CALL: // Nothing is happening
|
---|
92 |
|
---|
93 | break;
|
---|
94 |
|
---|
95 | case RECEIVINGCALL: // Yes! Someone is calling us
|
---|
96 |
|
---|
97 | SerialUSB.println("RECEIVING CALL");
|
---|
98 |
|
---|
99 |
|
---|
100 | // Retrieve the calling number
|
---|
101 | vcs.retrieveCallingNumber(number, number_len);
|
---|
102 |
|
---|
103 | // Print the calling number
|
---|
104 | SerialUSB.print("Number:");
|
---|
105 | SerialUSB.println(number);
|
---|
106 | SerialUSB.println("Press a to answer");
|
---|
107 | while(SerialUSB.read() !='a');
|
---|
108 | // Answer the call, establish the call
|
---|
109 | vcs.answerCall();
|
---|
110 | break;
|
---|
111 |
|
---|
112 | case TALKING: // In this case the call would be established
|
---|
113 |
|
---|
114 | SerialUSB.println("TALKING. Press h to hang up.");
|
---|
115 | while (SerialUSB.read() != 'h')
|
---|
116 | delay(100);
|
---|
117 | vcs.hangCall();
|
---|
118 | SerialUSB.println("Hanging up and waiting for the next call.");
|
---|
119 | break;
|
---|
120 | }
|
---|
121 | delay(1000);
|
---|
122 | }
|
---|
123 |
|
---|
124 |
|
---|