Sample project to connect to AT&T M2X from the STM32 Nucleo + MTSAS Cellular SocketModem shield

Dependencies:   M2XStreamClient jsonlite mbed

Fork of MTSAS_Cellular_Connect_M2X_Example_F411 by Joe Tijerina

Committer:
Vanger
Date:
Mon Jul 28 15:20:57 2014 +0000
Revision:
7:3e937d898953
Parent:
5:46e66c649006
Parent:
6:9c490265dd91
Child:
8:95c226a1dca7
Added NONE for setLogLevel as a choice

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Vanger 0:47bc9ce390cc 1 #include "mbed.h"
Vanger 0:47bc9ce390cc 2 #include "mtsas.h"
Vanger 0:47bc9ce390cc 3
Vanger 0:47bc9ce390cc 4 int main(){
Vanger 0:47bc9ce390cc 5 //Modify to match your apn if you are using an HSPA radio with a SIM card
Vanger 4:8b02a6b67f4d 6 const char APN[] = "";
Vanger 4:8b02a6b67f4d 7
Vanger 4:8b02a6b67f4d 8 //Sets the log level to INFO, which is about midway on priority levels
Vanger 6:9c490265dd91 9 //Possible levels: FATAL, ERROR, WARNING, INFO, DEBUG, TRACE, NONE
Vanger 4:8b02a6b67f4d 10 MTSLog::setLogLevel(MTSLog::INFO_LEVEL);
Vanger 0:47bc9ce390cc 11
Vanger 0:47bc9ce390cc 12 /** STMicro Nucelo F401RE
Vanger 0:47bc9ce390cc 13 * The supported jumper configurations of the MTSAS do not line up with
Vanger 0:47bc9ce390cc 14 * the pin mapping of the Nucleo F401RE. Therefore, the MTSAS serial TX
Vanger 0:47bc9ce390cc 15 * pin (JP8 Pin 2) must be manually jumped to Serial1 RX (Shield pin D2)
Vanger 0:47bc9ce390cc 16 * and the MTSAS serial RX pin (JP9 Pin 2) pin must be manually jumped to
Vanger 0:47bc9ce390cc 17 * Serial1 TX (Shield pin D8).
Vanger 0:47bc9ce390cc 18 * Uncomment the following line to use the STMicro Nuceleo F401RE
Vanger 0:47bc9ce390cc 19 */
Vanger 0:47bc9ce390cc 20 MTSSerialFlowControl* io = new MTSSerialFlowControl(D8, D2, D3, D6);
Vanger 0:47bc9ce390cc 21
Vanger 0:47bc9ce390cc 22 /** Freescale KL46Z
Vanger 0:47bc9ce390cc 23 * To configure the pins for the Freescale KL46Z board, use configuration B
Vanger 3:f22ad66e049e 24 * for the SocketModem.
Vanger 0:47bc9ce390cc 25 * Uncomment te following line to use the Freescale KL46Z board
Vanger 0:47bc9ce390cc 26 */
Vanger 0:47bc9ce390cc 27 //MTSSerialFlowControl* io = new MTSSerialFlowControl(D2, D9, D3, D6);
Vanger 0:47bc9ce390cc 28
Vanger 0:47bc9ce390cc 29 /** Freescale KL64F
Vanger 0:47bc9ce390cc 30 * To configure the pins for the Freescale KL46Z board, use configuration A
Vanger 3:f22ad66e049e 31 * for the SocketModem.
Vanger 0:47bc9ce390cc 32 * Uncomment te following line to use the Freescale KL46F board
Vanger 0:47bc9ce390cc 33 */
Vanger 0:47bc9ce390cc 34 //MTSSerialFlowControl* io = new MTSSerialFlowControl(D1, D0, D3, D6);
Vanger 0:47bc9ce390cc 35
Vanger 0:47bc9ce390cc 36 //Sets the baudrate for communicating with the radio
Vanger 1:4c54ec0a3a20 37 io->baud(115200);
Vanger 0:47bc9ce390cc 38
Vanger 0:47bc9ce390cc 39 Cellular* radio = CellularFactory::create(io);
Vanger 1:4c54ec0a3a20 40 for (int i = 0; i < 10; i++) {
Vanger 1:4c54ec0a3a20 41 if (i >= 10) {
mfiore 5:46e66c649006 42 logError("Failed to set APN to %s", APN);
Vanger 1:4c54ec0a3a20 43 }
Vanger 1:4c54ec0a3a20 44 if (radio->setApn(APN) == MTS_SUCCESS) {
mfiore 5:46e66c649006 45 logInfo("Successfully set APN to %s", APN);
Vanger 1:4c54ec0a3a20 46 break;
Vanger 1:4c54ec0a3a20 47 } else {
Vanger 1:4c54ec0a3a20 48 wait(1);
Vanger 1:4c54ec0a3a20 49 }
Vanger 1:4c54ec0a3a20 50 }
Vanger 0:47bc9ce390cc 51
Vanger 0:47bc9ce390cc 52 //Establish PPP link
Vanger 1:4c54ec0a3a20 53 for (int i = 0; i < 10; i++) {
Vanger 1:4c54ec0a3a20 54 if (i >= 10) {
mfiore 5:46e66c649006 55 logError("Failed to establish PPP link");
Vanger 1:4c54ec0a3a20 56 }
Vanger 1:4c54ec0a3a20 57 if (radio->connect() == true) {
Vanger 3:f22ad66e049e 58 logInfo("Successfully established PPP link");
Vanger 1:4c54ec0a3a20 59 break;
Vanger 1:4c54ec0a3a20 60 } else {
Vanger 1:4c54ec0a3a20 61 wait(1);
Vanger 1:4c54ec0a3a20 62 }
Vanger 1:4c54ec0a3a20 63 }
Vanger 0:47bc9ce390cc 64
Vanger 1:4c54ec0a3a20 65 //Ping google.com
Vanger 1:4c54ec0a3a20 66 for (int i = 0; i < 10; i++) {
Vanger 1:4c54ec0a3a20 67 if (i >= 10) {
mfiore 5:46e66c649006 68 logError("Failed to ping www.google.com");
Vanger 1:4c54ec0a3a20 69 }
Vanger 3:f22ad66e049e 70 if (radio->ping("www.google.com") == true) {
Vanger 4:8b02a6b67f4d 71 logInfo("Successfully pinged www.google.com");
Vanger 1:4c54ec0a3a20 72 break;
Vanger 1:4c54ec0a3a20 73 } else {
Vanger 1:4c54ec0a3a20 74 wait(1);
Vanger 1:4c54ec0a3a20 75 }
Vanger 1:4c54ec0a3a20 76 }
Vanger 0:47bc9ce390cc 77
Vanger 0:47bc9ce390cc 78 //Disconnect ppp link
Vanger 0:47bc9ce390cc 79 radio->disconnect();
Vanger 0:47bc9ce390cc 80
Vanger 3:f22ad66e049e 81 logInfo("End of example code");
Vanger 0:47bc9ce390cc 82 return 0;
Vanger 0:47bc9ce390cc 83 }