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
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
Diff: MTSCellularManager.cpp
- Revision:
- 1:5a896191c3c4
- Parent:
- 0:b32fa0c757d7
- Child:
- 3:0a48c984e15b
--- a/MTSCellularManager.cpp Tue May 09 13:16:48 2017 +0000 +++ b/MTSCellularManager.cpp Fri May 12 11:49:58 2017 +0000 @@ -44,4 +44,72 @@ radio->disconnect(); delete radio; delete io; -} \ No newline at end of file +} + +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(); + /*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";*/ + 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; +}