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

Dependencies:   mbed-src mtsas

Committer:
Vanger
Date:
Thu Jul 24 19:24:37 2014 +0000
Revision:
0:d9fd19c8ca39
Child:
1:1f5c9497a125
MTSAS example to demonstrate the use of the mtsas library to send an SMS message to the phone number set, read all received messages from the radio, and delete all sms messages before and after sending the sms message.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Vanger 0:d9fd19c8ca39 1 #include "mbed.h"
Vanger 0:d9fd19c8ca39 2 #include "mtsas.h"
Vanger 0:d9fd19c8ca39 3
Vanger 0:d9fd19c8ca39 4 int main(){
Vanger 0:d9fd19c8ca39 5 //Modify to match your apn if you are using an HSPA radio with a SIM card
Vanger 0:d9fd19c8ca39 6 const char APN[] = "";
Vanger 0:d9fd19c8ca39 7
Vanger 0:d9fd19c8ca39 8 //Input the phone number below that you want to send the SMS messages to.
Vanger 0:d9fd19c8ca39 9 //Send the AT command AT+CNUM to the radio to obtain the phone number of the radio.
Vanger 0:d9fd19c8ca39 10 const char PHONE_NUMBER[] = "";
Vanger 0:d9fd19c8ca39 11
Vanger 0:d9fd19c8ca39 12 /** STMicro Nucelo F401RE
Vanger 0:d9fd19c8ca39 13 * The supported jumper configurations of the MTSAS do not line up with
Vanger 0:d9fd19c8ca39 14 * the pin mapping of the Nucleo F401RE. Therefore, the MTSAS serial TX
Vanger 0:d9fd19c8ca39 15 * pin (JP8 Pin 2) must be manually jumped to Serial1 RX (Shield pin D2)
Vanger 0:d9fd19c8ca39 16 * and the MTSAS serial RX pin (JP9 Pin 2) pin must be manually jumped to
Vanger 0:d9fd19c8ca39 17 * Serial1 TX (Shield pin D8).
Vanger 0:d9fd19c8ca39 18 * Uncomment the following line to use the STMicro Nuceleo F401RE
Vanger 0:d9fd19c8ca39 19 */
Vanger 0:d9fd19c8ca39 20 MTSSerialFlowControl* io = new MTSSerialFlowControl(D8, D2, D3, D6);
Vanger 0:d9fd19c8ca39 21
Vanger 0:d9fd19c8ca39 22 /** Freescale KL46Z
Vanger 0:d9fd19c8ca39 23 * To configure the pins for the Freescale KL46Z board, use configuration B
Vanger 0:d9fd19c8ca39 24 * for the SocketModem. The TX pin should be jumped to pin D2 (JP8), and the
Vanger 0:d9fd19c8ca39 25 * RX pin should be jumped to pin D9 (JP9).
Vanger 0:d9fd19c8ca39 26 * Uncomment te following line to use the Freescale KL46Z board
Vanger 0:d9fd19c8ca39 27 */
Vanger 0:d9fd19c8ca39 28 //MTSSerialFlowControl* io = new MTSSerialFlowControl(D2, D9, D3, D6);
Vanger 0:d9fd19c8ca39 29
Vanger 0:d9fd19c8ca39 30 /** Freescale KL64F
Vanger 0:d9fd19c8ca39 31 * To configure the pins for the Freescale KL46Z board, use configuration A
Vanger 0:d9fd19c8ca39 32 * for the SocketModem. The TX pin should be jumped to pin D1 (JP8), and the
Vanger 0:d9fd19c8ca39 33 * RX pin should be jumped to pin D0 (JP9).
Vanger 0:d9fd19c8ca39 34 * Uncomment te following line to use the Freescale KL46F board
Vanger 0:d9fd19c8ca39 35 */
Vanger 0:d9fd19c8ca39 36 //MTSSerialFlowControl* io = new MTSSerialFlowControl(D1, D0, D3, D6);
Vanger 0:d9fd19c8ca39 37
Vanger 0:d9fd19c8ca39 38 //Sets the baudrate for communicating with the radio
Vanger 0:d9fd19c8ca39 39 io->baud(115200);
Vanger 0:d9fd19c8ca39 40
Vanger 0:d9fd19c8ca39 41 Cellular* radio = CellularFactory::create(io);
Vanger 0:d9fd19c8ca39 42 radio->setApn(APN);
Vanger 0:d9fd19c8ca39 43 wait(15);
Vanger 0:d9fd19c8ca39 44
Vanger 0:d9fd19c8ca39 45 //Delete all SMS messages
Vanger 0:d9fd19c8ca39 46 radio->sendBasicCommand("AT+CMGD=1,4", 1000);
Vanger 0:d9fd19c8ca39 47
Vanger 0:d9fd19c8ca39 48 //Setup commands and settings
Vanger 0:d9fd19c8ca39 49 radio->sendBasicCommand("AT+CMGF=1", 1000);
Vanger 0:d9fd19c8ca39 50
Vanger 0:d9fd19c8ca39 51 /** If the radio is and H5 type (MTSMC_H5, MTSMC_H5_IP) then
Vanger 0:d9fd19c8ca39 52 * uncomment the first line. Otherwise, uncomment the second line.
Vanger 0:d9fd19c8ca39 53 */
Vanger 0:d9fd19c8ca39 54 radio->sendBasicCommand("AT+CSMP=17,167,0,0", 1000);
Vanger 0:d9fd19c8ca39 55 //radio->sendBasicCommand("AT+CSMP=,4098,0,2", 1000);
Vanger 0:d9fd19c8ca39 56
Vanger 0:d9fd19c8ca39 57 //Format message and send to radio
Vanger 0:d9fd19c8ca39 58 char command[100] = {0};
Vanger 0:d9fd19c8ca39 59 sprintf(command, "AT+CMGS=\"%s\"", PHONE_NUMBER);
Vanger 0:d9fd19c8ca39 60 radio->sendCommand(command, 1000);
Vanger 0:d9fd19c8ca39 61 radio->sendCommand("Hello from MultiTechSystems!", 5000, CTRL_Z);
Vanger 0:d9fd19c8ca39 62 wait(5);
Vanger 0:d9fd19c8ca39 63
Vanger 0:d9fd19c8ca39 64 //Read all messages received
Vanger 0:d9fd19c8ca39 65 std::string received = radio->sendCommand("AT+CMGL=\"ALL\"", 2000);
Vanger 0:d9fd19c8ca39 66 printf("Messages received:\n%s", received.c_str());
Vanger 0:d9fd19c8ca39 67
Vanger 0:d9fd19c8ca39 68 //Delete all messages
Vanger 0:d9fd19c8ca39 69 radio->sendBasicCommand("AT+CMGD=1,4", 1000);
Vanger 0:d9fd19c8ca39 70
Vanger 0:d9fd19c8ca39 71 printf("End of example code\n");
Vanger 0:d9fd19c8ca39 72 return 0;
Vanger 0:d9fd19c8ca39 73 }