Test of xively server connectivity layer

Dependencies:   C12832_lcd EthernetInterface mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
olgierdh
Date:
Mon May 13 20:10:35 2013 +0000
Child:
1:c9c854dada35
Commit message:
This is simple mbed test that make the mbed device to crash after few minutes.

Changed in this revision

C12832_lcd.lib Show annotated file Show diff for this revision Revisions of this file
EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832_lcd.lib	Mon May 13 20:10:35 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/dreschpe/code/C12832_lcd/#c9afe58d786a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Mon May 13 20:10:35 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#9b2d10dc0392
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon May 13 20:10:35 2013 +0000
@@ -0,0 +1,106 @@
+#include "mbed.h"
+#include "EthernetInterface.h"
+
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "C12832_lcd.h"
+
+C12832_LCD lcd;
+
+extern "C" {
+
+void user_printf( const char* buffer )
+{
+    lcd.cls();
+    lcd.locate( 0, 0 );
+    lcd.printf( buffer );
+    // wait( 1.0 );    
+}
+
+void mbed_printf( const char* fmt, ...  )
+{
+    char buffer[ 64 ];
+    
+    va_list ap;
+    va_start( ap, fmt );
+    vsnprintf( buffer, 64, fmt, ap );
+    va_end( ap );
+    
+    user_printf( buffer );
+}
+
+}
+
+#define ADDRESS "api.cosm.com"
+#define PORT 80
+
+#define MSG "PUT /v2/feeds/117107.csv HTTP/1.1\r\n"\
+            "Host: api.xively.com\r\n"\
+            "User-Agent: libxively/0.1.x\r\n"\
+            "Accept: */*\r\n"\
+            "X-ApiKey: ISx1ANJU8P4U2dPRqCfACUrHDBOSAKxOS3ZzazZ4Tk0zND0g\r\n"\
+            "Content-Type: text/plain\r\n"\
+            "Content-Length: 33\r\n\r\n"\
+            "0001,test1\n"\
+            "0002,test2\n"\
+            "0003,test3\n\0"
+ 
+
+int main() {
+    EthernetInterface eth;
+    
+    int s = eth.init(); //Use DHCP
+    
+    size_t msg_len = strlen( MSG );
+    
+    if( s != NULL )
+    {
+        mbed_printf( "Could not initialise. Will halt!\n" );        
+        exit( 0 );
+    }    
+        
+    s = eth.connect();
+    
+    if( s != NULL )
+    {
+        mbed_printf( "Could not connect. Will halt!\n" );
+        exit( 0 );
+    }
+    else 
+    {
+        mbed_printf( "IP: %s\n", eth.getIPAddress() );    
+    }
+
+    
+    TCPSocketConnection connection;
+    #define RECV_BUFFER_SIZE 512
+    char buffer[ RECV_BUFFER_SIZE ];
+    
+    while( 1 )
+    {
+        if( connection.connect( ADDRESS, PORT ) == -1 )
+        {
+            mbed_printf( "Error during connection attempt\n" );
+            wait( 1.0 );
+            continue;
+        }
+        
+        if( connection.send( MSG, msg_len ) == -1 )
+        {
+            mbed_printf( "Error during send attempt\n" );
+            wait( 1.0 );
+            goto close;
+        }
+         
+        memset( buffer, 0, RECV_BUFFER_SIZE ); 
+        
+        if( connection.receive( buffer, RECV_BUFFER_SIZE ) == -1 )
+        {
+            mbed_printf( "Error during receive attempt\n" );
+            wait( 1.0 );
+        }
+close:        
+        connection.close();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Mon May 13 20:10:35 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#db1fc233faa9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon May 13 20:10:35 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/b3110cd2dd17
\ No newline at end of file