hi again,
I don't use any modem initialise commands, the shield automatically starts, initialises and registers to GSM network upon power on.
I have found out today that pin 7 is the reset pin for the GSM shield and this has got me further to a point...
}
void loop() {
delay (10000);
analogWrite(7, 0);
delay (2000);
analogWrite(7, 255);
}
The above code will reset the shield time and time again so this confirms that I should be able to use the same code in my main sketch to the same effect.
// libraries
#include <GSM.h>
#include <Arduino.h>
#include <avr/wdt.h>
#define PINNUMBER ""
// initialize the library instance
GSM gsmAccess(true); // include a 'true' parameter for debug enabled
GSMVoiceCall vcs;
// Set the Constants
const int buttonPin = 4; // the number of the PUSHBUTTON PIN
const int readyPin = 13; // the number of the OK LED PIN
const int failPin = 12; // the number of the FAIL LED PIN
const int callPin = 11; // the number of the CALL LED PIN
// Set the variables
int buttonState = 0; // variable for reading the pushbutton status
// Timeout Variables
unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 21600000; // reset every 6 hours once running
void reboot() {
analogWrite(7, 0);
delay (2000);
analogWrite(7, 255);
attemptplus();
}
void attemptplus() {
delay (10000);
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
{ loop();
}
else
{
reboot();
}
}
void setup() {
startMillis = millis();
// initialize the LED pins as an output
pinMode(readyPin, OUTPUT);
pinMode(failPin, OUTPUT);
pinMode(callPin, OUTPUT);
// initialize the pushbutton pin as an input
pinMode(buttonPin, INPUT);
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
{
digitalWrite(failPin, HIGH); //Fail LED
delay (10000);
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
loop();
if(gsmAccess.begin(PINNUMBER)!=GSM_READY)
reboot();
}}
void loop() {
buttonState = digitalRead(buttonPin);
digitalWrite(failPin, LOW);
digitalWrite(readyPin, HIGH);
if ((buttonState == HIGH)&(vcs.getvoiceCallStatus()!=TALKING))
{
digitalWrite(callPin, HIGH);
vcs.voiceCall("07432297183");
}
if (vcs.getvoiceCallStatus()==TALKING)
{
digitalWrite(callPin, HIGH);
}
else
{
digitalWrite(callPin, LOW);
}}
Hopefully you can see what I have done here but basically: -
I have built a function called "reboot" which replicates the code to reset the shield. and then calls "attemptplus"
I have also built a function called "attemptplus", this is very similar to setup in that it carries out the "if" statement to see if GSM is ready. If it is then the sketch will run "loop" else it will run "reboot" and thus the cycle remains until GSM is established and "loop" is entered.
Outcome of this is: -
If sim card is in, then sketch runs like a dream and enters loop once established etc.
if sim card is out then the gsm shield resets once only so if I don't establish gsm on 2nd attempt i'm stuck again.
Does this indicate that one of my "loops" or "else" isn't working?