Hi,
I’m using a 2G Electron with a third-party SIM and flashed with the 0.5.2 firmware.
I’m trying to read an SMS from the cellular module like this:
#include "TestSms.h"
#include "application.h"
STARTUP(cellular_credentials_set("my.apn", "", "", NULL));
int theCallback(int type, const char* buf, int len, int* param) {
Serial.printlnf("type: %d. buf: %s. len: %d. param: %d.", type, buf, len, (*param));
delay(100);
if (type != TYPE_OK) {
return WAIT;
}
else {
return RESP_OK;
}
}
void setup() {
Serial.begin(9600);
while(!Serial.available()) {
Particle.process();
}
Serial.println("Serial started.");
int a = 5, resp;
Serial.println("Before.");
resp = Cellular.command(theCallback, &a, 300000, "AT+CMGF=1\r");
delay(100);
Serial.printlnf("After. Resp: %d.", resp);
Serial.println("Before.");
resp = Cellular.command(theCallback, &a, 300000, "AT+CPMS=\"MT\"\r");
delay(100);
Serial.printlnf("After. Resp: %d.", resp);
}
void loop() {
delay(10000);
int a = 5, resp;
Serial.println("Before.");
resp = Cellular.command(theCallback, &a, 300000, "AT+CMGR=1\r");
delay(100);
Serial.printlnf("After. Resp: %d.", resp);
if (resp != RESP_OK) {
Serial.println("Not ok.");
}
else {
Serial.println("Ok.");
}
}
The responses I get from the cellular module are strange. Here’s a picture (since I can’t copy-paste from the serial monitor):
The AT Commands Examples Manual (page 110) says that the response for “AT+CMGF=1” should be “OK” but I get something like "OK\r\n , ".
Also, as you can see, my biggest problem is with retrieving the contents of an SMS. After I call “AT+CMGR=1” I get three responses:
- One with a type of TYPE_PLUS that contains just the SMS headers and lots of gibberish. The weird thing is that the “len” callback parameter says that the response length is 53 which is exactly the length of the message except for the gibberish part.
- One with a type of TYPE_UNKNOWN that contains the SMS text (“Test. Test. Test.”) then a part of the SMS headers then the (same) gibberish again. The “len” parameter, again, only acknowledges the good parts of the response. The TYPE_UNKNOWN status if very disturbing.
- One with a type of TYPE_OK that contains part of the SMS text, part of the SMS headers then the dreaded gibberish.
This smells a lot like a memory leak but I can’t really figure out if I did something wrong and what that would be.
As a side question: I tested the same code with “\r” and “\r\n” at the end of the AT commands I sent. The result is the same but I wonder, which one is correct?
Thank you!