Example program for MTS Universal Socked Modem Shield. Test that you can connect to a network.

Dependencies:   SocketModem mbed

Committer:
jengbrecht
Date:
Wed Jan 22 23:20:50 2014 +0000
Revision:
6:54b72ffdac62
Parent:
5:6950fcac0abd
Updated SocketModem library version.

Who changed what in which revision?

UserRevisionLine numberNew 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 //Setup serial interface to radio
sam_grove 0:a21f66715fc0 16 MTSSerialFlowControl* serial = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8);
sam_grove 0:a21f66715fc0 17 serial->baud(115200);
sam_grove 0:a21f66715fc0 18
sam_grove 0:a21f66715fc0 19 //Setup Cellular class
sam_grove 0:a21f66715fc0 20 Cellular* cellular = Cellular::getInstance();
sam_grove 0:a21f66715fc0 21 cellular->init(serial, PTA4, PTC9); //DCD and DTR pins for KL46Z
sam_grove 0:a21f66715fc0 22
sam_grove 0:a21f66715fc0 23 //Run status and configuration commands
sam_grove 0:a21f66715fc0 24 printf("\n\r////Start Status and Configuration Commands////\n\r");
jengbrecht 1:bc4801701acb 25 printf("Command Test: %s\n\r", getCodeNames(cellular->test()).c_str()); //Make sure you can talk to the radio
jengbrecht 1:bc4801701acb 26 printf("Signal Strength: %d\n\r", cellular->getSignalStrength()); //Check the signal strength should be above 8
jengbrecht 1:bc4801701acb 27
jengbrecht 1:bc4801701acb 28 //Makes sure you are reistered with cell
jengbrecht 1:bc4801701acb 29 printf("Registration State: %s\n\r", Cellular::getRegistrationNames(cellular->getRegistration()).c_str());
jengbrecht 1:bc4801701acb 30
jengbrecht 1:bc4801701acb 31 //Shows example of how to send other commands, look at AT command guide for more info
sam_grove 0:a21f66715fc0 32 printf("Send Basic Command (AT): %s\n\r", getCodeNames(cellular->sendBasicCommand("AT", 1000)).c_str());
sam_grove 0:a21f66715fc0 33 printf("Send Command (AT+CSQ): %s\n\r", cellular->sendCommand("AT+CSQ", 1000).c_str());
sam_grove 0:a21f66715fc0 34
sam_grove 0:a21f66715fc0 35 //Start Test
sam_grove 0:a21f66715fc0 36 printf("\n\r////Start Network Connectivity Test////\n\r");
sam_grove 0:a21f66715fc0 37 printf("Set APN: %s\n\r", getCodeNames(cellular->setApn("wap.cingular")).c_str()); //Use APN from service provider!!!
sam_grove 0:a21f66715fc0 38
sam_grove 0:a21f66715fc0 39 //Setup a data connection
sam_grove 0:a21f66715fc0 40 printf("Attempting to Connect, this may take some time...\n\r");
sam_grove 0:a21f66715fc0 41 while (!cellular->connect()) {
sam_grove 0:a21f66715fc0 42 printf("Failed to connect... Trying again.\n\r");
sam_grove 0:a21f66715fc0 43 wait(1);
sam_grove 0:a21f66715fc0 44 }
sam_grove 0:a21f66715fc0 45 printf("Connected to the Network!\n\r");
sam_grove 0:a21f66715fc0 46
jengbrecht 1:bc4801701acb 47 //Try pinging default server "8.8.8.8" (Google's DNS)
mfiore 3:ad2245759407 48 while (true) {
mfiore 3:ad2245759407 49 printf("Ping Valid: %s\n\r", cellular->ping() ? "true" : "false");
mfiore 3:ad2245759407 50 wait(3);
mfiore 3:ad2245759407 51 }
sam_grove 0:a21f66715fc0 52 }