Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. #include <GSM.h>
  2.  
  3. // PIN Number
  4. #define PINNUMBER ""
  5.  
  6. // initialize the library instance
  7. GSM gsmAccess; // include a 'true' parameter for debug enabled
  8. GSMVoiceCall vcs;
  9.  
  10. char numtel[20]; // buffer for the incoming call
  11.  
  12. void setup()
  13. {
  14. // initialize serial communications
  15. Serial.begin(9600);
  16. Serial.println("Receive Voice Call");
  17.  
  18. // connection state
  19. boolean notConnected = true;
  20.  
  21. // Start GSM shield
  22. // If your SIM has PIN, pass it as a parameter of begin() in quotes
  23. while(notConnected)
  24. {
  25. if(gsmAccess.begin(PINNUMBER)==GSM_READY)
  26. notConnected = false;
  27. else
  28. {
  29. Serial.println("Not connected");
  30. delay(1000);
  31. }
  32. }
  33.  
  34. //Enable dtmf
  35. theGSM3ShieldV1ModemCore.genericCommand_rqc("AT+QTONEDET=1", true); // Send command
  36. delay(1000); // Wait for response
  37. bool resp;
  38. theGSM3ShieldV1ModemCore.genericParse_rsp(resp);
  39. if(resp){
  40. Serial.println("DTMF Enabled");
  41. }else{
  42. Serial.println("DTMF NOT Enabled");
  43. }
  44.  
  45.  
  46. // This makes sure the modem notifies correctly incoming events
  47. vcs.hangCall();
  48.  
  49. Serial.println("Waiting Call");
  50. }
  51.  
  52. void loop()
  53. {
  54. // Check the status of the voice call
  55. switch (vcs.getvoiceCallStatus())
  56. {
  57. case IDLE_CALL: // Nothing is happening
  58.  
  59. break;
  60.  
  61. case CALLING: // This should never happen, as we are not placing a call
  62.  
  63. Serial.println("CALLING");
  64. break;
  65.  
  66. case RECEIVINGCALL: // Yes! Someone is calling us
  67.  
  68. Serial.println("RECEIVING CALL");
  69.  
  70. // Retrieve the calling number
  71. vcs.retrieveCallingNumber(numtel, 20);
  72.  
  73. // Print the calling number
  74. Serial.print("Number:");
  75. Serial.println(numtel);
  76.  
  77. // Answer the call, establish the call
  78. vcs.answerCall();
  79. break;
  80.  
  81. case TALKING: // In this case the call would be established
  82.  
  83. Serial.println("TALKING. Enter line to interrupt.");
  84. const char* strSearch = "QTONEDET:";
  85. int len = strlen(strSearch);
  86. int sum=0;
  87. while(Serial.read()!='\n'){
  88. char c = theGSM3ShieldV1ModemCore.theBuffer().read();
  89. sum = (c==strSearch[sum]) ? sum+1 : 0;
  90. if(sum == len){
  91. sum=0;
  92. int n;
  93. n = atoi(theGSM3ShieldV1ModemCore.theBuffer().read());
  94. Serial.print("Tone found:");
  95. Serial.println(n);
  96. break;
  97. }
  98. delay(100);
  99. }
  100.  
  101. vcs.hangCall();
  102. Serial.println("HANG. Waiting Call.");
  103. break;
  104. }
  105. delay(1000);
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement