gsm connesso creare variabile

buon di a tutti, ho fatto questo semplice antifurto che viene attivato mediante un squillo, e se nel caso il pin in ingresso va alto chiama 2 numeri.
e qui funziona.
avrei bisogno di capire come posso creare una variabile che mi indica se in gsm e' connesso in rete ,
e in base a questa variabile faccio delle azioni, cosi divise;
che nel caso affermativo parte con le chiamate , altrimenti mi va in reset la scheda con la sim .
vi ringrazio per qualche informazioni in merito , buona giornata

//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 daniele");
        vcs.voiceCall("+393294156602", 5000);
        Tempo = millis();
        fase = 2;
      }
      break;
    case 2: {
        if (millis() - Tempo > 5500) {
          Serial.println(" 2 fine chiamata daniele");
          vcs.hangCall(); //serve per far cadere la chiamata
          fase = 3;
          Tempo = millis();
        }
      }
      break;

    case 3: {
        if (millis() - Tempo  > 1500) {
          Serial.println(" 3 chiamo olindo");
          vcs.voiceCall("+393294156602", 5000);
          Tempo = millis();
          fase = 4;
        }
      }
      break;
    case 4: {
        if (millis() - Tempo  > 7000) {
          Tempo = millis();
          Serial.println("4 fine chiamata olindo");
          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, "+390185358719") == 0) || (strcmp(numtel, "+393381231212") == 0)) {
        Serial.println(allarme);
        allarme = !allarme;
        vcs.hangCall(); //serve per far cadere la chiamata
      }

      else
        Serial.println(" => non riconosciuto!");
      vcs.hangCall();
  }

}

forse ho trovato qualcosa

if (gsmAccess.getStatus() == 3){
connessione==1;
}
else {
connessione==0;
}

e' corretto??

mi rispondo da solo....questo non va bene....

attenzione che come hai scritto "connessione==x" stai facendo confronto e non assegnazione....magari è per quello.

si e' vero , e' anche quello ,gsmAccess.getStatus() una volta fatto il setup, resta sempre a 3 anche se levo la scheda

nella libreria c'è un:

/** Check network access status
@return 1 if Alive, 0 if down
*/
int isAccessAlive();

ho fatto un po di prove ed usando questo sketch

/*

 GSM Scan Networks

 This example prints out the IMEI number of the modem,
 then checks to see if it's connected to a carrier. If so,
 it prints the phone number associated with the card.
 Then it scans for nearby networks and prints out their signal strengths.

 Circuit:
 * GSM shield
 * SIM card

 Created 8 Mar 2012
 by Tom Igoe, implemented by Javier Carazo
 Modified 4 Feb 2013
 by Scott Fitzgerald

 http://www.arduino.cc/en/Tutorial/GSMToolsGsmScanNetworks

 This example code is part of the public domain
 */

// libraries
#include <GSM.h>

// PIN Number
#define PINNUMBER ""

// initialize the library instance
GSM gsmAccess;     // include a 'true' parameter to enable debugging
GSMScanner scannerNetworks;
GSMModem modemTest;

// Save data variables
String IMEI = "";

// serial monitor result messages
String errortext = "ERROR";

void setup() {
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.println("GSM networks scanner");
  scannerNetworks.begin();

  // 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);
    }
  }

  // get modem parameters
  // IMEI, modem unique identifier
  Serial.print("Modem IMEI: ");
  IMEI = modemTest.getIMEI();
  IMEI.replace("\n", "");
  if (IMEI != NULL) {
    Serial.println(IMEI);
  }
}

void loop() {
  // scan for existing networks, displays a list of networks
  Serial.println("Scanning available networks. May take some seconds.");
  Serial.println(scannerNetworks.readNetworks());

  // currently connected carrier
  Serial.print("Current carrier: ");
  Serial.println(scannerNetworks.getCurrentCarrier());

  // returns strength and ber
  // signal strength in 0-31 scale. 31 means power > 51dBm
  // BER is the Bit Error Rate. 0-7 scale. 99=not detectable
  Serial.print("Signal Strength: ");
  Serial.print(scannerNetworks.getSignalStrength());
  Serial.println(" [0-31]");

}

che e' quello negli esempi ,sulla seriale mi da cosi

18:45:01.224 -> Modem IMEI: 0
18:45:03.244 -> Scanning available networks. May take some seconds.
18:45:23.321 -> 
18:45:23.321 -> Current carrier: 
18:45:25.314 -> Signal Strength:  [0-31]
18:45:27.369 -> Scanning available networks. May take some seconds.
18:45:47.448 -> > +39018xxxxxxx
18:45:47.448 ->

io numero me lo legge da chui chiamo la sim , ma degli altri dati mi da tutto 0 , il modulo funziona perche suona se chiamo ed il primo listato funziona, il problema dove e'?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.