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
main.cpp
- Committer:
- Vanger
- Date:
- 2014-07-28
- Revision:
- 6:9c490265dd91
- Parent:
- 4:8b02a6b67f4d
- Child:
- 7:3e937d898953
File content as of revision 6:9c490265dd91:
#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[] = ""; //Sets the log level to INFO, which is about midway on priority levels //Possible levels: FATAL, ERROR, WARNING, INFO, DEBUG, TRACE, NONE MTSLog::setLogLevel(MTSLog::INFO_LEVEL); /** 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. * 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. * 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); for (int i = 0; i < 10; i++) { if (i >= 10) { logError("Failed to set APN"); } if (radio->setApn(APN) == MTS_SUCCESS) { logInfo("Successfully set APN [%s]", APN); break; } else { wait(1); } } //Establish PPP link for (int i = 0; i < 10; i++) { if (i >= 10) { logError("Failed to connect to cell network"); } if (radio->connect() == true) { logInfo("Successfully established PPP link"); break; } else { wait(1); } } //Ping google.com for (int i = 0; i < 10; i++) { if (i >= 10) { logError("Failed to ping google.com"); } if (radio->ping("www.google.com") == true) { logInfo("Successfully pinged www.google.com"); break; } else { wait(1); } } //Disconnect ppp link radio->disconnect(); logInfo("End of example code"); return 0; }