Advertisement
pippero

Untitled

Jan 24th, 2021
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1.  
  2. //SIM800L
  3. // tx pin 2
  4. // rx pin 3
  5.  
  6. //Relay pin 4
  7.  
  8. // Include the GSM library
  9. #include <GSM.h>
  10. GSM_SMS sms;
  11. boolean allarme = 1;
  12. boolean presenza = 0;
  13.  
  14. // PIN Number
  15. #define PINNUMBER ""
  16.  
  17. // initialize the library instance
  18. GSM gsmAccess;
  19. GSMVoiceCall vcs;
  20.  
  21. // Array to hold the number for the incoming call
  22. char numtel[20];
  23. int rel1 = 4;
  24.  
  25. void setup() {
  26. // initialize serial communications and wait for port to open:
  27.  
  28.  
  29. Serial.begin(9600);
  30. pinMode(10, INPUT_PULLUP);
  31. pinMode(13, OUTPUT);
  32. digitalWrite(13, LOW);
  33. while (!Serial) {
  34. ; // wait for serial port to connect. Needed for native USB port only
  35. }
  36.  
  37.  
  38. Serial.println("Receive Voice Call");
  39.  
  40. // connection state
  41. boolean notConnected = true;
  42.  
  43. // Start GSM shield
  44. // If your SIM has PIN, pass it as a parameter of begin() in quotes
  45. while (notConnected) {
  46. if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
  47. notConnected = false;
  48. } else {
  49. Serial.println("Not connected");
  50. delay(1000);
  51. }
  52. }
  53.  
  54. // This makes sure the modem correctly reports incoming events
  55. vcs.hangCall();
  56.  
  57. Serial.println("Waiting for a call");
  58. }
  59.  
  60. void loop() {
  61. if (allarme == 1) {
  62. digitalWrite(13, HIGH);
  63. }
  64. if (allarme == 0) {
  65. digitalWrite(13, LOW);
  66. }
  67.  
  68. if (digitalRead(10) == LOW) {
  69. presenza = 1;
  70. }
  71. else {
  72. presenza = 0;
  73. }
  74. if ( presenza ==1) {
  75. Serial.println("chiamo");
  76. Serial.println(millis()/1000);
  77. vcs.voiceCall("+390185xxxxxx");//qui il mio numero
  78. delay(10000);
  79. Serial.println("fine");
  80. Serial.println(millis()/1000);
  81. vcs.hangCall();
  82. }
  83. // Check the status of the voice call
  84. switch (vcs.getvoiceCallStatus()) {
  85. case IDLE_CALL: // Nothing is happening
  86.  
  87. break;
  88.  
  89. case RECEIVINGCALL: // Yes! Someone is calling us
  90.  
  91. Serial.println("RECEIVING CALL");
  92.  
  93. // Retrieve the calling number
  94. vcs.retrieveCallingNumber(numtel, 20);
  95.  
  96.  
  97. if ((strcmp(numtel, "+390185xxxxxx") == 0) || (strcmp(numtel, "+39338xxxxxx") == 0)) {
  98. Serial.println(allarme);
  99. allarme = !allarme;
  100. vcs.hangCall(); //serve per far cadere la chiamata
  101. }
  102.  
  103. else
  104. Serial.println(" => non riconosciuto!");
  105. vcs.hangCall();
  106. }
  107.  
  108. };
  109.  
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement