mbed based IoT Gateway More details http://blog.thiseldo.co.uk/wp-filez/IoTGateway.pdf
Dependencies: NetServices FatFileSystem csv_parser mbed MQTTClient RF12B DNSResolver SDFileSystem
Diff: Outputs/OutputPachube.cpp
- Revision:
- 4:d460406ac780
- Parent:
- 0:a29a0225f203
- Child:
- 5:0dbc27a7af55
--- a/Outputs/OutputPachube.cpp Fri Apr 20 19:32:34 2012 +0000 +++ b/Outputs/OutputPachube.cpp Tue May 01 21:43:40 2012 +0000 @@ -39,10 +39,17 @@ sendCount = 0; } -void OutputPachube::setApiKey( char *key ) { +/** Alternative Constructor + */ +OutputPachube::OutputPachube( char *internalBufferStart, char *url, char *key ) { + sendCount = 0; + dataBuffer = internalBufferStart; + apiUrl = url; apiKey = key; - init(); + dbufPtr = dataBuffer; + *dbufPtr = '\0'; } + void OutputPachube::init( ) { dbufPtr = dataBuffer; @@ -64,23 +71,23 @@ int OutputPachube::send( void ) { char urlBuf[64]; - HTTPClient pachubeHttp; + HTTPClient http; if ( strlen( dataBuffer ) > 1 ) { - pachubeHttp.setRequestHeader("X-PachubeApiKey", apiKey); + http.setRequestHeader("X-PachubeApiKey", apiKey); HTTPText csvContent("text/csv"); // Get the string for Pachube csvContent.set(std::string(dataBuffer)); // uri for post includes feed ID and datastream ID - snprintf(urlBuf, 64, "http://api.pachube.com/v2/feeds/%d.csv?_method=PUT", currentFeed ); + snprintf(urlBuf, 64, PACHUBE_URL, currentFeed ); printf("URL: %s\n",urlBuf); activityLED = 1; // result should be 0 and response should be 200 for successful post - printf("Send count %d\n", ++sendCount); + printf("Pachube Send count %d\n", ++sendCount); printf("\nHEAP STATS\n"); __heapstats((__heapprt)fprintf,stderr); @@ -89,13 +96,15 @@ printf("\nStackP: %ld\n",__current_sp()); printf("---------------\n"); - HTTPResult result = pachubeHttp.post(urlBuf, csvContent, NULL); - int response = pachubeHttp.getHTTPResponseCode(); + HTTPResult result = http.post(urlBuf, csvContent, NULL); + int response = http.getHTTPResponseCode(); printf("updateDataStream(%d)\n", response ); activityLED = 0; } - init(); + dbufPtr = dataBuffer; + *dbufPtr = '\0'; + return 0; }