Library for writing and reading on ThingSpeak with ethernet

Dependents:   PMS5003 PMS5003

Committer:
mpuric
Date:
Thu Jun 08 18:28:20 2017 +0000
Revision:
1:ea7f0ef29ef5
Parent:
0:a7bce9e88175
Child:
2:5191c0e163d6
Added comments.; ;

Who changed what in which revision?

UserRevisionLine numberNew 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 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 1:ea7f0ef29ef5 41 /**
mpuric 1:ea7f0ef29ef5 42 * Added a function for pulling data from ThingSpeak.
mpuric 1:ea7f0ef29ef5 43 */
mpuric 0:a7bce9e88175 44 float pull(long int, int);
mpuric 0:a7bce9e88175 45
mpuric 1:ea7f0ef29ef5 46
mpuric 0:a7bce9e88175 47 void putUp();
mpuric 0:a7bce9e88175 48 /**
mpuric 0:a7bce9e88175 49 *Setting values to the field, they should be set in order.
mpuric 0:a7bce9e88175 50 * It's not required to set them all (example: you can set 1, 2, 3 or 1, 3)
mpuric 0:a7bce9e88175 51 * @param field value to store on
mpuric 0:a7bce9e88175 52 * @param i number of a field
mpuric 0:a7bce9e88175 53 */
mpuric 0:a7bce9e88175 54 void setField(float field, int i);
mpuric 0:a7bce9e88175 55 private:
mpuric 0:a7bce9e88175 56
mpuric 0:a7bce9e88175 57 char* thingSpeakUrl;
mpuric 0:a7bce9e88175 58 char* thingSpeakRead;
mpuric 0:a7bce9e88175 59 char* thingSpeakKey;
mpuric 0:a7bce9e88175 60 char urlBuffer[1023];
mpuric 0:a7bce9e88175 61 char fieldBuffer[1023];
mpuric 0:a7bce9e88175 62 EthernetNetIf eth;
mpuric 0:a7bce9e88175 63 EthernetErr ethErr;
mpuric 0:a7bce9e88175 64 HTTPClient http;
mpuric 0:a7bce9e88175 65 IpAddr ethIp;
mpuric 0:a7bce9e88175 66 HTTPText resp;
mpuric 0:a7bce9e88175 67 HTTPResult res;
mpuric 0:a7bce9e88175 68 };
mpuric 0:a7bce9e88175 69
mpuric 0:a7bce9e88175 70 #endif