vshymanskyy / TinyGSM

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

getNetworkTime() crashes if returned string ends with " #735

Open cnf opened 1 year ago

cnf commented 1 year ago

[x] I have read the Troubleshooting section of the ReadMe

What type of issues is this?

[ ] Request to support a new module

[ ] Bug or problem compiling the library [x] Bug or issue with library functionality (ie, sending data over TCP/IP) [ ] Question or request for help

What are you working with?

Modem Name: SIMCOM SIM7000G Modem Info: SIM7000G R1529 Main processor board: ESP32 TinyGSM version: 0.11.6 Code:

void loop() {
  SerialMon.println("\n\n+++ LOOP ++++++++++++++++++++++++++++++++++++++++++++++++++");

  SerialMon.println("getGSMDateTime");
  String time = modem.getGSMDateTime(DATE_FULL);
  SerialMon.println(time);

  SerialMon.println("getNetworkTime");
  int year, month, day, hour, minute, second;
  float timezone;
  if (modem.getNetworkTime(&year, &month, &day, &hour, &minute, &second, &timezone)) {
    SerialMon.printf("Y: %s M: %s D: %s\n", year, month, day);
    SerialMon.printf("h: %s m: %s s: %s\n", hour, minute, second);
  }
  delay(20000);
}

Scenario, steps to reproduce

When I send AT+CCLK? with SerialAT.println("AT+CCLK?"), or modem.getGSMDateTime() or modem.getNetworkTime(), my modem responds with +CCLK: "23/06/27,13:52:03+03"

Note the \"

From what I can see, https://github.com/vshymanskyy/TinyGSM/blob/master/src/TinyGsmTime.tpp#L87 is not expecting the " at the end, and crashes (full dump and reset)

Expected result

The string to be parsed, and date time elements to be returned

Actual result

code crashes

Debug and AT command log

+++ LOOP ++++++++++++++++++++++++++++++++++++++++++++++++++ getGSMDateTime AT+CCLK?

+CCLK: "23/06/27,13:56:22+03"

OK 23/06/27,13:56:22+03 getNetworkTime AT+CCLK?

+CCLK: "23/06/27,13:56:22+03"

OK Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.

Core 1 register dump: PC : 0x4008630c PS : 0x00060830 A0 : 0x800e89ca A1 : 0x3ffb1d90 A2 : 0x000007e7 A3 : 0x000007e3 A4 : 0x000000ff A5 : 0x0000ff00
A6 : 0x00ff0000 A7 : 0xff000000 A8 : 0x002e2e2e A9 : 0x3ffb2110 A10 : 0x3ffb21bc A11 : 0x00000000 A12 : 0x00000004 A13 : 0x0000ff00
A14 : 0x00ff0000 A15 : 0xff000000 SAR : 0x00000020 EXCCAUSE: 0x0000001c EXCVADDR: 0x000007e7 LBEG : 0x40086145 LEND : 0x40086155 LCOUNT : 0xfffffffa

Backtrace: 0x40086309:0x3ffb1d90 0x400e89c7:0x3ffb1da0 0x400ed4ea:0x3ffb20b0 0x400ed522:0x3ffb2140 0x400d4526:0x3ffb2180 0x400d2b22:0x3ffb2220 0x400d5cb1:0x3ffb2290

ELF file SHA256: 3c4a5bc44a5d87db

Rebooting...