I think one of the powerful API in Electron is the Cellular APIs. With Cellular APIs you can turn on/off the cellular module, read the RSSI, set custom APN in case you are using your own SIM card, etc… One of the interesting and most powerful API is Cellular.command. This API allows you to send AT commands directly to the cellular module. This is a powerful API, especially it gives you the ability to send AT commands supported by the U-Blox cellular module and parse the response.
Here is a sample application to text messages (SMS) using the Cellular.command API. You can refer to this U-Blox Commands Manual and this Example Application Note for the supported AT Commands. From the document you can see that +CMGS command can be used to send direct message. Format to send this AT Command is:
AT+CMGS="<number>"<129/145><CR><message body><ctrl+z>
An Example is:
AT+CMGS="+00123456789",145<CR>Message Body<Ctrl+Z>
The first part AT+MGS="123456789",145<CR>
specifies the telephone number and its address type. Address type can be 129 or 145. The type 129 specifies the number is formatted with ISDN/ITU but does not specify whether it is international, national or other type. The type 145 specifies this is ISDN/ITU formatted and is an international number starts with “+” symbol. The last character in the first part is Carriage Return (CR), ASCII code 13 (0x0D).
The second part is the message body terminates with Ctrl+Z ASCII Code 26 (0x1A).
Sample Application
The sample application uses a TSL256 Luminosity sensor to measure light value, If it is below a configurable minimum value, it will send text message to a predefined telephone number. Please not that here I am using third party (my own) SIM, not Particle SIM. I didn’t test it with Particle SIM.
A sample text message is
It's too dark here (9.25 lux)
Here is the a code snippet from the application that sends text message:
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;
}