Example program demonstrating proper powering down of Telit radio and putting the processor into STOP mode.

Dependencies:   WakeUp mbed mtsas SpiFlash25

Fork of Dragonfly_Cellular_Ping_Example by MultiTech

Committer:
mfiore
Date:
Wed Sep 30 14:39:45 2015 +0000
Revision:
0:da114ae7c596
Child:
1:1411b4274907
initial commit - just set APN

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mfiore 0:da114ae7c596 1 /** Dragonfly Cellular Ping Example
mfiore 0:da114ae7c596 2 * Configures the cellular radio, brings up the cellular link, and pings Google.
mfiore 0:da114ae7c596 3 *
mfiore 0:da114ae7c596 4 * NOTE: This example changes the baud rate of the debug port to 115200 baud!
mfiore 0:da114ae7c596 5 */
mfiore 0:da114ae7c596 6
mfiore 0:da114ae7c596 7 #include "mbed.h"
mfiore 0:da114ae7c596 8 #include "mtsas.h"
mfiore 0:da114ae7c596 9
mfiore 0:da114ae7c596 10 bool init_mtsas();
mfiore 0:da114ae7c596 11
mfiore 0:da114ae7c596 12 // the MTSSerialFlowControl represents the physical serial link between the processor and the cellular radio
mfiore 0:da114ae7c596 13 mts::MTSSerialFlowControl* io;
mfiore 0:da114ae7c596 14 // the Cellular object represents the cellular radio
mfiore 0:da114ae7c596 15 mts::Cellular* radio;
mfiore 0:da114ae7c596 16
mfiore 0:da114ae7c596 17 // an APN is required for GSM radios
mfiore 0:da114ae7c596 18 static const char apn[] = "";
mfiore 0:da114ae7c596 19
mfiore 0:da114ae7c596 20 bool radio_ok = false;
mfiore 0:da114ae7c596 21
mfiore 0:da114ae7c596 22 int main() {
mfiore 0:da114ae7c596 23 // change the baud rate of the debug port from the default 9600 to 115200
mfiore 0:da114ae7c596 24 Serial debug(USBTX, USBRX);
mfiore 0:da114ae7c596 25 debug.baud(115200);
mfiore 0:da114ae7c596 26
mfiore 0:da114ae7c596 27 //Sets the log level to INFO, higher log levels produce more log output.
mfiore 0:da114ae7c596 28 //Possible levels: NONE, FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
mfiore 0:da114ae7c596 29 mts::MTSLog::setLogLevel(mts::MTSLog::INFO_LEVEL);
mfiore 0:da114ae7c596 30
mfiore 0:da114ae7c596 31 logInfo("initializing cellular radio");
mfiore 0:da114ae7c596 32 radio_ok = init_mtsas();
mfiore 0:da114ae7c596 33 if (! radio_ok) {
mfiore 0:da114ae7c596 34 while (true) {
mfiore 0:da114ae7c596 35 logError("failed to initialize cellular radio");
mfiore 0:da114ae7c596 36 wait(1);
mfiore 0:da114ae7c596 37 }
mfiore 0:da114ae7c596 38 }
mfiore 0:da114ae7c596 39
mfiore 0:da114ae7c596 40 logInfo("setting APN");
mfiore 0:da114ae7c596 41 if (radio->setApn(apn) != MTS_SUCCESS)
mfiore 0:da114ae7c596 42 logError("failed to set APN to \"%s\"", apn);
mfiore 0:da114ae7c596 43
mfiore 0:da114ae7c596 44 logInfo("bringing up the link");
mfiore 0:da114ae7c596 45 if (! radio->connect()) {
mfiore 0:da114ae7c596 46 logError("failed to bring up the link");
mfiore 0:da114ae7c596 47 } else {
mfiore 0:da114ae7c596 48 for (int i = 0; i < 10; i++) {
mfiore 0:da114ae7c596 49 logInfo("pinging");
mfiore 0:da114ae7c596 50 if (! radio->ping("www.google.com"))
mfiore 0:da114ae7c596 51 logError("failed to ping");
mfiore 0:da114ae7c596 52 else
mfiore 0:da114ae7c596 53 logInfo("ping succeeded");
mfiore 0:da114ae7c596 54 }
mfiore 0:da114ae7c596 55 }
mfiore 0:da114ae7c596 56
mfiore 0:da114ae7c596 57 logInfo("finished - bringing down link");
mfiore 0:da114ae7c596 58 radio->disconnect();
mfiore 0:da114ae7c596 59
mfiore 0:da114ae7c596 60 return 0;
mfiore 0:da114ae7c596 61 }
mfiore 0:da114ae7c596 62
mfiore 0:da114ae7c596 63 bool init_mtsas() {
mfiore 0:da114ae7c596 64 io = new mts::MTSSerialFlowControl(RADIO_TX, RADIO_RX, RADIO_RTS, RADIO_CTS);
mfiore 0:da114ae7c596 65 if (! io)
mfiore 0:da114ae7c596 66 return false;
mfiore 0:da114ae7c596 67
mfiore 0:da114ae7c596 68 // radio default baud rate is 115200
mfiore 0:da114ae7c596 69 io->baud(115200);
mfiore 0:da114ae7c596 70 radio = mts::CellularFactory::create(io);
mfiore 0:da114ae7c596 71 if (! radio)
mfiore 0:da114ae7c596 72 return false;
mfiore 0:da114ae7c596 73
mfiore 0:da114ae7c596 74 // Transport must be set properly before any TCPSocketConnection or UDPSocket objects are created
mfiore 0:da114ae7c596 75 Transport::setTransport(radio);
mfiore 0:da114ae7c596 76
mfiore 0:da114ae7c596 77 return true;
mfiore 0:da114ae7c596 78 }