Send SMS with Particle Electron


#1

I am trying to send a text to my phone with my particle electron. I just want to see if it works and have been looking for a simple example code to send one test text to myself. I have used this code,

#define MAX_PHONE_NUMBER    14
#define CTRL_Z 0x1A
#define TIMEOUT 10000

unsigned char id;
boolean gain;     // Gain setting, 0 = X1, 1 = X16;
unsigned int ms;  // Integration ("shutter") time in milliseconds
unsigned int data1;
unsigned int data2;
char szPhoneNumber[MAX_PHONE_NUMBER] = "155555555555";

int lowerLimit = 10;
boolean smsSend = false;

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

int setLowerLimit(String args){
    lowerLimit = args.toInt();
    
    return lowerLimit;
}

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

void setup() {
  Particle.keepAlive(30);  // test how high you can go

    Serial.begin(115200);
    Spark.function("setmin", setLowerLimit);
}

void loop() {

    Serial.println();
    Serial.println();
    
    char szMessage[64];
    
    if(strlen(strcpy(szMessage, "Particle Electron Test Message!")) > 10)
    {
    
    sendMessage(szMessage);
    
    delay(1000);
}
}

and looking at a serial monitor I am getting

[16:34:42 --- Rx] Return: 
+CIEV: 2,3


[16:34:45 --- Rx] +ERROR, error sending message

[16:34:47 --- Rx] 

Sending command AT+CMGS="++15555555555",145

Return: 
OK

Return: 
+CMS ERROR: operation not supported

Why am I getting this opperation not supported error? I am using a 3rd party SIM that I have tested in a cell phone and it sends sms just fine that way.


#2

I’d guess it’s the double plus sign ++ in your phone number.

I had posted some code some while ago