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:
Thu Dec 19 21:49:05 2013 +0000
Revision:
0:d472df0659a9
Child:
1:d42aaf6f2e19
initial commit

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