php access with authentication

Dependencies:   EthernetInterface HTTPClient mbed-rtos mbed

Fork of SimpleXively by wolf SSL

Revision:
1:87481e00f41f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/php_access_auth.cpp	Thu Jul 30 07:31:26 2015 +0000
@@ -0,0 +1,49 @@
+// php_access php_access.cpp
+
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "HTTPClient.h"
+
+HTTPClient http;
+
+void php_access_main( char *uri, char *ch_name, int *sp ){
+    int ret ;
+    int i ;
+#define BUFFSIZE 1024
+static char AccountSid[]="ox2593is";
+static char AuthToken[] ="uo2yidix";
+    static char buff[BUFFSIZE];
+    char str[256];
+
+    //sprintf( header, "ApiKey: %s\r\n", ch_name ) ;
+    //http.setHeader( header );
+    http.basicAuth( AccountSid, AuthToken );
+    int j=0;
+    for( i=0; ; i++ ){
+        printf( "<<<< %d speed=%d data=%d >>>>\n", i, *sp, j ) ;
+        //sprintf( uri, "%s", uri) ;
+
+        //HTTPText outText( put_data, strlen(put_data) );
+        HTTPMap params;
+        HTTPText inText( buff, BUFFSIZE );
+        
+        sprintf( str, "%d", j+=*sp );
+        params.put("data", str );
+        params.put("ch", ch_name );
+        char str_sp[128]; sprintf( str_sp, "%d", *sp );
+        params.put("sp", str_sp );
+        char str_i[128]; sprintf( str_i, "%d", i );
+        params.put("x", str_i );
+
+        ret = http.post( uri, params, &inText ); // POST 
+        if( !ret ){
+            printf( "--- POST - read return data %d ---\n", strlen(buff) );
+            if( strlen(buff) )printf("Result: %s", buff);
+            printf( "--- POST - end %d ---\n\n", strlen(buff) );
+        }else{
+            printf( "++ Err = %d - HTTP = %d ++\n", 
+                ret, http.getHTTPResponseCode() );
+        }
+        wait(2.0); // sleep 5[s]
+    }
+}