From 23a467356584911a98bd1101542e008a02d8e2dc Mon Sep 17 00:00:00 2001 From: Stuart Feichtinger Date: Sun, 31 Jan 2016 17:24:00 -0600 Subject: [PATCH] Documented payload --- .../mqtt_arbitrary_buffer.ino | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/examples/mqtt_arbitrary_buffer/mqtt_arbitrary_buffer.ino b/examples/mqtt_arbitrary_buffer/mqtt_arbitrary_buffer.ino index 3186b25..ac2d08e 100644 --- a/examples/mqtt_arbitrary_buffer/mqtt_arbitrary_buffer.ino +++ b/examples/mqtt_arbitrary_buffer/mqtt_arbitrary_buffer.ino @@ -58,6 +58,23 @@ Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, PHOTOCELL_FEED); const char ONOFF_FEED[] PROGMEM = AIO_USERNAME "/feeds/onoff"; Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED); + +// Arbitrary Payload +// Union allows for easier interaction of members in struct form with easy publishing +// of "raw" bytes +typedef union{ + + struct __attribute__((__packed__)){ // packed to eliminate padding for easier parsing. + char charAry[10]; + int16_t val1; + unsigned long val2; + uint16_t val3; + }s; + + uint8_t raw[sizeof(s)]; // For publishing + +} packet_t; + /*************************** Sketch Code ************************************/ // Bug workaround for Arduino 1.6.6, it seems to need a function declaration