Library for writing and reading on ThingSpeak with ethernet

Fork of ThingSpeakEthernet by marko puric

Committer:
mpuric
Date:
Thu Jun 29 15:18:15 2017 +0000
Revision:
3:2067cd92dcc5
Parent:
2:5191c0e163d6
Added api doc;

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 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 3:2067cd92dcc5 48 /** Used for putting up data on ThingSpeak channel.
mpuric 3:2067cd92dcc5 49 * Use it after setField(float field, int i) function.
mpuric 3:2067cd92dcc5 50 */
mpuric 0:a7bce9e88175 51 void putUp();
mpuric 0:a7bce9e88175 52 /**
mpuric 0:a7bce9e88175 53 *Setting values to the field, they should be set in order.
mpuric 0:a7bce9e88175 54 * It's not required to set them all (example: you can set 1, 2, 3 or 1, 3)
mpuric 2:5191c0e163d6 55 * @param Field value to store on.
mpuric 2:5191c0e163d6 56 * @param i number of a field.
mpuric 0:a7bce9e88175 57 */
mpuric 0:a7bce9e88175 58 void setField(float field, int i);
mpuric 0:a7bce9e88175 59 private:
mpuric 0:a7bce9e88175 60
mpuric 0:a7bce9e88175 61 char* thingSpeakUrl;
mpuric 0:a7bce9e88175 62 char* thingSpeakRead;
mpuric 0:a7bce9e88175 63 char* thingSpeakKey;
mpuric 0:a7bce9e88175 64 char urlBuffer[1023];
mpuric 0:a7bce9e88175 65 char fieldBuffer[1023];
mpuric 0:a7bce9e88175 66 EthernetNetIf eth;
mpuric 0:a7bce9e88175 67 EthernetErr ethErr;
mpuric 0:a7bce9e88175 68 HTTPClient http;
mpuric 0:a7bce9e88175 69 IpAddr ethIp;
mpuric 0:a7bce9e88175 70 HTTPText resp;
mpuric 0:a7bce9e88175 71 HTTPResult res;
mpuric 0:a7bce9e88175 72 };
mpuric 0:a7bce9e88175 73
mpuric 0:a7bce9e88175 74 #endif