Connecting a Multi-Tech Systems Dragonfly™ to Twilio's Sync for IoT Quickstart. Blink a dev board LED.

Dependencies:   MQTT MbedJSONValue mbed mtsas

Fork of DragonflyMQTT by miao zhicheng

Code to connect a Multi-Tech® MultiConnect® Dragonfly™ to Twilio's Sync for IoT: https://www.twilio.com/docs/api/devices

Uses MQTT over TLS and subscribes to a topic where you can control an LED. See also our Quickstart using this code, here: https://www.twilio.com/docs/quickstart/sync-iot/mqtt-multi-tech-multiconnect-dragonfly-sync-iot

MTSCellularManager.cpp

Committer:
miaotwilio
Date:
2017-05-09
Revision:
0:b32fa0c757d7
Child:
1:5a896191c3c4

File content as of revision 0:b32fa0c757d7:

#include "MTSCellularManager.hpp"

MTSCellularManager::MTSCellularManager(const char* apn_) : apn(apn_), io(NULL), radio(NULL) {
}

MTSCellularManager::~MTSCellularManager() {
    delete radio;
    delete io;
}

bool MTSCellularManager::init() {
    logInfo("initializing cellular radio");

    io = new mts::MTSSerialFlowControl(RADIO_TX, RADIO_RX, RADIO_RTS, RADIO_CTS);
    // radio default baud rate is 115200
    io->baud(115200);
    if (! io)
        return false;
    
    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);

    logInfo("setting APN");
    if (radio->setApn(apn) != MTS_SUCCESS) {
        logError("failed to set APN to \"%s\"", apn);
        return false;
    }

    logInfo("bringing up the link");
    if (! radio->connect()) {
        logError("failed to bring up the link");
        return false;
    } else {
        return true;
    }
}

void MTSCellularManager::uninit() {
    logInfo("finished - bringing down link");
    radio->disconnect();
    delete radio;
    delete io;
}