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@6:aa0594410aa9, 2014-01-04 (annotated)
- Committer:
- mfiore
- Date:
- Sat Jan 04 08:00:38 2014 +0000
- Revision:
- 6:aa0594410aa9
- Parent:
- 4:76c124f0a842
shorten HTTPClient timeout to 5 seconds
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 | namespace mts { |
mfiore | 0:d472df0659a9 | 8 | |
mfiore | 0:d472df0659a9 | 9 | class AxedaWrapper { |
mfiore | 0:d472df0659a9 | 10 | public: |
mfiore | 0:d472df0659a9 | 11 | /** Constructor |
mfiore | 0:d472df0659a9 | 12 | * Creates an AxedaWrapper object |
mfiore | 0:d472df0659a9 | 13 | * |
mfiore | 0:d472df0659a9 | 14 | * @param serial A made up serial number for your device. It needs to be unique! |
mfiore | 0:d472df0659a9 | 15 | * A good format to use is <your initials>-<a random string of numbers>, |
mfiore | 0:d472df0659a9 | 16 | * e.g. "JTA-862653" |
mfiore | 0:d472df0659a9 | 17 | */ |
mfiore | 0:d472df0659a9 | 18 | AxedaWrapper(const std::string& serial, const std::string& model = "mbed", const std::string& host = "dev6-connect.axeda.com", int port = 52689); |
mfiore | 0:d472df0659a9 | 19 | |
mfiore | 0:d472df0659a9 | 20 | /** Destructor |
mfiore | 0:d472df0659a9 | 21 | * Deletes the AxedaWrapper object and returns all allocated memory |
mfiore | 0:d472df0659a9 | 22 | */ |
mfiore | 0:d472df0659a9 | 23 | ~AxedaWrapper(); |
mfiore | 0:d472df0659a9 | 24 | |
mfiore | 2:99baa98f84a3 | 25 | /** push |
mfiore | 0:d472df0659a9 | 26 | * Adds a key-value pair to the internal map. |
mfiore | 0:d472df0659a9 | 27 | * |
mfiore | 0:d472df0659a9 | 28 | * @param key The "name" of the value. |
mfiore | 0:d472df0659a9 | 29 | * @param value The value to be stored. |
mfiore | 0:d472df0659a9 | 30 | */ |
mfiore | 2:99baa98f84a3 | 31 | void push(const std::string& key, const std::string& value); |
sgodinez | 3:134410324a6a | 32 | void push(const std::string& key, const char* value); |
mfiore | 2:99baa98f84a3 | 33 | void push(const std::string& key, int value); |
mfiore | 2:99baa98f84a3 | 34 | void push(const std::string& key, double value); |
mfiore | 2:99baa98f84a3 | 35 | void push(const std::string& key, bool value); |
mfiore | 0:d472df0659a9 | 36 | |
mfiore | 2:99baa98f84a3 | 37 | /** toString |
mfiore | 2:99baa98f84a3 | 38 | * Returns a std::string containing the serialized json contents of the internal map |
mfiore | 2:99baa98f84a3 | 39 | * If the internal map is empty, "{}" will be returned |
mfiore | 2:99baa98f84a3 | 40 | */ |
mfiore | 2:99baa98f84a3 | 41 | std::string toString(); |
mfiore | 2:99baa98f84a3 | 42 | |
mfiore | 2:99baa98f84a3 | 43 | /** clear |
mfiore | 0:d472df0659a9 | 44 | * Removes all key-value pairs from the internal map. |
mfiore | 0:d472df0659a9 | 45 | * If the internal map is empty, no action is taken. |
mfiore | 0:d472df0659a9 | 46 | */ |
mfiore | 2:99baa98f84a3 | 47 | void clear(); |
mfiore | 0:d472df0659a9 | 48 | |
mfiore | 2:99baa98f84a3 | 49 | /** size |
mfiore | 0:d472df0659a9 | 50 | * @returns the current size of the map |
mfiore | 0:d472df0659a9 | 51 | */ |
mfiore | 2:99baa98f84a3 | 52 | int size(); |
mfiore | 0:d472df0659a9 | 53 | |
mfiore | 2:99baa98f84a3 | 54 | /** send |
mfiore | 0:d472df0659a9 | 55 | * Sends a key-value pair to the Axeda platform |
mfiore | 0:d472df0659a9 | 56 | * |
mfiore | 0:d472df0659a9 | 57 | * @param key The "name" of the value. |
mfiore | 0:d472df0659a9 | 58 | * @param value The value to be sent. |
mfiore | 0:d472df0659a9 | 59 | * @return true if the value was sent successfully, false otherwise |
mfiore | 0:d472df0659a9 | 60 | */ |
mfiore | 2:99baa98f84a3 | 61 | bool send(const std::string& key, const std::string& value); |
sgodinez | 3:134410324a6a | 62 | bool send(const std::string& key, const char* value); |
mfiore | 2:99baa98f84a3 | 63 | bool send(const std::string& key, int value); |
mfiore | 2:99baa98f84a3 | 64 | bool send(const std::string& key, double value); |
mfiore | 2:99baa98f84a3 | 65 | bool send(const std::string& key, bool value); |
mfiore | 0:d472df0659a9 | 66 | |
mfiore | 2:99baa98f84a3 | 67 | /** sendAll |
mfiore | 0:d472df0659a9 | 68 | * Sends all the key-value pairs in the internal map to the Axeda platform |
mfiore | 0:d472df0659a9 | 69 | * |
mfiore | 0:d472df0659a9 | 70 | * @param clear If true, clear the internal map if the send is successful, |
mfiore | 0:d472df0659a9 | 71 | * if false, don't clear the internal map |
mfiore | 0:d472df0659a9 | 72 | * @return true if successful, false otherwise |
mfiore | 0:d472df0659a9 | 73 | */ |
mfiore | 2:99baa98f84a3 | 74 | bool sendAll(bool clean = true); |
mfiore | 0:d472df0659a9 | 75 | |
mfiore | 0:d472df0659a9 | 76 | private: |
mfiore | 1:d42aaf6f2e19 | 77 | bool sendBase(const std::string& data); |
mfiore | 0:d472df0659a9 | 78 | |
mfiore | 0:d472df0659a9 | 79 | HTTPClient* _http_client; |
mfiore | 0:d472df0659a9 | 80 | std::string _url; |
mfiore | 0:d472df0659a9 | 81 | MbedJSONValue* _data; |
mfiore | 0:d472df0659a9 | 82 | int _timeout; |
mfiore | 0:d472df0659a9 | 83 | }; |
mfiore | 0:d472df0659a9 | 84 | |
mfiore | 0:d472df0659a9 | 85 | } |
mfiore | 0:d472df0659a9 | 86 | |
mfiore | 0:d472df0659a9 | 87 | #endif |