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 Segundo Equipo

Committer:
tsoic
Date:
Sun Nov 29 13:41:05 2015 +0000
Revision:
7:1da0a084cd69
Parent:
6:ebbde59c5a1d
Child:
8:9b35ac104ab7

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tsoic 7:1da0a084cd69 1 /** Class for sending data to ThingSpeak over ethernet,
tsoic 7:1da0a084cd69 2 * Class is using old mbed library revision and EthernetNetIf from
tsoic 7:1da0a084cd69 3 * https://developer.mbed.org/users/okini3939/notebook/TCPSocket_jp/
tsoic 7:1da0a084cd69 4 * Example:
tsoic 7:1da0a084cd69 5 * @code
tsoic 7:1da0a084cd69 6 * #include "mbed.h"
tsoic 7:1da0a084cd69 7 * #include "ThingSpeak.h"
tsoic 7:1da0a084cd69 8 *
tsoic 7:1da0a084cd69 9 * ThingSpeak thingSpeak("XXXXXXXXXXXXXXXX");
tsoic 7:1da0a084cd69 10 *
tsoic 7:1da0a084cd69 11 * int main() {
tsoic 7:1da0a084cd69 12 * int i = 1;
tsoic 7:1da0a084cd69 13 * flot value = 3.14;
tsoic 7:1da0a084cd69 14 * thingSpeak.connect();
tsoic 7:1da0a084cd69 15 * thingSpeak.setField(value,i)
tsoic 7:1da0a084cd69 16 * thingSpeak.putUp();
tsoic 7:1da0a084cd69 17 * }
tsoic 7:1da0a084cd69 18 * @endcode
tsoic 7:1da0a084cd69 19 */
tsoic 7:1da0a084cd69 20
tsoic 6:ebbde59c5a1d 21 #ifndef THINGSPEAK_H
tsoic 6:ebbde59c5a1d 22 #define THINGSPEAK_H
tsoic 6:ebbde59c5a1d 23 #define HOSTNAME "mbed"
tsoic 6:ebbde59c5a1d 24 #include "mbed.h"
tsoic 6:ebbde59c5a1d 25 #include "EthernetNetIf.h"
tsoic 6:ebbde59c5a1d 26 #include "HTTPClient.h"
tsoic 6:ebbde59c5a1d 27
tsoic 6:ebbde59c5a1d 28
tsoic 7:1da0a084cd69 29 class ThingSpeak
tsoic 7:1da0a084cd69 30 {
tsoic 7:1da0a084cd69 31
tsoic 7:1da0a084cd69 32 public:
tsoic 7:1da0a084cd69 33 /**
tsoic 7:1da0a084cd69 34 * @param: write api key provided from ThingSpeak chanell
tsoic 7:1da0a084cd69 35 */
tsoic 7:1da0a084cd69 36 ThingSpeak(char*);
tsoic 7:1da0a084cd69 37 /**
tsoic 7:1da0a084cd69 38 * Establishing ethernet connection until connected
tsoic 7:1da0a084cd69 39 *
tsoic 7:1da0a084cd69 40 */
tsoic 7:1da0a084cd69 41 void connect();
tsoic 7:1da0a084cd69 42 /**
tsoic 7:1da0a084cd69 43 * Should be added
tsoic 7:1da0a084cd69 44 */
tsoic 7:1da0a084cd69 45 /**
tsoic 7:1da0a084cd69 46 * void getIP();
tsoic 7:1da0a084cd69 47 */
tsoic 7:1da0a084cd69 48 /**
tsoic 7:1da0a084cd69 49 * Put up data to thing speak when all fields are set
tsoic 7:1da0a084cd69 50 */
tsoic 7:1da0a084cd69 51 void putUp();
tsoic 7:1da0a084cd69 52 /**
tsoic 7:1da0a084cd69 53 *Setting values to the field, they should be set in order.
tsoic 7:1da0a084cd69 54 * It's not required to set them all (example: you can set 1, 2, 3 or 1, 3)
tsoic 7:1da0a084cd69 55 * @param field value to store on
tsoic 7:1da0a084cd69 56 * @param i number of a field
tsoic 7:1da0a084cd69 57 */
tsoic 7:1da0a084cd69 58 void setField(float field, int i);
tsoic 7:1da0a084cd69 59 private:
tsoic 7:1da0a084cd69 60
tsoic 7:1da0a084cd69 61 char* thingSpeakUrl;
tsoic 7:1da0a084cd69 62 char* thingSpeakKey;
tsoic 7:1da0a084cd69 63 char urlBuffer[511];
tsoic 7:1da0a084cd69 64 char fieldBuffer[255];
tsoic 7:1da0a084cd69 65 EthernetNetIf eth;
tsoic 7:1da0a084cd69 66 EthernetErr ethErr;
tsoic 7:1da0a084cd69 67 HTTPClient http;
tsoic 7:1da0a084cd69 68 IpAddr ethIp;
tsoic 7:1da0a084cd69 69 HTTPText resp;
tsoic 7:1da0a084cd69 70 HTTPResult res;
tsoic 6:ebbde59c5a1d 71 };
tsoic 6:ebbde59c5a1d 72
tsoic 7:1da0a084cd69 73 #endif