An AirVantage layer for MQTT

Dependencies:   niMQTT picojson

Dependents:   AV_MQTT_example

Committer:
Nim65s
Date:
Fri Aug 09 12:13:54 2013 +0000
Revision:
1:7f1a11a70a2b
Parent:
0:37b9835622f9
Child:
6:b251f6276497
Sub is useless

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Nim65s 0:37b9835622f9 1 #include "AV_MQTT.h"
Nim65s 0:37b9835622f9 2
Nim65s 0:37b9835622f9 3 AV_MQTT::AV_MQTT(char *server, void (*callback)(char *, char*), char *username, char *password, char *id, int port, bool debug):
Nim65s 0:37b9835622f9 4 client(server, callback, id, port, username, password, debug), debug(debug) {
Nim65s 0:37b9835622f9 5 topic = new char[strlen(username) + 15];
Nim65s 0:37b9835622f9 6 strcpy(topic, username);
Nim65s 0:37b9835622f9 7 strcat(topic, "/messages/json");
Nim65s 0:37b9835622f9 8 }
Nim65s 0:37b9835622f9 9
Nim65s 0:37b9835622f9 10 void AV_MQTT::pub(char *key, char *value) {
Nim65s 0:37b9835622f9 11 int key_length = strlen(key);
Nim65s 0:37b9835622f9 12 int value_length = strlen(value);
Nim65s 0:37b9835622f9 13 char json[key_length + value_length + 36];
Nim65s 0:37b9835622f9 14 strcpy(json, "[{\"");
Nim65s 0:37b9835622f9 15 strcat(json, key);
Nim65s 0:37b9835622f9 16 strcat(json, "\":[{\"timestamp\":null,\"value\":");
Nim65s 0:37b9835622f9 17 strcat(json, value);
Nim65s 0:37b9835622f9 18 strcat(json, "}]}]");
Nim65s 0:37b9835622f9 19 client.pub(topic, json);
Nim65s 0:37b9835622f9 20 }