Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SIM800] DateTime AutoSync doesn't work properly in restart() method #289

Open
Warlib1975 opened this issue May 26, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@Warlib1975
Copy link

commented May 26, 2019

Hardware: SIM800L

Scenario, steps to reproduce

  • Execute restart() method of TimyGSM lib.
  • Execute the command "AT+CCLK?".
  • Got the default DateTime "04/01/01,00:00:40+12" instead of current one.

Expected result

After reset() the modem I supposed to get current DateTime.

Actual result

AT+CCLK?
+CCLK: "04/01/01,00:00:40+12"
OK

Check either GSM modem in auto sync mode
AT+CLTS?
+CLTS: 0
OK

Solution

The code in the TinyGSM lib is:

bool restart() {
    ...
    //Enable Local Time Stamp for getting network time
    // TODO: Find a better place for this
    sendAT(GF("+CLTS=1"));
    if (waitResponse(10000L) != 1) {
      return false;
    }
    sendAT(GF("&W"));
    waitResponse();
    sendAT(GF("+CFUN=0"));
    if (waitResponse(10000L) != 1) {
      return false;
    }
    sendAT(GF("+CFUN=1,1"));
    if (waitResponse(10000L) != 1) {
      return false;
    }
    ...
  }

I wrote an additional method SetAutoTimeSync() which I execute after the restart() and it works ok.

void SetAutoTimeSync()
{
  Serial.println("Enable GSM RTC network time sync.");
  sendAT(GF("+CLTS=1"));
  if (waitResponse(10000L) != 1) 
  {
      Serial.println("AT command \"AT+CLTS=1\" executing fault.");;
  }
  
  sendAT(GF("&W"));
  waitResponse();

  sendAT(GF("+CFUN=0"));
  if (waitResponse(10000L) != 1) 
  {
      Serial.println("AT command \"AT+CFUN=0\" executing fault.");;
  }
  
  //delay(3000);
  sendAT(GF("+CFUN=1"));
  //if (modemGSM.waitResponse(10000L) != 1) 
  if (waitResponse(10000L, GF(GSM_NL "DST:")) != 1)
  {
    Serial.println("AT command \"AT+CFUN=1\" executing fault.");;
  }

  Serial.println("DateTime: "+ GetDateTime());
}

String GetDateTime()
{
  sendAT(GF("+CCLK?"));
  if (waitResponse(10000L, GF(GSM_NL "+CCLK:")))
  {
      String body = stream.readStringUntil('\n');
      return body;
  }
  else
  {
    Serial.println("AT command \"+CCLK?\" executing fault.");
  } 
  return "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.