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
Revision 10:e9abab84df23, committed 2017-09-19
- Comitter:
- pkamp
- Date:
- Tue Sep 19 21:45:19 2017 +0000
- Parent:
- 9:2d119fbe7482
- Commit message:
- Adding publishing
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 2d119fbe7482 -r e9abab84df23 main.cpp --- a/main.cpp Fri Sep 15 22:41:22 2017 +0000 +++ b/main.cpp Tue Sep 19 21:45:19 2017 +0000 @@ -16,7 +16,7 @@ char* sync_key = "KYXXXXXXXXXXXXXXXXXXXX"; char* sync_password = "SECRET_HERE"; char* sync_document = "sync/docs/BoardLED"; -char* sync_device_name = "MST Dragonfly"; +char* sync_device_name = "MultiConnect Dragonfly"; /* Sync server and MQTT setup; you probably don't have to change these. */ const char* mqtt_server = "mqtt-sync.us1.twilio.com"; @@ -50,7 +50,7 @@ /* The parser will segfault and reset the board if "led" isn't contained. */ if (parser.hasMember("led")) { std::string led_str; - led_str = parser["led"][0].get<std::string>(); + led_str = parser["led"].get<std::string>(); if (led_str.compare("ON") == 0) { logDebug("Turning LED ON"); @@ -105,6 +105,26 @@ wait(MQTT_HEARTBEAT*10); connect_mqtt(); } + + // Here's an example of publishing from the MultiConnect Dragonfly. + // Uncomment until the end of the function to send a 'msg' back to Sync + // every 5 cycles through the loop! (5*MQTT_HEARTBEAT seconds) + /* + static uint32_t ticks = 0; + MQTT::Message message; + char buf[maxMQTTpackageSize] = "{\"msg\":\"Ahoy!\",\"led\":\"ON\"}"; + message.qos = MQTT::QOS1; + message.payload = (void*)buf; + message.payloadlen = strlen(buf) + 1; + if (ticks++ > 4) { + logInfo("Sending ON message to Twilio!"); + client.publish( + sync_document, + message + ); + ticks = 0; + } + */ }