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/
AxedaWrapper.h@3:134410324a6a, 2013-12-27 (annotated)
- Committer:
- sgodinez
- Date:
- Fri Dec 27 20:58:22 2013 +0000
- Revision:
- 3:134410324a6a
- Parent:
- 2:99baa98f84a3
- Child:
- 4:76c124f0a842
Removed functions that could use implicit parameter conversions
Who changed what in which revision?
User | Revision | Line number | New 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 | 2:99baa98f84a3 | 26 | /** push |
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 | 2:99baa98f84a3 | 32 | void push(const std::string& key, const std::string& value); |
sgodinez | 3:134410324a6a | 33 | void push(const std::string& key, const char* value); |
mfiore | 2:99baa98f84a3 | 34 | void push(const std::string& key, int value); |
mfiore | 2:99baa98f84a3 | 35 | void push(const std::string& key, double value); |
mfiore | 2:99baa98f84a3 | 36 | void push(const std::string& key, bool value); |
mfiore | 0:d472df0659a9 | 37 | |
mfiore | 2:99baa98f84a3 | 38 | /** toString |
mfiore | 2:99baa98f84a3 | 39 | * Returns a std::string containing the serialized json contents of the internal map |
mfiore | 2:99baa98f84a3 | 40 | * If the internal map is empty, "{}" will be returned |
mfiore | 2:99baa98f84a3 | 41 | */ |
mfiore | 2:99baa98f84a3 | 42 | std::string toString(); |
mfiore | 2:99baa98f84a3 | 43 | |
mfiore | 2:99baa98f84a3 | 44 | /** clear |
mfiore | 0:d472df0659a9 | 45 | * Removes all key-value pairs from the internal map. |
mfiore | 0:d472df0659a9 | 46 | * If the internal map is empty, no action is taken. |
mfiore | 0:d472df0659a9 | 47 | */ |
mfiore | 2:99baa98f84a3 | 48 | void clear(); |
mfiore | 0:d472df0659a9 | 49 | |
mfiore | 2:99baa98f84a3 | 50 | /** size |
mfiore | 0:d472df0659a9 | 51 | * @returns the current size of the map |
mfiore | 0:d472df0659a9 | 52 | */ |
mfiore | 2:99baa98f84a3 | 53 | int size(); |
mfiore | 0:d472df0659a9 | 54 | |
mfiore | 2:99baa98f84a3 | 55 | /** send |
mfiore | 0:d472df0659a9 | 56 | * Sends a key-value pair to the Axeda platform |
mfiore | 0:d472df0659a9 | 57 | * |
mfiore | 0:d472df0659a9 | 58 | * @param key The "name" of the value. |
mfiore | 0:d472df0659a9 | 59 | * @param value The value to be sent. |
mfiore | 0:d472df0659a9 | 60 | * @return true if the value was sent successfully, false otherwise |
mfiore | 0:d472df0659a9 | 61 | */ |
mfiore | 2:99baa98f84a3 | 62 | bool send(const std::string& key, const std::string& value); |
sgodinez | 3:134410324a6a | 63 | bool send(const std::string& key, const char* value); |
mfiore | 2:99baa98f84a3 | 64 | bool send(const std::string& key, int value); |
mfiore | 2:99baa98f84a3 | 65 | bool send(const std::string& key, double value); |
mfiore | 2:99baa98f84a3 | 66 | bool send(const std::string& key, bool value); |
mfiore | 0:d472df0659a9 | 67 | |
mfiore | 2:99baa98f84a3 | 68 | /** sendAll |
mfiore | 0:d472df0659a9 | 69 | * Sends all the key-value pairs in the internal map to the Axeda platform |
mfiore | 0:d472df0659a9 | 70 | * |
mfiore | 0:d472df0659a9 | 71 | * @param clear If true, clear the internal map if the send is successful, |
mfiore | 0:d472df0659a9 | 72 | * if false, don't clear the internal map |
mfiore | 0:d472df0659a9 | 73 | * @return true if successful, false otherwise |
mfiore | 0:d472df0659a9 | 74 | */ |
mfiore | 2:99baa98f84a3 | 75 | bool sendAll(bool clean = true); |
mfiore | 0:d472df0659a9 | 76 | |
mfiore | 0:d472df0659a9 | 77 | private: |
mfiore | 1:d42aaf6f2e19 | 78 | bool sendBase(const std::string& data); |
mfiore | 0:d472df0659a9 | 79 | |
mfiore | 0:d472df0659a9 | 80 | HTTPClient* _http_client; |
mfiore | 0:d472df0659a9 | 81 | std::string _url; |
mfiore | 0:d472df0659a9 | 82 | MbedJSONValue* _data; |
mfiore | 0:d472df0659a9 | 83 | int _timeout; |
mfiore | 0:d472df0659a9 | 84 | }; |
mfiore | 0:d472df0659a9 | 85 | |
mfiore | 0:d472df0659a9 | 86 | } |
mfiore | 0:d472df0659a9 | 87 | |
mfiore | 0:d472df0659a9 | 88 | #endif |