vshymanskyy / TinyGSM

A small Arduino library for GSM modules, that just works
GNU Lesser General Public License v3.0
1.91k stars 709 forks source link

Waiting for Initialization complete before doing anything with SIM800 module #568

Open krupis opened 2 years ago

krupis commented 2 years ago

Hello. I would like to know what is the best way to wait for modem to fully initialise before trying to use it? At the moment, my code looks as following:

StreamDebugger debugger(SerialAT, Serial);
TinyGsm modem(debugger);
TinyGsmClient client(modem);

void setup()
{
    Serial.begin(115200);
    SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);

#ifdef MODEM_RST
    // Keep reset high
    pinMode(MODEM_RST, OUTPUT);
    digitalWrite(MODEM_RST, HIGH);
#endif

    pinMode(MODEM_PWRKEY, OUTPUT);
    pinMode(MODEM_POWER_ON, OUTPUT);

    // Turn on the Modem power first
    digitalWrite(MODEM_POWER_ON, HIGH);

    // Pull down PWRKEY for more than 1 second according to manual requirements
    digitalWrite(MODEM_PWRKEY, HIGH);
    delay(100);
    digitalWrite(MODEM_PWRKEY, LOW);
    delay(1000);
    digitalWrite(MODEM_PWRKEY, HIGH);

    // Initialize the indicator as an output
    pinMode(LED_GPIO, OUTPUT);
    digitalWrite(LED_GPIO, LED_OFF);

//The following functions will not work because the modem is not fully initialised and cannot respond to the AT commands
    String modemInfo = modem.getModemInfo();
    Serial.print("Modem: ");
    Serial.println(modemInfo);

check_signal_strength();
update_serial();
modem.sendSMS(my_phone_number,"hello from esp");

}

void update_serial(){
    while(Serial.available())
    {
        SerialAT.write(Serial.read());
        Serial.println("receiving");
    }
    while(SerialAT.available())
    {
        Serial.write(SerialAT.read());
        Serial.println("sending");
    }
}

void check_signal_strength()
{
    SerialAT.println("AT+CSQ");
    Serial.println("checing signal strenghth");
}

If I add 6 seconds delay after initialization, then it works, but that does not seem like the best way to do that. Is there any better way to ensure that module properly started before sending AT commands? Is there a function available to check that?

adrianca88 commented 2 years ago

Hello,

I think that you forgot to call init().

I use the testAT() method to check if it's alive

SRGDamia1 commented 2 years ago

Has this issue been resolved?