Example program for MTS Universal Socked Modem Shield. Test that you can connect to a network.
Dependencies: SocketModem mbed
main.cpp@2:76a4d7e86a3c, 2014-01-04 (annotated)
- Committer:
- jengbrecht
- Date:
- Sat Jan 04 20:30:06 2014 +0000
- Revision:
- 2:76a4d7e86a3c
- Parent:
- 1:bc4801701acb
- Child:
- 3:ad2245759407
Added while(1) at the end...
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sam_grove | 0:a21f66715fc0 | 1 | #include "mbed.h" |
sam_grove | 0:a21f66715fc0 | 2 | #include "Cellular.h" |
sam_grove | 0:a21f66715fc0 | 3 | #include "MTSSerialFlowControl.h" |
sam_grove | 0:a21f66715fc0 | 4 | |
jengbrecht | 1:bc4801701acb | 5 | /* This example can be used to check basic network |
jengbrecht | 1:bc4801701acb | 6 | * connectivity on the cellular network using the |
jengbrecht | 1:bc4801701acb | 7 | * MTS SocketModem shield. The test connects to the |
jengbrecht | 1:bc4801701acb | 8 | * network and performs a ping test to Google's DNS. |
jengbrecht | 1:bc4801701acb | 9 | */ |
jengbrecht | 1:bc4801701acb | 10 | |
sam_grove | 0:a21f66715fc0 | 11 | using namespace mts; |
sam_grove | 0:a21f66715fc0 | 12 | |
sam_grove | 0:a21f66715fc0 | 13 | main() |
sam_grove | 0:a21f66715fc0 | 14 | { |
sam_grove | 0:a21f66715fc0 | 15 | //Wait for radio to boot up |
sam_grove | 0:a21f66715fc0 | 16 | for (int i = 30; i >= 0; i = i - 5) { |
sam_grove | 0:a21f66715fc0 | 17 | wait(5); |
sam_grove | 0:a21f66715fc0 | 18 | printf("Waiting %d seconds...\n\r", i); |
sam_grove | 0:a21f66715fc0 | 19 | } |
sam_grove | 0:a21f66715fc0 | 20 | |
sam_grove | 0:a21f66715fc0 | 21 | //Setup serial interface to radio |
sam_grove | 0:a21f66715fc0 | 22 | MTSSerialFlowControl* serial = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8); |
sam_grove | 0:a21f66715fc0 | 23 | serial->baud(115200); |
sam_grove | 0:a21f66715fc0 | 24 | |
sam_grove | 0:a21f66715fc0 | 25 | //Setup Cellular class |
sam_grove | 0:a21f66715fc0 | 26 | Cellular* cellular = Cellular::getInstance(); |
sam_grove | 0:a21f66715fc0 | 27 | cellular->init(serial, PTA4, PTC9); //DCD and DTR pins for KL46Z |
sam_grove | 0:a21f66715fc0 | 28 | |
sam_grove | 0:a21f66715fc0 | 29 | //Run status and configuration commands |
sam_grove | 0:a21f66715fc0 | 30 | printf("\n\r////Start Status and Configuration Commands////\n\r"); |
jengbrecht | 1:bc4801701acb | 31 | printf("Command Test: %s\n\r", getCodeNames(cellular->test()).c_str()); //Make sure you can talk to the radio |
jengbrecht | 1:bc4801701acb | 32 | printf("Signal Strength: %d\n\r", cellular->getSignalStrength()); //Check the signal strength should be above 8 |
jengbrecht | 1:bc4801701acb | 33 | |
jengbrecht | 1:bc4801701acb | 34 | //Makes sure you are reistered with cell |
jengbrecht | 1:bc4801701acb | 35 | printf("Registration State: %s\n\r", Cellular::getRegistrationNames(cellular->getRegistration()).c_str()); |
jengbrecht | 1:bc4801701acb | 36 | |
jengbrecht | 1:bc4801701acb | 37 | //Shows example of how to send other commands, look at AT command guide for more info |
sam_grove | 0:a21f66715fc0 | 38 | printf("Send Basic Command (AT): %s\n\r", getCodeNames(cellular->sendBasicCommand("AT", 1000)).c_str()); |
sam_grove | 0:a21f66715fc0 | 39 | printf("Send Command (AT+CSQ): %s\n\r", cellular->sendCommand("AT+CSQ", 1000).c_str()); |
sam_grove | 0:a21f66715fc0 | 40 | |
sam_grove | 0:a21f66715fc0 | 41 | //Start Test |
sam_grove | 0:a21f66715fc0 | 42 | printf("\n\r////Start Network Connectivity Test////\n\r"); |
sam_grove | 0:a21f66715fc0 | 43 | printf("Set APN: %s\n\r", getCodeNames(cellular->setApn("wap.cingular")).c_str()); //Use APN from service provider!!! |
sam_grove | 0:a21f66715fc0 | 44 | |
sam_grove | 0:a21f66715fc0 | 45 | //Setup a data connection |
sam_grove | 0:a21f66715fc0 | 46 | printf("Attempting to Connect, this may take some time...\n\r"); |
sam_grove | 0:a21f66715fc0 | 47 | while (!cellular->connect()) { |
sam_grove | 0:a21f66715fc0 | 48 | printf("Failed to connect... Trying again.\n\r"); |
sam_grove | 0:a21f66715fc0 | 49 | wait(1); |
sam_grove | 0:a21f66715fc0 | 50 | } |
sam_grove | 0:a21f66715fc0 | 51 | printf("Connected to the Network!\n\r"); |
sam_grove | 0:a21f66715fc0 | 52 | |
jengbrecht | 1:bc4801701acb | 53 | //Try pinging default server "8.8.8.8" (Google's DNS) |
sam_grove | 0:a21f66715fc0 | 54 | printf("Ping Valid: %s\n\r", cellular->ping() ? "true" : "false"); |
sam_grove | 0:a21f66715fc0 | 55 | |
sam_grove | 0:a21f66715fc0 | 56 | printf("End Program\n\r"); |
jengbrecht | 2:76a4d7e86a3c | 57 | while(1); |
sam_grove | 0:a21f66715fc0 | 58 | } |