Post by rrrrpa on Apr 25, 2024 2:04:01 GMT
I previously reported in another thread (SIM7000A modem.sendSMS return is not reliable) that there is a problem with the return from modem.sendSMS. I find the sendSMS is always successful,
but the return routinely reports that it failed. After much frustration I dove into the library to better understand what's happening.
I have identified an issue in the library for "boolean Botletics_modem::sendSMS(const char *smsaddr, const char *smsmsg)".
According to the library for the SIM7000A, two CRLFs are expected prior to the +CMGS reply.
THIS IS ABSOLUTELY WRONG. In addition, I occasionally get a collision between the sendSMS and a clock update.
Since I have no RTC on the Mega 2560 I depend on the cell tower for clock time via "modem.getTime(buffer, 23);". Hence, I have "modem.enableRTC(true);" in the setup routine.
For diagnostic purposes I modified modem.sendSMS per below.
Normally the reply to modem.sendSMS is this. NOTE NO CRLFs ARE EVER RECEIVED.
17:00:27.221 -> Elapsed time (msec) = 570 sendSMS reply: i = 0 length = 10 content = +CMGS: 169
17:00:27.286 -> Elapsed time (msec) = 587 sendSMS reply: i = 0 length = 2 content = OK
On occasion a clock update interferes and this is typical captured corrupted evidence:
15:21:00.867 -> Elapsed time (msec) = 1631 sendSMS reply: i = 0 length = 6 content = DST: 1
15:21:00.932 -> Cycling in the while loop
15:21:00.965 -> Elapsed time (msec) = 1672 sendSMS reply: i = 0 length = 35 content = *PSUTTZ: 24/04/24,22:20:59","-28",1
15:21:01.063 -> Cycling in the while loop
15:21:31.387 -> Elapsed time (msec) = 32162 sendSMS reply: i = 0 length = 0 content =
15:21:55.629 -> Elapsed time (msec) = 56401 sendSMS reply: i = 1 length = 10 content = +CMGS: 159
15:21:55.695 -> Elapsed time (msec) = 56419 sendSMS reply: i = 1 length = 2 content = OK
16:30:46.140 -> Elapsed time (msec) = 1809 sendSMS reply: i = 0 length = 6 content = DST: 1
16:30:46.239 -> Cycling in the while loop
16:30:46.239 -> Elapsed time (msec) = 1850 sendSMS reply: i = 0 length = 35 content = *PSUTTZ: 24/04/24,23:30:44","-28",1
16:30:46.370 -> Cycling in the while loop
16:31:16.686 -> Elapsed time (msec) = 32339 sendSMS reply: i = 0 length = 0 content =
16:31:41.335 -> Elapsed time (msec) = 57007 sendSMS reply: i = 1 length = 10 content = +CMGS: 166
16:31:41.436 -> Elapsed time (msec) = 57026 sendSMS reply: i = 1 length = 2 content = OK
I should also mention that the system is running on T-Mobile with good signal:
18:34:51.560 -> Sys Info --->+CPSI: LTE CAT-M1,Online,310-260,0x411F,21294086,47,EUTRAN-BAND12,5035,2,2,-8,-81,-60,16
18:34:51.700 -> Operator --->+COPS: 0,0,"T-Mobile",7
18:34:51.778 -> My Network status = 1 -> Registered (home)
18:34:51.853 -> RSSI = 27 -> -60 dBm
I assume "modem.enableRTC(true);" is required to be able to successfully get time via "modem.getTime(buffer, 23);". Am I wrong?
Any help will be appreciated. Thanks.
******************************************************************************************************************
boolean Botletics_modem::sendSMS(const char *smsaddr, const char *smsmsg) {
if (! sendCheckReply(F("AT+CMGF=1"), ok_reply)) return false;
char sendcmd[30] = "AT+CMGS=\"";
strncpy(sendcmd+9, smsaddr, 30-9-2); // 9 bytes beginning, 2 bytes for close quote + null
sendcmd[strlen(sendcmd)] = '\"';
if (! sendCheckReply(sendcmd, F("> "))) return false;
//DEBUG_PRINT(F("\t835---> ")); DEBUG_PRINTLN(smsmsg);
// no need for extra NEWLINE characters mySerial->println(smsmsg);
// no need for extra NEWLINE characters mySerial->println();
mySerial->print(smsmsg);
mySerial->write(0x1A);
//DEBUG_PRINTLN("^Z");
/*2024.02.03 - There is an issue (CRLF or timing?) with the SIM7000A
if ( (_type == SIM5320A) || (_type == SIM5320E) || (_type >= SIM7000) ) {
// Eat two sets of CRLF
readline(200);
DEBUG_PRINT("Line 1: "); DEBUG_PRINT(strlen(replybuffer)); DEBUG_PRINT(" = "); DEBUG_PRINTLN(replybuffer);
readline(200);
DEBUG_PRINT("Line 2: "); DEBUG_PRINT(strlen(replybuffer)); DEBUG_PRINT(" = "); DEBUG_PRINTLN(replybuffer);
}
readline(30000); // read the +CMGS reply, wait up to 30s
DEBUG_PRINT("Line 3: "); DEBUG_PRINT(strlen(replybuffer)); DEBUG_PRINT(" = "); DEBUG_PRINTLN(replybuffer);
if (strstr(replybuffer, "+CMGS") == 0) {
//DEBUG_PRINTLN("Line 4: FAILED!");
return false;
}
readline(1000); // read OK
DEBUG_PRINT("Line 5: "); DEBUG_PRINT(strlen(replybuffer)); DEBUG_PRINT(" = "); DEBUG_PRINTLN(replybuffer);
//DEBUG_PRINT("* "); DEBUG_PRINTLN(replybuffer);
if (strcmp(replybuffer, "OK") != 0) {
DEBUG_PRINTLN("Line 6: "); DEBUG_PRINT(strlen(replybuffer)); DEBUG_PRINT(" = "); DEBUG_PRINTLN(replybuffer);
return false;
}
//DEBUG_PRINTLN("Line 7: SUCCESSFUL!");
return true;
*/
unsigned long myTime = millis();
unsigned long myUL;
for (int i = 0; i < 3; i++) {
readline(30000); // look for the +CMGS reply, wait up to 30s
myUL = millis() - myTime;
Serial.print(F("Elapsed time (msec) = ")); Serial.print(myUL);
Serial.print(F("\tsendSMS reply: i = ")); Serial.print(i);
Serial.print(F("\tlength = ")); Serial.print(strlen(replybuffer));
Serial.print(F("\tcontent = ")); Serial.println(replybuffer);
while ((strstr(replybuffer, "DST:") != 0) || (strstr(replybuffer, "*PSUTTZ:") != 0)) {
Serial.println(F("Cycling in the while loop"));
readline(30000); // look for the +CMGS reply, wait up to 30s
myUL = millis() - myTime;
Serial.print(F("Elapsed time (msec) = ")); Serial.print(myUL);
Serial.print(F("\tsendSMS reply: i = ")); Serial.print(i);
Serial.print(F("\tlength = ")); Serial.print(strlen(replybuffer));
Serial.print(F("\tcontent = ")); Serial.println(replybuffer);
}
if (strstr(replybuffer, "+CMGS") != 0) {
readline(1000); // read the OK reply
myUL = millis() - myTime;
Serial.print(F("Elapsed time (msec) = ")); Serial.print(myUL);
Serial.print(F("\tsendSMS reply: i = ")); Serial.print(i);
Serial.print(F("\tlength = ")); Serial.print(strlen(replybuffer));
Serial.print(F("\tcontent = ")); Serial.println(replybuffer);
if (strcmp(replybuffer, "OK") == 0) { // returns 0 if the same
return true;
}
}
}
myUL = millis() - myTime;
Serial.print(F("Elapsed time (msec) = ")); Serial.println(myUL);
return false;
}
but the return routinely reports that it failed. After much frustration I dove into the library to better understand what's happening.
I have identified an issue in the library for "boolean Botletics_modem::sendSMS(const char *smsaddr, const char *smsmsg)".
According to the library for the SIM7000A, two CRLFs are expected prior to the +CMGS reply.
THIS IS ABSOLUTELY WRONG. In addition, I occasionally get a collision between the sendSMS and a clock update.
Since I have no RTC on the Mega 2560 I depend on the cell tower for clock time via "modem.getTime(buffer, 23);". Hence, I have "modem.enableRTC(true);" in the setup routine.
For diagnostic purposes I modified modem.sendSMS per below.
Normally the reply to modem.sendSMS is this. NOTE NO CRLFs ARE EVER RECEIVED.
17:00:27.221 -> Elapsed time (msec) = 570 sendSMS reply: i = 0 length = 10 content = +CMGS: 169
17:00:27.286 -> Elapsed time (msec) = 587 sendSMS reply: i = 0 length = 2 content = OK
On occasion a clock update interferes and this is typical captured corrupted evidence:
15:21:00.867 -> Elapsed time (msec) = 1631 sendSMS reply: i = 0 length = 6 content = DST: 1
15:21:00.932 -> Cycling in the while loop
15:21:00.965 -> Elapsed time (msec) = 1672 sendSMS reply: i = 0 length = 35 content = *PSUTTZ: 24/04/24,22:20:59","-28",1
15:21:01.063 -> Cycling in the while loop
15:21:31.387 -> Elapsed time (msec) = 32162 sendSMS reply: i = 0 length = 0 content =
15:21:55.629 -> Elapsed time (msec) = 56401 sendSMS reply: i = 1 length = 10 content = +CMGS: 159
15:21:55.695 -> Elapsed time (msec) = 56419 sendSMS reply: i = 1 length = 2 content = OK
16:30:46.140 -> Elapsed time (msec) = 1809 sendSMS reply: i = 0 length = 6 content = DST: 1
16:30:46.239 -> Cycling in the while loop
16:30:46.239 -> Elapsed time (msec) = 1850 sendSMS reply: i = 0 length = 35 content = *PSUTTZ: 24/04/24,23:30:44","-28",1
16:30:46.370 -> Cycling in the while loop
16:31:16.686 -> Elapsed time (msec) = 32339 sendSMS reply: i = 0 length = 0 content =
16:31:41.335 -> Elapsed time (msec) = 57007 sendSMS reply: i = 1 length = 10 content = +CMGS: 166
16:31:41.436 -> Elapsed time (msec) = 57026 sendSMS reply: i = 1 length = 2 content = OK
I should also mention that the system is running on T-Mobile with good signal:
18:34:51.560 -> Sys Info --->+CPSI: LTE CAT-M1,Online,310-260,0x411F,21294086,47,EUTRAN-BAND12,5035,2,2,-8,-81,-60,16
18:34:51.700 -> Operator --->+COPS: 0,0,"T-Mobile",7
18:34:51.778 -> My Network status = 1 -> Registered (home)
18:34:51.853 -> RSSI = 27 -> -60 dBm
I assume "modem.enableRTC(true);" is required to be able to successfully get time via "modem.getTime(buffer, 23);". Am I wrong?
Any help will be appreciated. Thanks.
******************************************************************************************************************
boolean Botletics_modem::sendSMS(const char *smsaddr, const char *smsmsg) {
if (! sendCheckReply(F("AT+CMGF=1"), ok_reply)) return false;
char sendcmd[30] = "AT+CMGS=\"";
strncpy(sendcmd+9, smsaddr, 30-9-2); // 9 bytes beginning, 2 bytes for close quote + null
sendcmd[strlen(sendcmd)] = '\"';
if (! sendCheckReply(sendcmd, F("> "))) return false;
//DEBUG_PRINT(F("\t835---> ")); DEBUG_PRINTLN(smsmsg);
// no need for extra NEWLINE characters mySerial->println(smsmsg);
// no need for extra NEWLINE characters mySerial->println();
mySerial->print(smsmsg);
mySerial->write(0x1A);
//DEBUG_PRINTLN("^Z");
/*2024.02.03 - There is an issue (CRLF or timing?) with the SIM7000A
if ( (_type == SIM5320A) || (_type == SIM5320E) || (_type >= SIM7000) ) {
// Eat two sets of CRLF
readline(200);
DEBUG_PRINT("Line 1: "); DEBUG_PRINT(strlen(replybuffer)); DEBUG_PRINT(" = "); DEBUG_PRINTLN(replybuffer);
readline(200);
DEBUG_PRINT("Line 2: "); DEBUG_PRINT(strlen(replybuffer)); DEBUG_PRINT(" = "); DEBUG_PRINTLN(replybuffer);
}
readline(30000); // read the +CMGS reply, wait up to 30s
DEBUG_PRINT("Line 3: "); DEBUG_PRINT(strlen(replybuffer)); DEBUG_PRINT(" = "); DEBUG_PRINTLN(replybuffer);
if (strstr(replybuffer, "+CMGS") == 0) {
//DEBUG_PRINTLN("Line 4: FAILED!");
return false;
}
readline(1000); // read OK
DEBUG_PRINT("Line 5: "); DEBUG_PRINT(strlen(replybuffer)); DEBUG_PRINT(" = "); DEBUG_PRINTLN(replybuffer);
//DEBUG_PRINT("* "); DEBUG_PRINTLN(replybuffer);
if (strcmp(replybuffer, "OK") != 0) {
DEBUG_PRINTLN("Line 6: "); DEBUG_PRINT(strlen(replybuffer)); DEBUG_PRINT(" = "); DEBUG_PRINTLN(replybuffer);
return false;
}
//DEBUG_PRINTLN("Line 7: SUCCESSFUL!");
return true;
*/
unsigned long myTime = millis();
unsigned long myUL;
for (int i = 0; i < 3; i++) {
readline(30000); // look for the +CMGS reply, wait up to 30s
myUL = millis() - myTime;
Serial.print(F("Elapsed time (msec) = ")); Serial.print(myUL);
Serial.print(F("\tsendSMS reply: i = ")); Serial.print(i);
Serial.print(F("\tlength = ")); Serial.print(strlen(replybuffer));
Serial.print(F("\tcontent = ")); Serial.println(replybuffer);
while ((strstr(replybuffer, "DST:") != 0) || (strstr(replybuffer, "*PSUTTZ:") != 0)) {
Serial.println(F("Cycling in the while loop"));
readline(30000); // look for the +CMGS reply, wait up to 30s
myUL = millis() - myTime;
Serial.print(F("Elapsed time (msec) = ")); Serial.print(myUL);
Serial.print(F("\tsendSMS reply: i = ")); Serial.print(i);
Serial.print(F("\tlength = ")); Serial.print(strlen(replybuffer));
Serial.print(F("\tcontent = ")); Serial.println(replybuffer);
}
if (strstr(replybuffer, "+CMGS") != 0) {
readline(1000); // read the OK reply
myUL = millis() - myTime;
Serial.print(F("Elapsed time (msec) = ")); Serial.print(myUL);
Serial.print(F("\tsendSMS reply: i = ")); Serial.print(i);
Serial.print(F("\tlength = ")); Serial.print(strlen(replybuffer));
Serial.print(F("\tcontent = ")); Serial.println(replybuffer);
if (strcmp(replybuffer, "OK") == 0) { // returns 0 if the same
return true;
}
}
}
myUL = millis() - myTime;
Serial.print(F("Elapsed time (msec) = ")); Serial.println(myUL);
return false;
}