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

Dependencies:   SocketModem mbed

Committer:
sam_grove
Date:
Sat Jan 04 04:23:09 2014 +0000
Revision:
0:a21f66715fc0
Child:
1:bc4801701acb
Initial commit

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
sam_grove 0:a21f66715fc0 5 using namespace mts;
sam_grove 0:a21f66715fc0 6
sam_grove 0:a21f66715fc0 7 main()
sam_grove 0:a21f66715fc0 8 {
sam_grove 0:a21f66715fc0 9 //Wait for radio to boot up
sam_grove 0:a21f66715fc0 10 for (int i = 30; i >= 0; i = i - 5) {
sam_grove 0:a21f66715fc0 11 wait(5);
sam_grove 0:a21f66715fc0 12 printf("Waiting %d seconds...\n\r", i);
sam_grove 0:a21f66715fc0 13 }
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");
sam_grove 0:a21f66715fc0 25 printf("Command Test: %s\n\r", getCodeNames(cellular->test()).c_str());
sam_grove 0:a21f66715fc0 26 printf("Signal Strength: %d\n\r", cellular->getSignalStrength());
sam_grove 0:a21f66715fc0 27 printf("Registration State: %s\n\r", Cellular::getRegistrationNames(cellular->getRegistration()).c_str());
sam_grove 0:a21f66715fc0 28 printf("Send Basic Command (AT): %s\n\r", getCodeNames(cellular->sendBasicCommand("AT", 1000)).c_str());
sam_grove 0:a21f66715fc0 29 printf("Send Command (AT+CSQ): %s\n\r", cellular->sendCommand("AT+CSQ", 1000).c_str());
sam_grove 0:a21f66715fc0 30
sam_grove 0:a21f66715fc0 31 //Start Test
sam_grove 0:a21f66715fc0 32 printf("\n\r////Start Network Connectivity Test////\n\r");
sam_grove 0:a21f66715fc0 33 printf("Set APN: %s\n\r", getCodeNames(cellular->setApn("wap.cingular")).c_str()); //Use APN from service provider!!!
sam_grove 0:a21f66715fc0 34
sam_grove 0:a21f66715fc0 35 //Setup a data connection
sam_grove 0:a21f66715fc0 36 printf("Attempting to Connect, this may take some time...\n\r");
sam_grove 0:a21f66715fc0 37 while (!cellular->connect()) {
sam_grove 0:a21f66715fc0 38 printf("Failed to connect... Trying again.\n\r");
sam_grove 0:a21f66715fc0 39 wait(1);
sam_grove 0:a21f66715fc0 40 }
sam_grove 0:a21f66715fc0 41 printf("Connected to the Network!\n\r");
sam_grove 0:a21f66715fc0 42
sam_grove 0:a21f66715fc0 43 //Try pinging default server "8.8.8.8"
sam_grove 0:a21f66715fc0 44 printf("Ping Valid: %s\n\r", cellular->ping() ? "true" : "false");
sam_grove 0:a21f66715fc0 45
sam_grove 0:a21f66715fc0 46 printf("End Program\n\r");
sam_grove 0:a21f66715fc0 47
sam_grove 0:a21f66715fc0 48 while(1);
sam_grove 0:a21f66715fc0 49 }