Team,
Trying to do the following with a SIM7600.
Operator needs 2424 and BAL sent to retrieve the balance
Output using AT commands directly and all I want is the credit 20.05
.
SMS text is at index 0 and +CMGRD=0
reads then deletes.
Couple of questions is I need to factor if there is any other random SMS from the operator so every x hrs I run modem.sendAT("+CMGD=0,4");
that deletes all SMS texts so I should be at index 0 again.
Thoughts? where I am going wrong? Its almost like code doesnt work and its only given me the credit value when the SMS is not deleted i.e, at a different index say 1 or 2.
Run the AT+CPMS? to see where the SMS is located - SIM, stop my +CMGD=0,4
command and SMS count builds as expected.
AT+CPMS?
+CPMS: "SM",0,10,"SM",0,10,"SM",0,10
+CPMS: "SM",1,10,"SM",1,10,"SM",1,10
+CPMS: "SM",3,10,"SM",3,10,"SM",3,10
AT commands are
AT+CMGF=1
AT+CMGS="2424"
BAL
CTRL-Z
Output from the AT+CPMS 2424 BAL command
18:37:16.135 -> AT+CMGS="2424"
18:37:16.135 ->
18:37:16.135 -> >
18:37:22.475 ->
18:37:22.475 -> +CMGS: 201
18:37:22.521 ->
18:37:22.521 -> OK
18:37:22.521 -> +CMGS Sent BALANCE request!!!
18:37:22.521 -> AT+CMGL="REC UNREAD"
18:37:22.993 ->
18:37:22.993 -> +CMGL: 1,"REC UNREAD","2424","","23/07/12,18:33:17+48"
18:37:23.089 -> Hi! Your Skinny balance is
18:37:23.183 -> $20.05 credit
Code block that was working and randomly works. Well I think it works when it finds a old SMS at index 0.
//Get Balance send to display on boot
void Get_Balance()
{
if (balance_requested) {
//Serial.println("Balance has already been requested!");
return;
}
String smsNumber = "2424";
String smsMessage2 = "BAL";
//Set in global
//modem.sendAT("+CMGF=1");
//modem.waitResponse(1000L);
String command = "+CMGS=\"" + smsNumber + "\"";
modem.sendAT(command);
modem.waitResponse(1000L);
SerialAT.print(smsMessage2);
modem.waitResponse(1000L);
SerialAT.write(CR);
modem.waitResponse(5000L);
pDBGln("+CMGS Sent BALANCE request!!!");
//modem.sendAT("+CMGL=\"ALL\"");
//modem.waitResponse(120000L);
modem.sendAT("+CMGL=\"REC UNREAD\"");
modem.waitResponse(5000L);
modem.sendAT("+CMGRD=0");
data = SerialAT.readString();
Serial.print("message: ");
Serial.println(data);
String balanceMessage = data.substring(data.indexOf("$"));
balanceMessage.trim();
float balance = balanceMessage.substring(1).toFloat();
Serial.print("Get balance: ");
Serial.println(balance);
credit = balance;
mqtt.publish(topicCredit, String(balance).c_str());
balance_requested = true;
}
OK
AT+CMGF=1
OK
AT+CMGS="2424"
>
BAL
>
>
+CMGS: 246
OK
+CMTI: "SM",0
+CMTI response takes 10-12 secs or 1-2 secs
0 – No SMS-DELIVER indications are routed to the TE.
1 – If SMS-DELIVER is stored into ME/TA, indication of the
memory location is routed to the TE using unsolicited result code:
+CMTI: <mem3>,<index>
If I use the AT manual commands to get the credit SMS the code and dont delete it the next time it picks it up and gets the credit value of 19.35 which is correct but to me this means the this code is not working and the logs at the bottom show it picked up on a previous SMS at index 0?
String command = "+CMGS=\"" + smsNumber + "\"";
modem.sendAT(command);
modem.waitResponse(1000L);
SerialAT.print(smsMessage2);
modem.waitResponse(1000L);
SerialAT.write(CR);
modem.waitResponse(5000L);
pDBGln("+CMGS Sent BALANCE request!!!");
//modem.sendAT("+CMGL=\"ALL\"");
//modem.waitResponse(120000L);
modem.sendAT("+CMGL=\"REC UNREAD\"");
modem.waitResponse(5000L);
modem.sendAT("+CMGRD=0");
data = SerialAT.readString();
Serial.print("message: ");
Serial.println(data);
19:44:42.906 -> AT+CMGS="2424"
19:44:42.906 ->
19:44:42.906 -> >
19:44:45.252 ->
19:44:45.252 -> +CMGS: 247
19:44:45.252 ->
19:44:45.252 -> OK
19:44:45.299 -> +CMGS Sent BALANCE request!!!
19:44:45.299 -> AT+CMGL="REC UNREAD"
19:44:45.299 ->
19:44:45.299 -> OK
19:44:45.299 -> AT+CMGRD=0
19:44:46.374 -> message:
19:44:46.374 -> +CMGRD: "REC READ","2424","","23/07/13,19:42:38+48"
19:44:46.374 -> Hi! Your Skinny balance is
19:44:46.374 -> $19.35 credit
19:44:46.374 -> For your account info, text INFO to 2424.
19:44:46.419 ->
19:44:46.419 -> OK
Can someone educate me as I dont understand where I am going wrong?