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

Revision:
9:2d119fbe7482
Parent:
6:4a25f3b9caef
--- a/MTSCellularManager.cpp	Thu Sep 14 08:14:18 2017 +0000
+++ b/MTSCellularManager.cpp	Fri Sep 15 22:41:22 2017 +0000
@@ -1,7 +1,12 @@
 #include "MTSCellularManager.hpp"
 
-MTSCellularManager::MTSCellularManager(const char* apn_) : apn(apn_), io(NULL), radio(NULL) {
-}
+MTSCellularManager::MTSCellularManager(
+    const char* apn_
+) :     apn(apn_), 
+        io(NULL), 
+        radio(NULL) 
+{}
+
 
 MTSCellularManager::~MTSCellularManager() {
     delete radio;
@@ -9,10 +14,16 @@
 }
 
 bool MTSCellularManager::init() {
-    logInfo("initializing cellular radio");
+    logInfo("Initializing Cellular Radio");
 
-    io = new mts::MTSSerialFlowControl(RADIO_TX, RADIO_RX, RADIO_RTS, RADIO_CTS);
-    // radio default baud rate is 115200
+    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;
@@ -22,7 +33,10 @@
     if (! radio)
         return false;
     
-    // Transport must be set properly before any TCPSocketConnection or UDPSocket objects are created
+    /* 
+     * Transport must be set properly before any TCPSocketConnection or 
+     * UDPSocket objects are created
+     */
     Transport::setTransport(radio);
 
     logInfo("setting APN");
@@ -45,78 +59,4 @@
     radio->disconnect();
     delete radio;
     delete io;
-}
-
-void MTSCellularManager::enableGps() {
-
-    if( !radio->GPSenabled() ) {
-        logInfo("GPS: enabling");
-        radio->GPSenable();
-        while( !radio->GPSenabled() ) {
-            logInfo("...");
-            wait(5);
-        }
-        logInfo("GPS enabled");
-    }
-}
-
-MTSCellularManager::GPSStatus MTSCellularManager::gpsPollStatus() {
-    GPSStatus status;
-
-    int i;
-    char c;
-    
-    if( !radio->GPSenabled() ) {
-        logInfo("GPS: enabling");
-        radio->GPSenable();
-        while( !radio->GPSenabled() ) {
-            logInfo("...");
-            wait(5);
-        }
-    }
-
-
-    logInfo("GPS polling");
-    mts::Cellular::gpsData gpsValues = radio->GPSgetPosition();
-
-    // mocked data
-    /*
-    gpsValues.success = true;
-    gpsValues.fix = 3;
-    gpsValues.satellites = 4;
-    gpsValues.timestamp = "17/05/12, 08:59:56.483";
-    gpsValues.latitude = "5925.4477N";
-    gpsValues.longitude = "02444.9046E";
-    gpsValues.kmhr = "40";
-    */
-
-    if (gpsValues.success && gpsValues.fix > 2) {
-        logInfo("GPS polled: success %d, sats: %d, fix: %d, ts %s, lat %s, lng %s",
-            gpsValues.success, gpsValues.satellites, gpsValues.fix, gpsValues.timestamp.c_str(), gpsValues.latitude.c_str(), gpsValues.longitude.c_str());
-        status.success = gpsValues.success;
-        status.fix = gpsValues.fix;
-        status.speedVal = gpsValues.kmhr / 0.621371f;
-        status.latitudeVal = .0;
-        status.longitudeVal = .0;
-        sscanf(gpsValues.latitude.substr(0, gpsValues.latitude.size()-1).c_str(), "%02d%lf", &i, &status.latitudeVal);
-        c = gpsValues.latitude.c_str()[gpsValues.latitude.size()-1];
-        //logInfo("i=%d,lat=%f,c=%c", i, latitudeVal ,c);
-        status.latitudeVal /= 60.0;
-        status.latitudeVal += i;
-        if(c == 'S')
-            status.latitudeVal = 0.0 - status.latitudeVal;
-        sscanf(gpsValues.longitude.substr(0, gpsValues.longitude.size()-1).c_str(), "%03d%lf", &i, &status.longitudeVal);
-        c = gpsValues.longitude.c_str()[gpsValues.longitude.size()-1];
-        //logInfo("i=%d,lon=%f,c=%c", i, status.longitudeVal, c);
-        status.longitudeVal /= 60.0;
-        status.longitudeVal += i;
-        if(c == 'W')
-            status.longitudeVal = 0.0 - status.longitudeVal;
-    } else {
-        status.success = false;
-        logInfo("GPS polled failed: success %d, sats: %d, fix: %d",
-            gpsValues.success, gpsValues.satellites, gpsValues.fix);
-    }
-
-    return status;
-}
+}
\ No newline at end of file