You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The connectGSM() function can be modified to return a boolean type to determine whether GPRS functionality is available on setup. The return value will determine whether or not to switch to a WiFi connection.
The procedure can be improved by:
Setting additional flags:
SIM_available/usable: This will determine whether we can use the SIM even if GPRS is not available
GPRS_active: This can be set after running a test to ping a DNS
Steps to initiate the service
The obvious is to check for serial communication with the GSM chip. If improperly configured set gsm_capable flag to false
Check if SIM is available. There are a few ways to do this. e.g AT+CCID
Check if PIN is set/and or attempt to set pin:
Check whether the module is registered to a network. At this point, the SIM_available flag can be set.
Enable GPRS
Run a connection test and set the GPRS_active flag
Audit the amount of time it takes to connect to a network. A warmup time delay would be suitable during the initialization process.
*** Suggestions ***
Rename function to initGSM(). This function can be called when restarting the GSM either via hardware or software serial.
/**** //ToDo: 1. Change return type to boolean 2. Set flag to check if SIM is inserted/usable //? change function name to initGSM() maybe to set different flags. GSM restart can call this function; ***/voidconnectGSM()
{
int retry_count = 0;
fonaSerial->begin(4800);
if (!fona.begin(*fonaSerial))
{
debug_outln(F("Couldn't find FONA"), DEBUG_MIN_INFO);
debug_outln(F("Switching to Wifi"), DEBUG_MIN_INFO);
gsm_capable = 0;
connectWifi(); // ToDo: Return false instead
}
else
{
debug_outln(F("FONA is OK"), DEBUG_MIN_INFO); //// ToDO: Check if SIM is installed. Run CCIDunlock_pin(); // ToDO check if PIN is set. If not return false and set SIM usable and GPRS capable flags to falsechar imei[16] = {0}; // MUST use a 16 character buffer for IMEI!uint8_t imeiLen = fona.getIMEI(imei);
if (imeiLen > 0)
{
debug_outln(F("Module IMEI: "), DEBUG_MIN_INFO);
debug_out(String(imei), DEBUG_MIN_INFO);
}
fona.setGPRSNetworkSettings(F("internet"), F(""), F(""));
while ((fona.getNetworkStatus() != GSM_CONNECTED) && (retry_count < 40))
{
Serial.println("Not registered on network");
delay(5000); // ?: Takes 2.5mins until until retry_count=30. It will take 5sec longer every other time and GSM is always restarted!
retry_count++;
if (retry_count > 30) // ?: Review this. Seems to be increasing the connect time. Maybe try 3 times
{
delay(5000);
restart_GSM();
}
flushSerial();
}
if (fona.getNetworkStatus() != GSM_CONNECTED) // ToDo: Return false and enable wifi connect somewhere else
{
String fss(cfg::fs_ssid);
display_debug(fss.substring(0, 16), fss.substring(16));
wifiConfig();
if (fona.getNetworkStatus() != GSM_CONNECTED)
{
retry_count = 0;
while ((fona.getNetworkStatus() != GSM_CONNECTED) && (retry_count < 20))
{
delay(500);
debug_outln(".", DEBUG_MIN_INFO);
retry_count++;
}
debug_outln("", DEBUG_MIN_INFO);
}
}
else
{
enableGPRS(); // ToDO: Expect a boolean value from this and set GPRS flag
Serial.println("GPRS ENABLED");
}
}
}
The text was updated successfully, but these errors were encountered:
The
connectGSM()
function can be modified to return a boolean type to determine whether GPRS functionality is available on setup. The return value will determine whether or not to switch to a WiFi connection.The procedure can be improved by:
AT+CCID
*** Suggestions ***
Rename function to initGSM(). This function can be called when restarting the GSM either via hardware or software serial.
The text was updated successfully, but these errors were encountered: