Advertisement
pippero

Untitled

Jan 27th, 2021
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1.  
  2. //SIM800L
  3. // tx pin 2
  4. // rx pin 3
  5.  
  6. unsigned long Tempo = 0;
  7. //int voiceCall(10000);
  8. // Include the GSM library
  9. #include <GSM.h>
  10. GSM_SMS sms;
  11. boolean allarme = 1;
  12. boolean presenza = 0;
  13. #define LED 13
  14. #define PULSANTE 10
  15. // PIN Number
  16. #define PINNUMBER //""
  17. int fase = 0;
  18. int all = 1;
  19. // initialize the library instance
  20. GSM gsmAccess;
  21. GSMVoiceCall vcs;
  22.  
  23. // Array to hold the number for the incoming call
  24. char numtel[20];
  25.  
  26.  
  27. void setup() {
  28. // initialize serial communications and wait for port to open:
  29.  
  30.  
  31. Serial.begin(9600);
  32. pinMode(10, INPUT_PULLUP);
  33. pinMode(13, OUTPUT);
  34. digitalWrite(13, LOW);
  35. while (!Serial) {
  36. ; // wait for serial port to connect. Needed for native USB port only
  37. }
  38.  
  39.  
  40. Serial.println("connessione rete gsm");
  41.  
  42. // connection state
  43. boolean notConnected = true;
  44.  
  45. // Start GSM shield
  46. // If your SIM has PIN, pass it as a parameter of begin() in quotes
  47. while (notConnected) {
  48. if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
  49. notConnected = false;
  50. } else {
  51. Serial.println("Not connected");
  52. delay(1000);
  53. }
  54. }
  55.  
  56. // This makes sure the modem correctly reports incoming events
  57. vcs.hangCall();
  58.  
  59. Serial.println("attesa evento");
  60. }
  61.  
  62. void loop() {
  63. switch (allarme) {
  64.  
  65. case 0:
  66. digitalWrite(LED, LOW);
  67. break;
  68.  
  69. case 1:
  70. digitalWrite(LED, HIGH);
  71. break;
  72. }
  73. if (digitalRead(10) == LOW) {
  74. presenza = 1;
  75. }
  76. else {
  77. presenza = 0;
  78. }
  79.  
  80. if ( presenza == 1 && all == 1) {
  81. all = 0;
  82. fase = 1;
  83. }
  84.  
  85. switch (fase) {
  86.  
  87. case 1: {
  88. Serial.println(" 1 chiamo ");
  89. vcs.voiceCall("+39329xxxxxxxx", 5000);
  90. Tempo = millis();
  91. fase = 2;
  92. }
  93. break;
  94. case 2: {
  95. if (millis() - Tempo > 5500) {
  96. Serial.println(" 2 fine chiamata ");
  97. vcs.hangCall(); //serve per far cadere la chiamata
  98. fase = 3;
  99. Tempo = millis();
  100. }
  101. }
  102. break;
  103.  
  104. case 3: {
  105. if (millis() - Tempo > 1500) {
  106. Serial.println(" 3 chiamo ");
  107. vcs.voiceCall("+39329xxxxxxxx", 5000);
  108. Tempo = millis();
  109. fase = 4;
  110. }
  111. }
  112. break;
  113. case 4: {
  114. if (millis() - Tempo > 7000) {
  115. Tempo = millis();
  116. Serial.println("4 fine chiamata ");
  117. vcs.hangCall(); //serve per far cadere la chiamata
  118. fase = 5;
  119. }
  120. }
  121. break;
  122. case 5: {
  123. if (millis() - Tempo > 1000) {
  124. all = 1;
  125. //Serial.println("fine fasi");
  126. }
  127. }
  128. break;
  129. }
  130. // Check the status of the voice call
  131. switch (vcs.getvoiceCallStatus()) {
  132. case IDLE_CALL: // Nothing is happening
  133.  
  134. break;
  135.  
  136. case RECEIVINGCALL: // Yes! Someone is calling us
  137.  
  138. Serial.println("RECEIVING CALL");
  139.  
  140. // Retrieve the calling number
  141. vcs.retrieveCallingNumber(numtel, 20);
  142.  
  143.  
  144. if ((strcmp(numtel, "+390185xxxxxx") == 0) || (strcmp(numtel, "+3933xxxxxxxx") == 0)) {
  145. Serial.println(allarme);
  146. allarme = !allarme;
  147. vcs.hangCall(); //serve per far cadere la chiamata
  148. }
  149.  
  150. else
  151. Serial.println(" => non riconosciuto!");
  152. vcs.hangCall();
  153. }
  154.  
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement