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@3:f22ad66e049e, 2014-07-28 (annotated)
- Committer:
- Vanger
- Date:
- Mon Jul 28 14:57:44 2014 +0000
- Revision:
- 3:f22ad66e049e
- Parent:
- 2:99606ba5d1bf
- Child:
- 4:8b02a6b67f4d
Added APN value set to APN log print, DNS name for ping as "www.google.com"; Removed \n from log lines.;
Who changed what in which revision?
User | Revision | Line number | New 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 | 3:f22ad66e049e | 6 | const char APN[] = "internet"; |
Vanger | 0:47bc9ce390cc | 7 | |
Vanger | 0:47bc9ce390cc | 8 | /** STMicro Nucelo F401RE |
Vanger | 0:47bc9ce390cc | 9 | * The supported jumper configurations of the MTSAS do not line up with |
Vanger | 0:47bc9ce390cc | 10 | * the pin mapping of the Nucleo F401RE. Therefore, the MTSAS serial TX |
Vanger | 0:47bc9ce390cc | 11 | * pin (JP8 Pin 2) must be manually jumped to Serial1 RX (Shield pin D2) |
Vanger | 0:47bc9ce390cc | 12 | * and the MTSAS serial RX pin (JP9 Pin 2) pin must be manually jumped to |
Vanger | 0:47bc9ce390cc | 13 | * Serial1 TX (Shield pin D8). |
Vanger | 0:47bc9ce390cc | 14 | * Uncomment the following line to use the STMicro Nuceleo F401RE |
Vanger | 0:47bc9ce390cc | 15 | */ |
Vanger | 0:47bc9ce390cc | 16 | MTSSerialFlowControl* io = new MTSSerialFlowControl(D8, D2, D3, D6); |
Vanger | 0:47bc9ce390cc | 17 | |
Vanger | 0:47bc9ce390cc | 18 | /** Freescale KL46Z |
Vanger | 0:47bc9ce390cc | 19 | * To configure the pins for the Freescale KL46Z board, use configuration B |
Vanger | 3:f22ad66e049e | 20 | * for the SocketModem. |
Vanger | 0:47bc9ce390cc | 21 | * Uncomment te following line to use the Freescale KL46Z board |
Vanger | 0:47bc9ce390cc | 22 | */ |
Vanger | 0:47bc9ce390cc | 23 | //MTSSerialFlowControl* io = new MTSSerialFlowControl(D2, D9, D3, D6); |
Vanger | 0:47bc9ce390cc | 24 | |
Vanger | 0:47bc9ce390cc | 25 | /** Freescale KL64F |
Vanger | 0:47bc9ce390cc | 26 | * To configure the pins for the Freescale KL46Z board, use configuration A |
Vanger | 3:f22ad66e049e | 27 | * for the SocketModem. |
Vanger | 0:47bc9ce390cc | 28 | * Uncomment te following line to use the Freescale KL46F board |
Vanger | 0:47bc9ce390cc | 29 | */ |
Vanger | 0:47bc9ce390cc | 30 | //MTSSerialFlowControl* io = new MTSSerialFlowControl(D1, D0, D3, D6); |
Vanger | 0:47bc9ce390cc | 31 | |
Vanger | 0:47bc9ce390cc | 32 | //Sets the baudrate for communicating with the radio |
Vanger | 1:4c54ec0a3a20 | 33 | io->baud(115200); |
Vanger | 0:47bc9ce390cc | 34 | |
Vanger | 0:47bc9ce390cc | 35 | Cellular* radio = CellularFactory::create(io); |
Vanger | 1:4c54ec0a3a20 | 36 | for (int i = 0; i < 10; i++) { |
Vanger | 1:4c54ec0a3a20 | 37 | if (i >= 10) { |
Vanger | 3:f22ad66e049e | 38 | logError("Failed to set APN"); |
Vanger | 1:4c54ec0a3a20 | 39 | } |
Vanger | 1:4c54ec0a3a20 | 40 | if (radio->setApn(APN) == MTS_SUCCESS) { |
Vanger | 3:f22ad66e049e | 41 | logInfo("Successfully set APN [%s]", APN); |
Vanger | 1:4c54ec0a3a20 | 42 | break; |
Vanger | 1:4c54ec0a3a20 | 43 | } else { |
Vanger | 1:4c54ec0a3a20 | 44 | wait(1); |
Vanger | 1:4c54ec0a3a20 | 45 | } |
Vanger | 1:4c54ec0a3a20 | 46 | } |
Vanger | 0:47bc9ce390cc | 47 | |
Vanger | 0:47bc9ce390cc | 48 | //Establish PPP link |
Vanger | 1:4c54ec0a3a20 | 49 | for (int i = 0; i < 10; i++) { |
Vanger | 1:4c54ec0a3a20 | 50 | if (i >= 10) { |
Vanger | 3:f22ad66e049e | 51 | logError("Failed to connect to cell network"); |
Vanger | 1:4c54ec0a3a20 | 52 | } |
Vanger | 1:4c54ec0a3a20 | 53 | if (radio->connect() == true) { |
Vanger | 3:f22ad66e049e | 54 | logInfo("Successfully established PPP link"); |
Vanger | 1:4c54ec0a3a20 | 55 | break; |
Vanger | 1:4c54ec0a3a20 | 56 | } else { |
Vanger | 1:4c54ec0a3a20 | 57 | wait(1); |
Vanger | 1:4c54ec0a3a20 | 58 | } |
Vanger | 1:4c54ec0a3a20 | 59 | } |
Vanger | 0:47bc9ce390cc | 60 | |
Vanger | 1:4c54ec0a3a20 | 61 | //Ping google.com |
Vanger | 1:4c54ec0a3a20 | 62 | for (int i = 0; i < 10; i++) { |
Vanger | 1:4c54ec0a3a20 | 63 | if (i >= 10) { |
Vanger | 3:f22ad66e049e | 64 | logError("Failed to ping google.com"); |
Vanger | 1:4c54ec0a3a20 | 65 | } |
Vanger | 3:f22ad66e049e | 66 | if (radio->ping("www.google.com") == true) { |
Vanger | 3:f22ad66e049e | 67 | logInfo("Successfully pinged google.com"); |
Vanger | 1:4c54ec0a3a20 | 68 | break; |
Vanger | 1:4c54ec0a3a20 | 69 | } else { |
Vanger | 1:4c54ec0a3a20 | 70 | wait(1); |
Vanger | 1:4c54ec0a3a20 | 71 | } |
Vanger | 1:4c54ec0a3a20 | 72 | } |
Vanger | 0:47bc9ce390cc | 73 | |
Vanger | 0:47bc9ce390cc | 74 | //Disconnect ppp link |
Vanger | 0:47bc9ce390cc | 75 | radio->disconnect(); |
Vanger | 0:47bc9ce390cc | 76 | |
Vanger | 3:f22ad66e049e | 77 | logInfo("End of example code"); |
Vanger | 0:47bc9ce390cc | 78 | return 0; |
Vanger | 0:47bc9ce390cc | 79 | } |