[175] | 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://www.arduino.org/products/shields/5-arduino-shields/arduino-gsm-shield-2
|
---|
| 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 | http://arduino.cc/en/Tutorial/GSMExamplesReceiveVoiceCall
|
---|
| 23 |
|
---|
| 24 | */
|
---|
| 25 |
|
---|
| 26 | // Include the GSM library
|
---|
| 27 | #include <GSM.h>
|
---|
| 28 |
|
---|
| 29 | // PIN Number
|
---|
| 30 | #define PINNUMBER ""
|
---|
| 31 |
|
---|
| 32 | // initialize the library instance
|
---|
| 33 | GSM gsmAccess;
|
---|
| 34 | GSMVoiceCall vcs;
|
---|
| 35 |
|
---|
| 36 | // Array to hold the number for the incoming call
|
---|
| 37 | char numtel[20];
|
---|
| 38 |
|
---|
| 39 | void setup()
|
---|
| 40 | {
|
---|
| 41 | // initialize serial communications and wait for port to open:
|
---|
| 42 | SerialUSB.begin(9600);
|
---|
| 43 | while (!SerialUSB) {
|
---|
| 44 | ; // wait for serial port to connect. Needed for Leonardo only
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | SerialUSB.println("Receive Voice Call");
|
---|
| 48 |
|
---|
| 49 | // connection state
|
---|
| 50 | boolean notConnected = true;
|
---|
| 51 |
|
---|
| 52 | // Start GSM shield
|
---|
| 53 | // If your SIM has PIN, pass it as a parameter of begin() in quotes
|
---|
| 54 | while (notConnected)
|
---|
| 55 | {
|
---|
| 56 | if (gsmAccess.begin(PINNUMBER) == GSM_READY)
|
---|
| 57 | notConnected = false;
|
---|
| 58 | else
|
---|
| 59 | {
|
---|
| 60 | SerialUSB.println("Not connected");
|
---|
| 61 | delay(1000);
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | // This makes sure the modem correctly reports incoming events
|
---|
| 66 | vcs.hangCall();
|
---|
| 67 |
|
---|
| 68 | SerialUSB.println("Waiting for a call");
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | void loop()
|
---|
| 72 | {
|
---|
| 73 | // Check the status of the voice call
|
---|
| 74 | switch (vcs.getvoiceCallStatus())
|
---|
| 75 | {
|
---|
| 76 | case IDLE_CALL: // Nothing is happening
|
---|
| 77 |
|
---|
| 78 | break;
|
---|
| 79 |
|
---|
| 80 | case RECEIVINGCALL: // Yes! Someone is calling us
|
---|
| 81 |
|
---|
| 82 | SerialUSB.println("RECEIVING CALL");
|
---|
| 83 |
|
---|
| 84 | // Retrieve the calling number
|
---|
| 85 | vcs.retrieveCallingNumber(numtel, 20);
|
---|
| 86 |
|
---|
| 87 | // Print the calling number
|
---|
| 88 | SerialUSB.print("Number:");
|
---|
| 89 | SerialUSB.println(numtel);
|
---|
| 90 |
|
---|
| 91 | // Answer the call, establish the call
|
---|
| 92 | vcs.answerCall();
|
---|
| 93 | break;
|
---|
| 94 |
|
---|
| 95 | case TALKING: // In this case the call would be established
|
---|
| 96 |
|
---|
| 97 | SerialUSB.println("TALKING. Press enter to hang up.");
|
---|
| 98 | while (SerialUSB.read() != '\n')
|
---|
| 99 | delay(100);
|
---|
| 100 | vcs.hangCall();
|
---|
| 101 | SerialUSB.println("Hanging up and waiting for the next call.");
|
---|
| 102 | break;
|
---|
| 103 | }
|
---|
| 104 | delay(1000);
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 |
|
---|