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:
Thu Aug 07 20:35:21 2014 +0000
Revision:
11:7e11c3f99b51
Parent:
10:2e6637cca9d7
Child:
12:23c052e020a9
Deleted socketmodem under configuration comment line.

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 9:0ed53023033b 8 //Sets the log level to INFO, higher log levels produce more log output.
Vanger 9:0ed53023033b 9 //Possible levels: NONE, FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
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 9:0ed53023033b 24 * Uncomment the following line to use the Freescale KL46Z board
Vanger 0:47bc9ce390cc 25 */
Vanger 0:47bc9ce390cc 26 //MTSSerialFlowControl* io = new MTSSerialFlowControl(D2, D9, D3, D6);
Vanger 0:47bc9ce390cc 27
Vanger 9:0ed53023033b 28 /** Freescale K64F
Vanger 0:47bc9ce390cc 29 * To configure the pins for the Freescale KL46Z board, use configuration A
Vanger 10:2e6637cca9d7 30 * Uncomment the following line to use the Freescale KL46F board
Vanger 0:47bc9ce390cc 31 */
Vanger 0:47bc9ce390cc 32 //MTSSerialFlowControl* io = new MTSSerialFlowControl(D1, D0, D3, D6);
Vanger 0:47bc9ce390cc 33
Vanger 9:0ed53023033b 34 //Sets the baud rate for communicating with the radio
Vanger 1:4c54ec0a3a20 35 io->baud(115200);
Vanger 0:47bc9ce390cc 36
Vanger 8:95c226a1dca7 37 //Create radio object
Vanger 0:47bc9ce390cc 38 Cellular* radio = CellularFactory::create(io);
Vanger 8:95c226a1dca7 39 radio->configureSignals(D4,D7,RESET);
Vanger 8:95c226a1dca7 40 Transport::setTransport(radio);
Vanger 8:95c226a1dca7 41
Vanger 9:0ed53023033b 42 if (! radio) {
Vanger 9:0ed53023033b 43 logFatal("Failed to initialize radio");
Vanger 9:0ed53023033b 44 return 1;
Vanger 9:0ed53023033b 45 }
Vanger 9:0ed53023033b 46
Vanger 8:95c226a1dca7 47 //Set radio APN
Vanger 1:4c54ec0a3a20 48 for (int i = 0; i < 10; i++) {
Vanger 1:4c54ec0a3a20 49 if (i >= 10) {
mfiore 5:46e66c649006 50 logError("Failed to set APN to %s", APN);
Vanger 1:4c54ec0a3a20 51 }
Vanger 1:4c54ec0a3a20 52 if (radio->setApn(APN) == MTS_SUCCESS) {
mfiore 5:46e66c649006 53 logInfo("Successfully set APN to %s", APN);
Vanger 1:4c54ec0a3a20 54 break;
Vanger 1:4c54ec0a3a20 55 } else {
Vanger 1:4c54ec0a3a20 56 wait(1);
Vanger 1:4c54ec0a3a20 57 }
Vanger 1:4c54ec0a3a20 58 }
Vanger 0:47bc9ce390cc 59
Vanger 0:47bc9ce390cc 60 //Establish PPP link
Vanger 1:4c54ec0a3a20 61 for (int i = 0; i < 10; i++) {
Vanger 1:4c54ec0a3a20 62 if (i >= 10) {
mfiore 5:46e66c649006 63 logError("Failed to establish PPP link");
Vanger 1:4c54ec0a3a20 64 }
Vanger 1:4c54ec0a3a20 65 if (radio->connect() == true) {
Vanger 3:f22ad66e049e 66 logInfo("Successfully established PPP link");
Vanger 1:4c54ec0a3a20 67 break;
Vanger 1:4c54ec0a3a20 68 } else {
Vanger 1:4c54ec0a3a20 69 wait(1);
Vanger 1:4c54ec0a3a20 70 }
Vanger 1:4c54ec0a3a20 71 }
Vanger 0:47bc9ce390cc 72
Vanger 1:4c54ec0a3a20 73 //Ping google.com
Vanger 1:4c54ec0a3a20 74 for (int i = 0; i < 10; i++) {
Vanger 1:4c54ec0a3a20 75 if (i >= 10) {
mfiore 5:46e66c649006 76 logError("Failed to ping www.google.com");
Vanger 1:4c54ec0a3a20 77 }
Vanger 3:f22ad66e049e 78 if (radio->ping("www.google.com") == true) {
Vanger 4:8b02a6b67f4d 79 logInfo("Successfully pinged www.google.com");
Vanger 1:4c54ec0a3a20 80 break;
Vanger 1:4c54ec0a3a20 81 } else {
Vanger 1:4c54ec0a3a20 82 wait(1);
Vanger 1:4c54ec0a3a20 83 }
Vanger 1:4c54ec0a3a20 84 }
Vanger 0:47bc9ce390cc 85
Vanger 0:47bc9ce390cc 86 //Disconnect ppp link
Vanger 0:47bc9ce390cc 87 radio->disconnect();
Vanger 0:47bc9ce390cc 88
Vanger 3:f22ad66e049e 89 logInfo("End of example code");
Vanger 0:47bc9ce390cc 90 return 0;
Vanger 8:95c226a1dca7 91 }