Wifi Pressure Sensor
Dependencies: HTTPClient MPL3115A2 NTPClient TMP102 USBDevice cc3000_hostdriver_mbedsocket mbed
Diff: tcpTests.cpp
- Revision:
- 10:11d946f4ecea
- Parent:
- 9:ac299b1a17a0
- Child:
- 11:8a3bc0e3255d
diff -r ac299b1a17a0 -r 11d946f4ecea tcpTests.cpp --- a/tcpTests.cpp Wed Jan 08 22:36:17 2014 +0000 +++ b/tcpTests.cpp Thu Jan 09 00:05:34 2014 +0000 @@ -4,8 +4,8 @@ #include "TCPSocketConnection.h" #include "TCPSocketServer.h" -#include "HTTPClient.h" -#include "Websocket.h" +//#include "HTTPClient.h" +//#include "Websocket.h" #include "TMP102.h" using namespace mbed_cc3000; @@ -13,7 +13,7 @@ extern cc3000 wifi; extern USBSerial pc; -HTTPClient http; +//HTTPClient http; // NOTE : Change SolderSplashLabs to anything else for your own channel // Goto the viewier page here : http://sockets.mbed.org/SolderSplashLabs/viewer to see the websocket writes @@ -24,6 +24,7 @@ // Put the tmpbuffer into RAM1 char tmpBuffer[512] __attribute__((section("AHBSRAM0"))); +char tmpDataBuffer[128] __attribute__((section("AHBSRAM0"))); // Add your own feed Id and API key here.. char XivelyHostname[] = "api.xively.com"; @@ -54,6 +55,7 @@ int res = 0; uint16_t counter = 0; int httpCmdLen = 0; +int httpDataLen = 0; float tempt = 0; //if ( wifi.is_connected() ) @@ -79,22 +81,23 @@ // Temp Read tempt = temperature.read(); + // Build the data string + httpDataLen = sprintf(&tmpDataBuffer[0], "COUNT, %05d\r\nRAMP, %05d\r\nTEMP, %.1f\r\n\0", counter, number, tempt); + + //httpDataLen += sprintf(&tmpDataBuffer[0], "ADC0, %05d\r\nADC1, %05d\r\nADC2, %05d\r\nADC3, %05d\r\nADC5, %05d\r\nADC6, %05d\r\nADC7, %05d\r\n\0", + //adc0.read_u16(), adc1.read_u16(), adc2.read_u16(), adc3.read_u16(), adc5.read_u16(), adc6.read_u16(), adc7.read_u16()); + // Build the header httpCmdLen = sprintf(&tmpBuffer[0], "PUT %s.csv HTTP/1.1\r\n", XivelyPath ); httpCmdLen += sprintf(&tmpBuffer[httpCmdLen], "Host: %s\r\nUser-Agent: WiFi-DipCortex\r\n", XivelyHostname); httpCmdLen += sprintf(&tmpBuffer[httpCmdLen], "X-ApiKey: %s\r\n", XivelyApiKey); // TODO : hardcoded data length of 91, using printf with padding to fix the string length - httpCmdLen += sprintf(&tmpBuffer[httpCmdLen], "Content-Type: text/csv\r\nContent-Length: 91\r\n"); + httpCmdLen += sprintf(&tmpBuffer[httpCmdLen], "Content-Type: text/csv\r\nContent-Length: %d\r\n", httpDataLen); httpCmdLen += sprintf(&tmpBuffer[httpCmdLen], "Connection: close\r\n\r\n"); - - // add the data - //httpCmdLen += sprintf(&tmpBuffer[httpCmdLen], "ADC0, %05d\r\nADC1, %05d\r\nADC2, %05d\r\nADC3, %05d\r\nADC5, %05d\r\nADC6, %05d\r\nADC7, %05d\r\n\0", - //adc0.read_u16(), adc1.read_u16(), adc2.read_u16(), adc3.read_u16(), adc5.read_u16(), adc6.read_u16(), adc7.read_u16()); - - httpCmdLen += sprintf(&tmpBuffer[httpCmdLen], "COUNT, %05d\r\nRAMP, %05d\r\nTEMP, %f\r\n\0", - counter, number, tempt); + // Add the data + httpCmdLen += sprintf(&tmpBuffer[httpCmdLen], "%s\0", tmpDataBuffer); - pc.printf("Data to be sent : \r\n %s", tmpBuffer); + pc.printf("HTTP Data to be sent : \r\n %s", tmpBuffer); pc.printf("Posting ADC's to Xively \r\n"); res = socket.send_all(tmpBuffer, httpCmdLen); @@ -144,7 +147,7 @@ // ------------------------------------------------------------------------------------------------------------ void HttpClientTest ( void ) { - +/* //GET data pc.printf("\r\nTrying to fetch page... \r\n"); int ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", tmpBuffer, 128); @@ -204,6 +207,7 @@ { pc.printf("Error - ret = %d - HTTP return code = %d \r\n", ret, http.getHTTPResponseCode()); } + */ } // ------------------------------------------------------------------------------------------------------------ @@ -213,7 +217,7 @@ // ------------------------------------------------------------------------------------------------------------ void WebSocketTest ( void ) { - +/* int res = 0; uint16_t counter = 0; uint16_t reconnects = 0; @@ -275,6 +279,7 @@ { pc.printf("Websocket connection failed\r\n"); } + */ } // ------------------------------------------------------------------------------------------------------------ @@ -284,7 +289,7 @@ // ------------------------------------------------------------------------------------------------------------ void WebSocketReadTest ( void ) { - +/* int res = 0; uint16_t counter = 0; uint16_t reconnects = 0; @@ -352,6 +357,7 @@ { pc.printf("Websocket connection failed\r\n"); } + */ } // ------------------------------------------------------------------------------------------------------------