php access
Dependencies: EthernetInterface HTTPClient mbed-rtos mbed
Fork of SimpleXively by
php_access.cpp
- Committer:
- thursday1024
- Date:
- 2016-07-28
- Revision:
- 2:7cf2ef9c51da
- Parent:
- 1:3c8fcecce568
File content as of revision 2:7cf2ef9c51da:
// 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 buff[BUFFSIZE]; char str[256]; //sprintf( header, "ApiKey: %s\r\n", ch_name ) ; //http.setHeader( header ); 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, "%.2f", (*sp)/100.0 ); 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] } }