TinyGSM icon indicating copy to clipboard operation
TinyGSM copied to clipboard

Waiting for Initialization complete before doing anything with SIM800 module

Open krupis opened this issue 3 years ago • 2 comments

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?

krupis avatar Jul 22 '21 06:07 krupis

Hello,

I think that you forgot to call init().

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

adrianca88 avatar Oct 20 '21 22:10 adrianca88

Has this issue been resolved?

SRGDamia1 avatar Nov 24 '21 16:11 SRGDamia1