Is it impossible to use the Particle Electron with the Particle SIM to send a direct SMS… or is my code wrong?
In the code below, I tried multiple attempts in a crude copy and paste of a function to validate that I had my syntax/number formatted correctly. Watching the serial monitor, the second format works in terms of function, but I get the following error “+CMS ERROR: Call Barred”.
What does this error mean, in laymens terms? I’ve googled for the error and its painfully written and less intuitive to me than the verbiage of the error itself. Which, to me, implies a network restriction.
I’ve seen the other examples of successful direct sending of sms, but only on 3rd party SIMs. This includes the very helpful example by krvarma example by krvarma
So is it a problem in the code? Or do I need a 3rd party SIM. Thanks in advance. Ben
char szPhoneNumber[] = "3334444";
char szPhoneNumber2[] = "12223334444";
char szPhoneNumber3[] = "+12223334444";
unsigned long lastTime = 0;
#define MAX_PHONE_NUMBER 14
#define CTRL_Z 0x1A
#define TIMEOUT 10000
int callback(int type, const char* buf, int len, char* param){
Serial.print("Return: ");
Serial.write((const uint8_t*)buf, len);
Serial.println();
return WAIT;
}
void setup() {
Cellular.connect();
Serial.begin(9600);
}
void loop() {
// Particle.publish("senda", "loop started");
if (millis() - lastTime >= 300000) {
lastTime = millis();
sendMessage("T1 333444");
Particle.publish("senda", "sms");
sendMessage2("T2 +12223334444");
Particle.publish("senda", "sms2");
sendMessage3("T3 12223334444");
Particle.publish("senda", "sms3");
}
}
int sendMessage(char* pMessage){
char szCmd[64];
sprintf(szCmd, "AT+CMGS=\"+%s\",145\r\n", szPhoneNumber);
Serial.print("Sending command ");
Serial.print(szCmd);
Serial.println();
char szReturn[32] = "";
Cellular.command(callback, szReturn, TIMEOUT, "AT+CMGF=1\r\n");
Cellular.command(callback, szReturn, TIMEOUT, szCmd);
Cellular.command(callback, szReturn, TIMEOUT, pMessage);
sprintf(szCmd, "%c", CTRL_Z);
int retVal = Cellular.command(callback, szReturn, TIMEOUT, szCmd);
if(RESP_OK == retVal){
Serial.println("+OK, Message Send");
}
else{
Serial.println("+ERROR, error sending message");
}
return retVal;
}
int sendMessage2(char* pMessage){
char szCmd[64];
sprintf(szCmd, "AT+CMGS=\"+%s\",145\r\n", szPhoneNumber2);
Serial.print("Sending command ");
Serial.print(szCmd);
Serial.println();
char szReturn[32] = "";
Cellular.command(callback, szReturn, TIMEOUT, "AT+CMGF=1\r\n");
Cellular.command(callback, szReturn, TIMEOUT, szCmd);
Cellular.command(callback, szReturn, TIMEOUT, pMessage);
sprintf(szCmd, "%c", CTRL_Z);
int retVal = Cellular.command(callback, szReturn, TIMEOUT, szCmd);
if(RESP_OK == retVal){
Serial.println("+OK, Message Send");
}
else{
Serial.println("+ERROR, error sending message");
}
return retVal;
}
int sendMessage3(char* pMessage){
char szCmd[64];
sprintf(szCmd, "AT+CMGS=\"+%s\",145\r\n", szPhoneNumber3);
Serial.print("Sending command ");
Serial.print(szCmd);
Serial.println();
char szReturn[32] = "";
Cellular.command(callback, szReturn, TIMEOUT, "AT+CMGF=1\r\n");
Cellular.command(callback, szReturn, TIMEOUT, szCmd);
Cellular.command(callback, szReturn, TIMEOUT, pMessage);
sprintf(szCmd, "%c", CTRL_Z);
int retVal = Cellular.command(callback, szReturn, TIMEOUT, szCmd);
if(RESP_OK == retVal){
Serial.println("+OK, Message Send");
}
else{
Serial.println("+ERROR, error sending message");
}
return retVal;
}