Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //SIM800L
- // tx pin 2
- // rx pin 3
- unsigned long Tempo = 0;
- //int voiceCall(10000);
- // Include the GSM library
- #include <GSM.h>
- GSM_SMS sms;
- boolean allarme = 1;
- boolean presenza = 0;
- #define LED 13
- #define PULSANTE 10
- // PIN Number
- #define PINNUMBER //""
- int fase = 0;
- int all = 1;
- // initialize the library instance
- GSM gsmAccess;
- GSMVoiceCall vcs;
- // Array to hold the number for the incoming call
- char numtel[20];
- void setup() {
- // initialize serial communications and wait for port to open:
- Serial.begin(9600);
- pinMode(10, INPUT_PULLUP);
- pinMode(13, OUTPUT);
- digitalWrite(13, LOW);
- while (!Serial) {
- ; // wait for serial port to connect. Needed for native USB port only
- }
- Serial.println("connessione rete gsm");
- // connection state
- boolean notConnected = true;
- // Start GSM shield
- // If your SIM has PIN, pass it as a parameter of begin() in quotes
- while (notConnected) {
- if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
- notConnected = false;
- } else {
- Serial.println("Not connected");
- delay(1000);
- }
- }
- // This makes sure the modem correctly reports incoming events
- vcs.hangCall();
- Serial.println("attesa evento");
- }
- void loop() {
- switch (allarme) {
- case 0:
- digitalWrite(LED, LOW);
- break;
- case 1:
- digitalWrite(LED, HIGH);
- break;
- }
- if (digitalRead(10) == LOW) {
- presenza = 1;
- }
- else {
- presenza = 0;
- }
- if ( presenza == 1 && all == 1) {
- all = 0;
- fase = 1;
- }
- switch (fase) {
- case 1: {
- Serial.println(" 1 chiamo ");
- vcs.voiceCall("+39329xxxxxxxx", 5000);
- Tempo = millis();
- fase = 2;
- }
- break;
- case 2: {
- if (millis() - Tempo > 5500) {
- Serial.println(" 2 fine chiamata ");
- vcs.hangCall(); //serve per far cadere la chiamata
- fase = 3;
- Tempo = millis();
- }
- }
- break;
- case 3: {
- if (millis() - Tempo > 1500) {
- Serial.println(" 3 chiamo ");
- vcs.voiceCall("+39329xxxxxxxx", 5000);
- Tempo = millis();
- fase = 4;
- }
- }
- break;
- case 4: {
- if (millis() - Tempo > 7000) {
- Tempo = millis();
- Serial.println("4 fine chiamata ");
- vcs.hangCall(); //serve per far cadere la chiamata
- fase = 5;
- }
- }
- break;
- case 5: {
- if (millis() - Tempo > 1000) {
- all = 1;
- //Serial.println("fine fasi");
- }
- }
- break;
- }
- // Check the status of the voice call
- switch (vcs.getvoiceCallStatus()) {
- case IDLE_CALL: // Nothing is happening
- break;
- case RECEIVINGCALL: // Yes! Someone is calling us
- Serial.println("RECEIVING CALL");
- // Retrieve the calling number
- vcs.retrieveCallingNumber(numtel, 20);
- if ((strcmp(numtel, "+390185xxxxxx") == 0) || (strcmp(numtel, "+3933xxxxxxxx") == 0)) {
- Serial.println(allarme);
- allarme = !allarme;
- vcs.hangCall(); //serve per far cadere la chiamata
- }
- else
- Serial.println(" => non riconosciuto!");
- vcs.hangCall();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement