Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MQTT MbedJSONValue mbed mtsas
Fork of DragonflyMQTT by
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 |
--- 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;
+ }
+ */
}
