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
Diff: ThingSpeak.cpp
- Revision:
- 6:ebbde59c5a1d
- Child:
- 7:1da0a084cd69
diff -r 1e77bdd1a639 -r ebbde59c5a1d ThingSpeak.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ThingSpeak.cpp Fri Nov 20 08:28:11 2015 +0000 @@ -0,0 +1,48 @@ +#include "mbed.h" +#include "EthernetNetIf.h" +#include "HTTPClient.h" +#include "ThingSpeak.h" + +Serial pc(USBTX, USBRX); + +ThingSpeak::ThingSpeak(char* Key, const int Qt) : thingSpeakKey(Key) { + thingSpeakUrl = "https://api.thingspeak.com/update"; + urlBuffer[0] = 0; + fieldBuffer[0] = 0; +} + +void ThingSpeak::connect() { + pc.printf("Setting up Ethernet...\r\n"); + EthernetErr ethErr = eth.setup(); + if(ethErr){ + pc.printf("Error %d in ethernet setup.\r\n", ethErr); + //* connect(); + } + pc.printf("Ethernet setup OK\r\n"); +} + +void ThingSpeak::getIP() { + +} + +void ThingSpeak::setField(float field, int i) { + char fieldi; + char fieldShortBuff[8]; + sprintf(fieldShortBuff, "%f", field); + sprintf(&fieldi, "%i", i); + strncat(fieldBuffer, "&field", 6 ); + strncat(fieldBuffer, &fieldi , 1); + strncat(fieldBuffer, "=", 1); + strncat(fieldBuffer, fieldShortBuff , 4); +} + +void ThingSpeak::putUp() { + sprintf(urlBuffer, "%s?key=%s%s", thingSpeakUrl, thingSpeakKey, fieldBuffer); + pc.printf("URL Buffer request: %s ", urlBuffer); + res = http.get(urlBuffer, &resp); + if (res == HTTP_OK) + pc.printf(" Result :\"%s\"\r\n", resp.gets()); + else + pc.printf(" Error %d\r\n", res); + fieldBuffer[0] = 0; +} \ No newline at end of file