Library for writing and reading on ThingSpeak with ethernet
Fork of ThingSpeakEthernet by
ThingSpeak.h@2:5191c0e163d6, 2017-06-28 (annotated)
- Committer:
- mpuric
- Date:
- Wed Jun 28 18:35:29 2017 +0000
- Revision:
- 2:5191c0e163d6
- Parent:
- 1:ea7f0ef29ef5
- Child:
- 3:2067cd92dcc5
added api doc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mpuric | 0:a7bce9e88175 | 1 | #ifndef THINGSPEAK_H |
mpuric | 0:a7bce9e88175 | 2 | #define THINGSPEAK_H |
mpuric | 0:a7bce9e88175 | 3 | #define HOSTNAME "mbed" |
mpuric | 0:a7bce9e88175 | 4 | #include "mbed.h" |
mpuric | 0:a7bce9e88175 | 5 | #include "EthernetNetIf.h" |
mpuric | 0:a7bce9e88175 | 6 | #include "HTTPClient.h" |
mpuric | 0:a7bce9e88175 | 7 | |
mpuric | 0:a7bce9e88175 | 8 | /** Class for sending data to ThingSpeak over ethernet, |
mpuric | 1:ea7f0ef29ef5 | 9 | * Class is using old mbed library revision and SensorsThingSpeak from |
mpuric | 1:ea7f0ef29ef5 | 10 | * https://developer.mbed.org/teams/TVZ-Mechatronics-Team/code/SensorsThingSpeak/ |
mpuric | 0:a7bce9e88175 | 11 | * Example: |
mpuric | 0:a7bce9e88175 | 12 | * @code |
mpuric | 0:a7bce9e88175 | 13 | * #include "mbed.h" |
mpuric | 0:a7bce9e88175 | 14 | * #include "ThingSpeak.h" |
mpuric | 0:a7bce9e88175 | 15 | * |
mpuric | 0:a7bce9e88175 | 16 | * ThingSpeak thingSpeak("XXXXXXXXXXXXXXXX"); |
mpuric | 0:a7bce9e88175 | 17 | * |
mpuric | 0:a7bce9e88175 | 18 | * int main() { |
mpuric | 0:a7bce9e88175 | 19 | * int i = 1; |
mpuric | 0:a7bce9e88175 | 20 | * flot value = 3.14; |
mpuric | 0:a7bce9e88175 | 21 | * thingSpeak.connect(); |
mpuric | 0:a7bce9e88175 | 22 | * thingSpeak.setField(value,i) |
mpuric | 0:a7bce9e88175 | 23 | * thingSpeak.putUp(); |
mpuric | 0:a7bce9e88175 | 24 | * } |
mpuric | 0:a7bce9e88175 | 25 | * @endcode |
mpuric | 0:a7bce9e88175 | 26 | */ |
mpuric | 0:a7bce9e88175 | 27 | class ThingSpeak |
mpuric | 0:a7bce9e88175 | 28 | { |
mpuric | 0:a7bce9e88175 | 29 | |
mpuric | 0:a7bce9e88175 | 30 | public: |
mpuric | 2:5191c0e163d6 | 31 | /** Write api key provided from ThingSpek channel. |
mpuric | 2:5191c0e163d6 | 32 | * @param: write api key provided from ThingSpeak channel. |
mpuric | 0:a7bce9e88175 | 33 | */ |
mpuric | 0:a7bce9e88175 | 34 | ThingSpeak(char*); |
mpuric | 0:a7bce9e88175 | 35 | /** |
mpuric | 2:5191c0e163d6 | 36 | * Establishing ethernet connection until connected. |
mpuric | 0:a7bce9e88175 | 37 | * |
mpuric | 0:a7bce9e88175 | 38 | */ |
mpuric | 0:a7bce9e88175 | 39 | void connect(); |
mpuric | 0:a7bce9e88175 | 40 | |
mpuric | 1:ea7f0ef29ef5 | 41 | /** |
mpuric | 2:5191c0e163d6 | 42 | * Funkcion for pulling data from ThingSpeak. |
mpuric | 2:5191c0e163d6 | 43 | * @param readKey Channel feed number |
mpuric | 2:5191c0e163d6 | 44 | * @param Field number. |
mpuric | 1:ea7f0ef29ef5 | 45 | */ |
mpuric | 0:a7bce9e88175 | 46 | float pull(long int, int); |
mpuric | 0:a7bce9e88175 | 47 | |
mpuric | 1:ea7f0ef29ef5 | 48 | |
mpuric | 0:a7bce9e88175 | 49 | void putUp(); |
mpuric | 0:a7bce9e88175 | 50 | /** |
mpuric | 0:a7bce9e88175 | 51 | *Setting values to the field, they should be set in order. |
mpuric | 0:a7bce9e88175 | 52 | * It's not required to set them all (example: you can set 1, 2, 3 or 1, 3) |
mpuric | 2:5191c0e163d6 | 53 | * @param Field value to store on. |
mpuric | 2:5191c0e163d6 | 54 | * @param i number of a field. |
mpuric | 0:a7bce9e88175 | 55 | */ |
mpuric | 0:a7bce9e88175 | 56 | void setField(float field, int i); |
mpuric | 0:a7bce9e88175 | 57 | private: |
mpuric | 0:a7bce9e88175 | 58 | |
mpuric | 0:a7bce9e88175 | 59 | char* thingSpeakUrl; |
mpuric | 0:a7bce9e88175 | 60 | char* thingSpeakRead; |
mpuric | 0:a7bce9e88175 | 61 | char* thingSpeakKey; |
mpuric | 0:a7bce9e88175 | 62 | char urlBuffer[1023]; |
mpuric | 0:a7bce9e88175 | 63 | char fieldBuffer[1023]; |
mpuric | 0:a7bce9e88175 | 64 | EthernetNetIf eth; |
mpuric | 0:a7bce9e88175 | 65 | EthernetErr ethErr; |
mpuric | 0:a7bce9e88175 | 66 | HTTPClient http; |
mpuric | 0:a7bce9e88175 | 67 | IpAddr ethIp; |
mpuric | 0:a7bce9e88175 | 68 | HTTPText resp; |
mpuric | 0:a7bce9e88175 | 69 | HTTPResult res; |
mpuric | 0:a7bce9e88175 | 70 | }; |
mpuric | 0:a7bce9e88175 | 71 | |
mpuric | 0:a7bce9e88175 | 72 | #endif |