A wrapper class for talking to Axeda from MBED devices. Uses HTTPClient and MbedJSONValue classes.

Dependents:   axeda_wrapper_dev MTS_Axeda_Example

AxedaWrapper simplifies pushing data to Axeda's cloud.

Uses HTTPClient and MbedJSONValue libs:

http://mbed.org/users/donatien/code/HTTPClient/

http://mbed.org/users/samux/code/MbedJSONValue/

Revision:
1:d42aaf6f2e19
Parent:
0:d472df0659a9
Child:
2:99baa98f84a3
--- a/AxedaWrapper.cpp	Thu Dec 19 21:49:05 2013 +0000
+++ b/AxedaWrapper.cpp	Fri Dec 20 14:49:01 2013 +0000
@@ -1,4 +1,5 @@
 #include "AxedaWrapper.h"
+#include "HTTPJsonText.h"
 #include <string>
 #include <vector>
 #include <stdlib.h>
@@ -12,7 +13,7 @@
     _data = new MbedJSONValue();
     
     char buf[256];
-    std::string path = PATH_BASE + model + "/" + serial;
+    std::string path = PATH_BASE + model + "!" + serial;
     sprintf(buf, "http://%s:%d%s", host.c_str(), port, path.c_str());
     _url = std::string(buf);
 }
@@ -23,35 +24,35 @@
 }
 
 void AxedaWrapper::addKvp(const std::string& key, const std::string& value) {
-    (*_data)[key] = value;
+    (*_data)["data"][0]["di"][key] = value;
 }
 
 void AxedaWrapper::addKvp(const char* key, const char* value) {
-    (*_data)[std::string(key)] = value;
+    (*_data)["data"][0]["di"][std::string(key)] = value;
 }
 
 void AxedaWrapper::addKvp(const std::string& key, int value) {
-    (*_data)[key] = value;
+    (*_data)["data"][0]["di"][key] = value;
 }
 
 void AxedaWrapper::addKvp(const char* key, int value) {
-    (*_data)[std::string(key)] = value;
+    (*_data)["data"][0]["di"][std::string(key)] = value;
 }
 
 void AxedaWrapper::addKvp(const std::string& key, double value) {
-    (*_data)[key] = value;
+    (*_data)["data"][0]["di"][key] = value;
 }
 
 void AxedaWrapper::addKvp(const char* key, double value) {
-    (*_data)[std::string(key)] = value;
+    (*_data)["data"][0]["di"][std::string(key)] = value;
 }
 
 void AxedaWrapper::addKvp(const std::string& key, bool value) {
-    (*_data)[key] = value;
+    (*_data)["data"][0]["di"][key] = value;
 }
 
 void AxedaWrapper::addKvp(const char* key, bool value) {
-    (*_data)[std::string(key)] = value;
+    (*_data)["data"][0]["di"][std::string(key)] = value;
 }
 
 void AxedaWrapper::deleteAllKvp() {
@@ -65,57 +66,56 @@
 
 bool AxedaWrapper::sendKvp(const std::string& key, const std::string& value) {
     MbedJSONValue data;
-    data[key] = value;
-    return sendBase(data);
+    data["data"][0]["di"][key] = value;
+    return sendBase(data.serialize());
 }
 
 bool AxedaWrapper::sendKvp(const char* key, const char* value) {
     MbedJSONValue data;
-    data[key] = value;
-    return sendBase(data);
+    data["data"][0]["di"][key] = value;
+    return sendBase(data.serialize());
 }
 
 bool AxedaWrapper::sendKvp(const std::string& key, int value) {
     MbedJSONValue data;
-    data[key] = value;
-    return sendBase(data);
+    data["data"][0]["di"][key] = value;
+    return sendBase(data.serialize());
 }
 
 bool AxedaWrapper::sendKvp(const char* key, int value) {
     MbedJSONValue data;
-    data[key] = value;
-    return sendBase(data);
+    data["data"][0]["di"][key] = value;
+    return sendBase(data.serialize());
 }
 
 bool AxedaWrapper::sendKvp(const std::string& key, double value) {
     MbedJSONValue data;
-    data[key] = value;
-    return sendBase(data);
+    data["data"][0]["di"][key] = value;
+    return sendBase(data.serialize());
 }
 
 bool AxedaWrapper::sendKvp(const char* key, double value) {
     MbedJSONValue data;
-    data[key] = value;
-    return sendBase(data);
+    data["data"][0]["di"][key] = value;
+    return sendBase(data.serialize());
 }
 
 bool AxedaWrapper::sendAllKvp(bool clear) {
-    bool ret = sendBase(_data);
+    std::string data = _data->serialize();
+    bool ret = sendBase(data);
     if (ret && clear) {
         deleteAllKvp();
     }
     return ret;
 }
 
-bool AxedaWrapper::sendBase(MbedJSONValue data) {
+bool AxedaWrapper::sendBase(const std::string& data) {
     int ret;
     char buf[512] = {0};
-    HTTPMap map;
-    HTTPText text(buf, sizeof(buf));
-    std::string data_str = data.serialize();
+    HTTPJsonText to_send((char*) data.c_str());
+    HTTPText to_recv(buf, sizeof(buf));
     
-    map.put("data", data_str.c_str());
-    ret = _http_client->post(_url.c_str(), map, &text, _timeout);
+    ret = _http_client->post(_url.c_str(), to_send, &to_recv, _timeout);
     if (ret != HTTP_OK) {
         return false;
     }