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

main.cpp

Committer:
mfiore
Date:
2015-09-30
Revision:
0:da114ae7c596
Child:
1:1411b4274907

File content as of revision 0:da114ae7c596:

/** Dragonfly Cellular Ping Example
 * Configures the cellular radio, brings up the cellular link, and pings Google.
 *
 * NOTE: This example changes the baud rate of the debug port to 115200 baud!
 */

#include "mbed.h"
#include "mtsas.h"

bool init_mtsas();

// the MTSSerialFlowControl represents the physical serial link between the processor and the cellular radio
mts::MTSSerialFlowControl* io;
// the Cellular object represents the cellular radio
mts::Cellular* radio;

// an APN is required for GSM radios
static const char apn[] = "";

bool radio_ok = false;

int main() {
    // change the baud rate of the debug port from the default 9600 to 115200
    Serial debug(USBTX, USBRX);
    debug.baud(115200);
    
    //Sets the log level to INFO, higher log levels produce more log output.
    //Possible levels: NONE, FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
    mts::MTSLog::setLogLevel(mts::MTSLog::INFO_LEVEL);
    
    logInfo("initializing cellular radio");
    radio_ok = init_mtsas();
    if (! radio_ok) {
        while (true) {
            logError("failed to initialize cellular radio");
            wait(1);
        }
    }
    
    logInfo("setting APN");
    if (radio->setApn(apn) != MTS_SUCCESS)
        logError("failed to set APN to \"%s\"", apn);
        
    logInfo("bringing up the link");
    if (! radio->connect()) {
        logError("failed to bring up the link");
    } else {
        for (int i = 0; i < 10; i++) {
            logInfo("pinging");
            if (! radio->ping("www.google.com"))
                logError("failed to ping");
            else
                logInfo("ping succeeded");
        }
    }
    
    logInfo("finished - bringing down link");
    radio->disconnect();
    
    return 0;
}

bool init_mtsas() {
    io = new mts::MTSSerialFlowControl(RADIO_TX, RADIO_RX, RADIO_RTS, RADIO_CTS);
    if (! io)
        return false;
        
    // radio default baud rate is 115200
    io->baud(115200);
    radio = mts::CellularFactory::create(io);
    if (! radio)
        return false;
        
    // Transport must be set properly before any TCPSocketConnection or UDPSocket objects are created
    Transport::setTransport(radio);
    
    return true;
}