Example program demonstrating sending and reading SMS messages from the cellular modem using the MTSAS library.

Dependencies:   mbed-src mtsas

Revision:
0:d9fd19c8ca39
Child:
1:1f5c9497a125
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jul 24 19:24:37 2014 +0000
@@ -0,0 +1,73 @@
+#include "mbed.h"
+#include "mtsas.h"
+
+int main(){
+    //Modify to match your apn if you are using an HSPA radio with a SIM card
+    const char APN[] = "";
+    
+    //Input the phone number below that you want to send the SMS messages to.
+    //Send the AT command AT+CNUM to the radio to obtain the phone number of the radio.
+    const char PHONE_NUMBER[] = "";
+    
+    /** STMicro Nucelo F401RE
+    * The supported jumper configurations of the MTSAS do not line up with
+    * the pin mapping of the Nucleo F401RE. Therefore, the MTSAS serial TX
+    * pin (JP8 Pin 2) must be manually jumped to Serial1 RX (Shield pin D2)
+    * and the MTSAS serial RX pin (JP9 Pin 2) pin must be manually jumped to
+    * Serial1 TX (Shield pin D8).
+    * Uncomment the following line to use the STMicro Nuceleo F401RE
+    */
+    MTSSerialFlowControl* io = new MTSSerialFlowControl(D8, D2, D3, D6);
+    
+    /** Freescale KL46Z
+    * To configure the pins for the Freescale KL46Z board, use configuration B
+    * for the SocketModem. The TX pin should be jumped to pin D2 (JP8), and the
+    * RX pin should be jumped to pin D9 (JP9). 
+    * Uncomment te following line to use the Freescale KL46Z board
+    */
+    //MTSSerialFlowControl* io = new MTSSerialFlowControl(D2, D9, D3, D6);
+    
+    /** Freescale KL64F
+    * To configure the pins for the Freescale KL46Z board, use configuration A
+    * for the SocketModem. The TX pin should be jumped to pin D1 (JP8), and the
+    * RX pin should be jumped to pin D0 (JP9). 
+    * Uncomment te following line to use the Freescale KL46F board
+    */
+    //MTSSerialFlowControl* io = new MTSSerialFlowControl(D1, D0, D3, D6);
+    
+    //Sets the baudrate for communicating with the radio
+    io->baud(115200); 
+    
+    Cellular* radio = CellularFactory::create(io);
+    radio->setApn(APN); 
+    wait(15);
+    
+    //Delete all SMS messages
+    radio->sendBasicCommand("AT+CMGD=1,4", 1000);
+    
+    //Setup commands and settings
+    radio->sendBasicCommand("AT+CMGF=1", 1000);
+    
+    /** If the radio is and H5 type (MTSMC_H5, MTSMC_H5_IP) then
+     * uncomment the first line. Otherwise, uncomment the second line.
+     */
+    radio->sendBasicCommand("AT+CSMP=17,167,0,0", 1000);
+    //radio->sendBasicCommand("AT+CSMP=,4098,0,2", 1000);
+    
+    //Format message and send to radio
+    char command[100] = {0};
+    sprintf(command, "AT+CMGS=\"%s\"", PHONE_NUMBER);
+    radio->sendCommand(command, 1000);
+    radio->sendCommand("Hello from MultiTechSystems!", 5000, CTRL_Z);
+    wait(5);
+    
+    //Read all messages received
+    std::string received = radio->sendCommand("AT+CMGL=\"ALL\"", 2000);
+    printf("Messages received:\n%s", received.c_str());
+    
+    //Delete all messages
+    radio->sendBasicCommand("AT+CMGD=1,4", 1000);
+    
+    printf("End of example code\n");
+    return 0;
+}
\ No newline at end of file