Library for writing and reading on ThingSpeak with ethernet
ThingSpeak.h@0:a7bce9e88175, 2017-06-05 (annotated)
- Committer:
- mpuric
- Date:
- Mon Jun 05 08:17:19 2017 +0000
- Revision:
- 0:a7bce9e88175
- Child:
- 1:ea7f0ef29ef5
ThingSpeak converted to library
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 | 0:a7bce9e88175 | 9 | * Class is using old mbed library revision and EthernetNetIf from |
mpuric | 0:a7bce9e88175 | 10 | * https://developer.mbed.org/users/okini3939/notebook/TCPSocket_jp/ |
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 | 0:a7bce9e88175 | 31 | /** |
mpuric | 0:a7bce9e88175 | 32 | * @param: write api key provided from ThingSpeak chanell |
mpuric | 0:a7bce9e88175 | 33 | */ |
mpuric | 0:a7bce9e88175 | 34 | ThingSpeak(char*); |
mpuric | 0:a7bce9e88175 | 35 | /** |
mpuric | 0:a7bce9e88175 | 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 | 0:a7bce9e88175 | 41 | float pull(long int, int); |
mpuric | 0:a7bce9e88175 | 42 | |
mpuric | 0:a7bce9e88175 | 43 | /** |
mpuric | 0:a7bce9e88175 | 44 | * Should be added |
mpuric | 0:a7bce9e88175 | 45 | */ |
mpuric | 0:a7bce9e88175 | 46 | /** |
mpuric | 0:a7bce9e88175 | 47 | * void getIP(); |
mpuric | 0:a7bce9e88175 | 48 | */ |
mpuric | 0:a7bce9e88175 | 49 | /** |
mpuric | 0:a7bce9e88175 | 50 | * Put up data to thing speak when all fields are set |
mpuric | 0:a7bce9e88175 | 51 | */ |
mpuric | 0:a7bce9e88175 | 52 | void putUp(); |
mpuric | 0:a7bce9e88175 | 53 | /** |
mpuric | 0:a7bce9e88175 | 54 | *Setting values to the field, they should be set in order. |
mpuric | 0:a7bce9e88175 | 55 | * It's not required to set them all (example: you can set 1, 2, 3 or 1, 3) |
mpuric | 0:a7bce9e88175 | 56 | * @param field value to store on |
mpuric | 0:a7bce9e88175 | 57 | * @param i number of a field |
mpuric | 0:a7bce9e88175 | 58 | */ |
mpuric | 0:a7bce9e88175 | 59 | void setField(float field, int i); |
mpuric | 0:a7bce9e88175 | 60 | private: |
mpuric | 0:a7bce9e88175 | 61 | |
mpuric | 0:a7bce9e88175 | 62 | char* thingSpeakUrl; |
mpuric | 0:a7bce9e88175 | 63 | char* thingSpeakRead; |
mpuric | 0:a7bce9e88175 | 64 | char* thingSpeakKey; |
mpuric | 0:a7bce9e88175 | 65 | char urlBuffer[1023]; |
mpuric | 0:a7bce9e88175 | 66 | char fieldBuffer[1023]; |
mpuric | 0:a7bce9e88175 | 67 | EthernetNetIf eth; |
mpuric | 0:a7bce9e88175 | 68 | EthernetErr ethErr; |
mpuric | 0:a7bce9e88175 | 69 | HTTPClient http; |
mpuric | 0:a7bce9e88175 | 70 | IpAddr ethIp; |
mpuric | 0:a7bce9e88175 | 71 | HTTPText resp; |
mpuric | 0:a7bce9e88175 | 72 | HTTPResult res; |
mpuric | 0:a7bce9e88175 | 73 | }; |
mpuric | 0:a7bce9e88175 | 74 | |
mpuric | 0:a7bce9e88175 | 75 | #endif |