An AirVantage layer for MQTT

Dependencies:   niMQTT picojson

Dependents:   AV_MQTT_example

Revision:
0:37b9835622f9
Child:
1:7f1a11a70a2b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AV_MQTT.cpp	Thu Aug 08 16:08:18 2013 +0000
@@ -0,0 +1,23 @@
+#include "AV_MQTT.h"
+
+AV_MQTT::AV_MQTT(char *server, void (*callback)(char *, char*), char *username, char *password,  char *id, int port, bool debug):
+    client(server, callback, id, port, username, password, debug), debug(debug) {
+    topic = new char[strlen(username) + 15];
+    strcpy(topic, username);
+    strcat(topic, "/messages/json");
+    printf(topic);
+    client.sub(topic);
+}
+
+void AV_MQTT::pub(char *key, char *value) {
+    int key_length = strlen(key);
+    int value_length = strlen(value);
+    char json[key_length + value_length + 36];
+    strcpy(json, "[{\"");
+    strcat(json, key);
+    strcat(json, "\":[{\"timestamp\":null,\"value\":");
+    strcat(json, value);
+    strcat(json, "}]}]");
+    printf(json);
+    client.pub(topic, json);
+}
\ No newline at end of file