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/

Committer:
mfiore
Date:
Fri Dec 20 14:49:01 2013 +0000
Revision:
1:d42aaf6f2e19
Parent:
0:d472df0659a9
Child:
2:99baa98f84a3
pass std::string to sendBase() instead of MbedJSONValue object; add proper formatting of JSON objects to match what Axeda free backend expects; add HTTPJsonText.h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mfiore 0:d472df0659a9 1 #ifndef AXEDAWRAPPER_H
mfiore 0:d472df0659a9 2 #define AXEDAWRAPPER_H
mfiore 0:d472df0659a9 3
mfiore 0:d472df0659a9 4 #include "HTTPClient.h"
mfiore 0:d472df0659a9 5 #include "MbedJSONValue.h"
mfiore 0:d472df0659a9 6
mfiore 0:d472df0659a9 7 #define MAX_KVP 32
mfiore 0:d472df0659a9 8 namespace mts {
mfiore 0:d472df0659a9 9
mfiore 0:d472df0659a9 10 class AxedaWrapper {
mfiore 0:d472df0659a9 11 public:
mfiore 0:d472df0659a9 12 /** Constructor
mfiore 0:d472df0659a9 13 * Creates an AxedaWrapper object
mfiore 0:d472df0659a9 14 *
mfiore 0:d472df0659a9 15 * @param serial A made up serial number for your device. It needs to be unique!
mfiore 0:d472df0659a9 16 * A good format to use is <your initials>-<a random string of numbers>,
mfiore 0:d472df0659a9 17 * e.g. "JTA-862653"
mfiore 0:d472df0659a9 18 */
mfiore 0:d472df0659a9 19 AxedaWrapper(const std::string& serial, const std::string& model = "mbed", const std::string& host = "dev6-connect.axeda.com", int port = 52689);
mfiore 0:d472df0659a9 20
mfiore 0:d472df0659a9 21 /** Destructor
mfiore 0:d472df0659a9 22 * Deletes the AxedaWrapper object and returns all allocated memory
mfiore 0:d472df0659a9 23 */
mfiore 0:d472df0659a9 24 ~AxedaWrapper();
mfiore 0:d472df0659a9 25
mfiore 0:d472df0659a9 26 /** addKvp
mfiore 0:d472df0659a9 27 * Adds a key-value pair to the internal map.
mfiore 0:d472df0659a9 28 *
mfiore 0:d472df0659a9 29 * @param key The "name" of the value.
mfiore 0:d472df0659a9 30 * @param value The value to be stored.
mfiore 0:d472df0659a9 31 */
mfiore 0:d472df0659a9 32 void addKvp(const std::string& key, const std::string& value);
mfiore 0:d472df0659a9 33 void addKvp(const char* key, const char* value);
mfiore 0:d472df0659a9 34 void addKvp(const std::string& key, int value);
mfiore 0:d472df0659a9 35 void addKvp(const char* key, int value);
mfiore 0:d472df0659a9 36 void addKvp(const std::string& key, double value);
mfiore 0:d472df0659a9 37 void addKvp(const char* key, double value);
mfiore 0:d472df0659a9 38 void addKvp(const std::string& key, bool value);
mfiore 0:d472df0659a9 39 void addKvp(const char* key, bool value);
mfiore 0:d472df0659a9 40
mfiore 0:d472df0659a9 41 /** deleteAllKvp
mfiore 0:d472df0659a9 42 * Removes all key-value pairs from the internal map.
mfiore 0:d472df0659a9 43 * If the internal map is empty, no action is taken.
mfiore 0:d472df0659a9 44 */
mfiore 0:d472df0659a9 45 void deleteAllKvp();
mfiore 0:d472df0659a9 46
mfiore 0:d472df0659a9 47 /** kvpMapSize
mfiore 0:d472df0659a9 48 * @returns the current size of the map
mfiore 0:d472df0659a9 49 */
mfiore 0:d472df0659a9 50 int kvpMapSize();
mfiore 0:d472df0659a9 51
mfiore 0:d472df0659a9 52 /** sendKvp
mfiore 0:d472df0659a9 53 * Sends a key-value pair to the Axeda platform
mfiore 0:d472df0659a9 54 * Specifically for the versions which take a double:
mfiore 0:d472df0659a9 55 * - the double value is formatted into a 256 byte buffer
mfiore 0:d472df0659a9 56 * - if the length of the string version of the value is greater than 255 bytes,
mfiore 0:d472df0659a9 57 * it will be cut off at 255 bytes (to leave room for the '\0' character)
mfiore 0:d472df0659a9 58 *
mfiore 0:d472df0659a9 59 * @param key The "name" of the value.
mfiore 0:d472df0659a9 60 * @param value The value to be sent.
mfiore 0:d472df0659a9 61 * @return true if the value was sent successfully, false otherwise
mfiore 0:d472df0659a9 62 */
mfiore 0:d472df0659a9 63 bool sendKvp(const std::string& key, const std::string& value);
mfiore 0:d472df0659a9 64 bool sendKvp(const char* key, const char* value);
mfiore 0:d472df0659a9 65 bool sendKvp(const std::string& key, int value);
mfiore 0:d472df0659a9 66 bool sendKvp(const char* key, int value);
mfiore 0:d472df0659a9 67 bool sendKvp(const std::string& key, double value);
mfiore 0:d472df0659a9 68 bool sendKvp(const char* key, double value);
mfiore 0:d472df0659a9 69 bool sendKvp(const std::string& key, bool value);
mfiore 0:d472df0659a9 70 bool sendKvp(const char* key, bool value);
mfiore 0:d472df0659a9 71
mfiore 0:d472df0659a9 72 /** sendAllKvp
mfiore 0:d472df0659a9 73 * Sends all the key-value pairs in the internal map to the Axeda platform
mfiore 0:d472df0659a9 74 *
mfiore 0:d472df0659a9 75 * @param clear If true, clear the internal map if the send is successful,
mfiore 0:d472df0659a9 76 * if false, don't clear the internal map
mfiore 0:d472df0659a9 77 * @return true if successful, false otherwise
mfiore 0:d472df0659a9 78 */
mfiore 0:d472df0659a9 79 bool sendAllKvp(bool clear = true);
mfiore 0:d472df0659a9 80
mfiore 0:d472df0659a9 81 private:
mfiore 1:d42aaf6f2e19 82 bool sendBase(const std::string& data);
mfiore 0:d472df0659a9 83
mfiore 0:d472df0659a9 84 HTTPClient* _http_client;
mfiore 0:d472df0659a9 85 std::string _url;
mfiore 0:d472df0659a9 86 MbedJSONValue* _data;
mfiore 0:d472df0659a9 87 int _timeout;
mfiore 0:d472df0659a9 88 };
mfiore 0:d472df0659a9 89
mfiore 0:d472df0659a9 90 }
mfiore 0:d472df0659a9 91
mfiore 0:d472df0659a9 92 #endif