Description
Asynchronous operation of the GSM class methods allows to run the task of connecting to the GSM infrastructure concurrently to the main job of your application. It means that your application does not block while actively waiting for the modem to answer etc. In order to do so, the application would trigger the begin() function in asynchronous mode so that it returns straight away. Now the application has to call the ready() function regularly that gives the GSM class processing time to handle the connection-process in the background. Its return value let the user application know if the task is finished and if it was successful or not. See the code below as an example how a asynchronous gsm.begin() process could be implemented. The status() method returns the current operation step the gsm-object is working on (e.g. ERROR, IDLE, CONNECTING, GSM_READY etc.)
Syntax
gsm.begin(“PIN”, true, false);
gsm.ready();
gsm.status();
Parameters
“PIN” stands for the character array holding the SIM PIN number e.g. “1234”
true – the 2nd parameter decides to restart the modem (as described here)
false – the 3rd parameter starts the begin function in asynchronous mode (as described here)
see https://www.arduino.cc/en/Reference/MKRGSMBegin
Returns
begin() returns:
– ERROR
– in case of problems with the modem communication.
– IDLE
– OK.
ready() returns:
0 – the process is still running
1– OK. Process was successfully finished
2– ERROR. Process could not be completed because an error occurred.
status() returns:IDLE
– modem process is idleERROR
– an error occurred during the latest modem process (e.g. begin() operation failed)GSM_READY
– modem was successfully started and is registered in the GSM networkCONNECTING
– modem is currently trying to register with the GSM networkGSM_OFF
-modem is off.
Example Code
This example shows how to start the GSM connection process, attaching to the GSM infrastructure in an asynchronous way.
#include <DICENB.h>
GSM gsm;
void setup()
{
gsm.begin("", true, false); // begin() in async mode
// ready() does the modem begin() task in the background
// so call it regularly until it returns != 0.
while(gsm.ready() == 0) {
// do other app things (async)
};
if(gsm.ready() == 2)
Serial.println("Error");
else
Serial.println("GSM initialised");
}
void loop()
{
// once connected do something interesting
}
Notes and Warnings
—