Particle Electron Send SMS, with Particle SIM

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;
}

Particle SIMs do not support SMS, so if you need direct SMS, you’ll have to use a 3rd party SIM. Alternatively, use an online SMS service, which might end up being a lot cheaper/convenient.

4 Likes

Just some notes on the code.
Instead of having three different sendMessageX() functions (which only differ in target phone number AFAICT), why not just have one function that also takes a const char* phoneNumber parameter?

4 Likes

The project target is to have independent systems able to use a cellular network, to send direct sms. If I was going to use an sms service I could achieve it with wifi and a sendmail script to a cellular network that translates/sends it as a text.( IE: email 12223334444@vtext.com ) I’ve done this on the much cheaper esp8266. I could also do that with a service, Twillio.

Doing what you suggested, while using the particle electron would make me reliant on a 3rd party service like Twillio, on top of cellular service/connectivity and dependence on particle. While the cellular network makes it easier than configuring esp8266’s on wifis every deployment, I’m not sure it’s better than a 3rd party sim.

Please let me know if I am thinking about this the wrong way. Thanks for your reply btw.

Thanks ScruffR, I’ve seen your posts in the forums and they’ve been useful dropping into the whole particle environment. I was simply being lazy and doing the fastest dirtiest thing to get an AT response to make sure I knew which one had the correct number format for the AT command.

Copy and Paste was quicker than thinking and creating anything original about that code. Which seems pretty standard.

Your suggested approach is certainly what I would/will do now that I know which AT command number format is correct, and that my issue is actually the Particle Network’s inability to send direct SMS.

Thanks