Uploading sensor data (voltage divider, MAX4172, INA219) over Ethernet to Thing Speak service. Uses old mbed revision that is compatible with NetServices library. I2C communication is made with I2CR library.
Dependencies: C12832 I2CR INA219 NetServices mbed
Fork of NetServices_HelloWorld by
ThingSpeak.h@8:9b35ac104ab7, 2015-11-29 (annotated)
- Committer:
- tbjazic
- Date:
- Sun Nov 29 14:26:32 2015 +0000
- Revision:
- 8:9b35ac104ab7
- Parent:
- 7:1da0a084cd69
premjesteni koemntari klase tocno prije deklaracije, kako bi se ispravno generirala dokumentacija
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tbjazic | 8:9b35ac104ab7 | 1 | #ifndef THINGSPEAK_H |
tbjazic | 8:9b35ac104ab7 | 2 | #define THINGSPEAK_H |
tbjazic | 8:9b35ac104ab7 | 3 | #define HOSTNAME "mbed" |
tbjazic | 8:9b35ac104ab7 | 4 | #include "mbed.h" |
tbjazic | 8:9b35ac104ab7 | 5 | #include "EthernetNetIf.h" |
tbjazic | 8:9b35ac104ab7 | 6 | #include "HTTPClient.h" |
tbjazic | 8:9b35ac104ab7 | 7 | |
tsoic | 7:1da0a084cd69 | 8 | /** Class for sending data to ThingSpeak over ethernet, |
tsoic | 7:1da0a084cd69 | 9 | * Class is using old mbed library revision and EthernetNetIf from |
tsoic | 7:1da0a084cd69 | 10 | * https://developer.mbed.org/users/okini3939/notebook/TCPSocket_jp/ |
tsoic | 7:1da0a084cd69 | 11 | * Example: |
tsoic | 7:1da0a084cd69 | 12 | * @code |
tsoic | 7:1da0a084cd69 | 13 | * #include "mbed.h" |
tsoic | 7:1da0a084cd69 | 14 | * #include "ThingSpeak.h" |
tsoic | 7:1da0a084cd69 | 15 | * |
tsoic | 7:1da0a084cd69 | 16 | * ThingSpeak thingSpeak("XXXXXXXXXXXXXXXX"); |
tsoic | 7:1da0a084cd69 | 17 | * |
tsoic | 7:1da0a084cd69 | 18 | * int main() { |
tsoic | 7:1da0a084cd69 | 19 | * int i = 1; |
tsoic | 7:1da0a084cd69 | 20 | * flot value = 3.14; |
tsoic | 7:1da0a084cd69 | 21 | * thingSpeak.connect(); |
tsoic | 7:1da0a084cd69 | 22 | * thingSpeak.setField(value,i) |
tsoic | 7:1da0a084cd69 | 23 | * thingSpeak.putUp(); |
tsoic | 7:1da0a084cd69 | 24 | * } |
tsoic | 7:1da0a084cd69 | 25 | * @endcode |
tsoic | 7:1da0a084cd69 | 26 | */ |
tsoic | 7:1da0a084cd69 | 27 | class ThingSpeak |
tsoic | 7:1da0a084cd69 | 28 | { |
tsoic | 7:1da0a084cd69 | 29 | |
tsoic | 7:1da0a084cd69 | 30 | public: |
tsoic | 7:1da0a084cd69 | 31 | /** |
tsoic | 7:1da0a084cd69 | 32 | * @param: write api key provided from ThingSpeak chanell |
tsoic | 7:1da0a084cd69 | 33 | */ |
tsoic | 7:1da0a084cd69 | 34 | ThingSpeak(char*); |
tsoic | 7:1da0a084cd69 | 35 | /** |
tsoic | 7:1da0a084cd69 | 36 | * Establishing ethernet connection until connected |
tsoic | 7:1da0a084cd69 | 37 | * |
tsoic | 7:1da0a084cd69 | 38 | */ |
tsoic | 7:1da0a084cd69 | 39 | void connect(); |
tsoic | 7:1da0a084cd69 | 40 | /** |
tsoic | 7:1da0a084cd69 | 41 | * Should be added |
tsoic | 7:1da0a084cd69 | 42 | */ |
tsoic | 7:1da0a084cd69 | 43 | /** |
tsoic | 7:1da0a084cd69 | 44 | * void getIP(); |
tsoic | 7:1da0a084cd69 | 45 | */ |
tsoic | 7:1da0a084cd69 | 46 | /** |
tsoic | 7:1da0a084cd69 | 47 | * Put up data to thing speak when all fields are set |
tsoic | 7:1da0a084cd69 | 48 | */ |
tsoic | 7:1da0a084cd69 | 49 | void putUp(); |
tsoic | 7:1da0a084cd69 | 50 | /** |
tsoic | 7:1da0a084cd69 | 51 | *Setting values to the field, they should be set in order. |
tsoic | 7:1da0a084cd69 | 52 | * It's not required to set them all (example: you can set 1, 2, 3 or 1, 3) |
tsoic | 7:1da0a084cd69 | 53 | * @param field value to store on |
tsoic | 7:1da0a084cd69 | 54 | * @param i number of a field |
tsoic | 7:1da0a084cd69 | 55 | */ |
tsoic | 7:1da0a084cd69 | 56 | void setField(float field, int i); |
tsoic | 7:1da0a084cd69 | 57 | private: |
tsoic | 7:1da0a084cd69 | 58 | |
tsoic | 7:1da0a084cd69 | 59 | char* thingSpeakUrl; |
tsoic | 7:1da0a084cd69 | 60 | char* thingSpeakKey; |
tsoic | 7:1da0a084cd69 | 61 | char urlBuffer[511]; |
tsoic | 7:1da0a084cd69 | 62 | char fieldBuffer[255]; |
tsoic | 7:1da0a084cd69 | 63 | EthernetNetIf eth; |
tsoic | 7:1da0a084cd69 | 64 | EthernetErr ethErr; |
tsoic | 7:1da0a084cd69 | 65 | HTTPClient http; |
tsoic | 7:1da0a084cd69 | 66 | IpAddr ethIp; |
tsoic | 7:1da0a084cd69 | 67 | HTTPText resp; |
tsoic | 7:1da0a084cd69 | 68 | HTTPResult res; |
tsoic | 6:ebbde59c5a1d | 69 | }; |
tsoic | 6:ebbde59c5a1d | 70 | |
tsoic | 7:1da0a084cd69 | 71 | #endif |