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@0:47bc9ce390cc, 2014-07-24 (annotated)
- Committer:
- Vanger
- Date:
- Thu Jul 24 18:56:55 2014 +0000
- Revision:
- 0:47bc9ce390cc
- Child:
- 1:4c54ec0a3a20
Tests device connectivity with a simple ping command after connecting to the cell network, then it disconnects.
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 | 0:47bc9ce390cc | 6 | const char APN[] = ""; |
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 | 0:47bc9ce390cc | 20 | * for the SocketModem. The TX pin should be jumped to pin D2 (JP8), and the |
Vanger | 0:47bc9ce390cc | 21 | * RX pin should be jumped to pin D9 (JP9). |
Vanger | 0:47bc9ce390cc | 22 | * Uncomment te following line to use the Freescale KL46Z board |
Vanger | 0:47bc9ce390cc | 23 | */ |
Vanger | 0:47bc9ce390cc | 24 | //MTSSerialFlowControl* io = new MTSSerialFlowControl(D2, D9, D3, D6); |
Vanger | 0:47bc9ce390cc | 25 | |
Vanger | 0:47bc9ce390cc | 26 | /** Freescale KL64F |
Vanger | 0:47bc9ce390cc | 27 | * To configure the pins for the Freescale KL46Z board, use configuration A |
Vanger | 0:47bc9ce390cc | 28 | * for the SocketModem. The TX pin should be jumped to pin D1 (JP8), and the |
Vanger | 0:47bc9ce390cc | 29 | * RX pin should be jumped to pin D0 (JP9). |
Vanger | 0:47bc9ce390cc | 30 | * Uncomment te 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 | 0:47bc9ce390cc | 34 | //Sets the baudrate for communicating with the radio |
Vanger | 0:47bc9ce390cc | 35 | io->baud(115200); |
Vanger | 0:47bc9ce390cc | 36 | |
Vanger | 0:47bc9ce390cc | 37 | Cellular* radio = CellularFactory::create(io); |
Vanger | 0:47bc9ce390cc | 38 | radio->setApn(APN); |
Vanger | 0:47bc9ce390cc | 39 | |
Vanger | 0:47bc9ce390cc | 40 | //Establish PPP link |
Vanger | 0:47bc9ce390cc | 41 | radio->connect(); |
Vanger | 0:47bc9ce390cc | 42 | |
Vanger | 0:47bc9ce390cc | 43 | printf("Ping was %s\n", radio->ping() ? "successful" : "unsuccessful"); |
Vanger | 0:47bc9ce390cc | 44 | |
Vanger | 0:47bc9ce390cc | 45 | //Disconnect ppp link |
Vanger | 0:47bc9ce390cc | 46 | radio->disconnect(); |
Vanger | 0:47bc9ce390cc | 47 | |
Vanger | 0:47bc9ce390cc | 48 | printf("End of example code\n"); |
Vanger | 0:47bc9ce390cc | 49 | return 0; |
Vanger | 0:47bc9ce390cc | 50 | } |