php access
Dependencies: EthernetInterface HTTPClient mbed-rtos mbed
Fork of SimpleXively by
php_access.cpp@1:3c8fcecce568, 2015-07-30 (annotated)
- Committer:
- thursday1024
- Date:
- Thu Jul 30 07:29:17 2015 +0000
- Revision:
- 1:3c8fcecce568
- Child:
- 2:7cf2ef9c51da
- Child:
- 3:f17ce0127553
php access
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thursday1024 | 1:3c8fcecce568 | 1 | // php_access php_access.cpp |
thursday1024 | 1:3c8fcecce568 | 2 | |
thursday1024 | 1:3c8fcecce568 | 3 | #include "mbed.h" |
thursday1024 | 1:3c8fcecce568 | 4 | #include "EthernetInterface.h" |
thursday1024 | 1:3c8fcecce568 | 5 | #include "HTTPClient.h" |
thursday1024 | 1:3c8fcecce568 | 6 | |
thursday1024 | 1:3c8fcecce568 | 7 | HTTPClient http; |
thursday1024 | 1:3c8fcecce568 | 8 | |
thursday1024 | 1:3c8fcecce568 | 9 | void php_access_main( char *uri, char *ch_name, int *sp ){ |
thursday1024 | 1:3c8fcecce568 | 10 | int ret ; |
thursday1024 | 1:3c8fcecce568 | 11 | int i ; |
thursday1024 | 1:3c8fcecce568 | 12 | #define BUFFSIZE 1024 |
thursday1024 | 1:3c8fcecce568 | 13 | static char buff[BUFFSIZE]; |
thursday1024 | 1:3c8fcecce568 | 14 | char str[256]; |
thursday1024 | 1:3c8fcecce568 | 15 | |
thursday1024 | 1:3c8fcecce568 | 16 | //sprintf( header, "ApiKey: %s\r\n", ch_name ) ; |
thursday1024 | 1:3c8fcecce568 | 17 | //http.setHeader( header ); |
thursday1024 | 1:3c8fcecce568 | 18 | int j=0; |
thursday1024 | 1:3c8fcecce568 | 19 | for( i=0; ; i++ ){ |
thursday1024 | 1:3c8fcecce568 | 20 | printf( "<<<< %d speed=%d data=%d >>>>\n", i, *sp, j ) ; |
thursday1024 | 1:3c8fcecce568 | 21 | //sprintf( uri, "%s", uri) ; |
thursday1024 | 1:3c8fcecce568 | 22 | |
thursday1024 | 1:3c8fcecce568 | 23 | //HTTPText outText( put_data, strlen(put_data) ); |
thursday1024 | 1:3c8fcecce568 | 24 | HTTPMap params; |
thursday1024 | 1:3c8fcecce568 | 25 | HTTPText inText( buff, BUFFSIZE ); |
thursday1024 | 1:3c8fcecce568 | 26 | |
thursday1024 | 1:3c8fcecce568 | 27 | sprintf( str, "%d", j+=*sp ); |
thursday1024 | 1:3c8fcecce568 | 28 | params.put("data", str ); |
thursday1024 | 1:3c8fcecce568 | 29 | params.put("ch", ch_name ); |
thursday1024 | 1:3c8fcecce568 | 30 | char str_sp[128]; sprintf( str_sp, "%d", *sp ); |
thursday1024 | 1:3c8fcecce568 | 31 | params.put("sp", str_sp ); |
thursday1024 | 1:3c8fcecce568 | 32 | char str_i[128]; sprintf( str_i, "%d", i ); |
thursday1024 | 1:3c8fcecce568 | 33 | params.put("x", str_i ); |
thursday1024 | 1:3c8fcecce568 | 34 | |
thursday1024 | 1:3c8fcecce568 | 35 | ret = http.post( uri, params, &inText ); // POST |
thursday1024 | 1:3c8fcecce568 | 36 | if( !ret ){ |
thursday1024 | 1:3c8fcecce568 | 37 | printf( "--- POST - read return data %d ---\n", strlen(buff) ); |
thursday1024 | 1:3c8fcecce568 | 38 | if( strlen(buff) )printf("Result: %s", buff); |
thursday1024 | 1:3c8fcecce568 | 39 | printf( "--- POST - end %d ---\n\n", strlen(buff) ); |
thursday1024 | 1:3c8fcecce568 | 40 | }else{ |
thursday1024 | 1:3c8fcecce568 | 41 | printf( "++ Err = %d - HTTP = %d ++\n", |
thursday1024 | 1:3c8fcecce568 | 42 | ret, http.getHTTPResponseCode() ); |
thursday1024 | 1:3c8fcecce568 | 43 | } |
thursday1024 | 1:3c8fcecce568 | 44 | wait(2.0); // sleep 5[s] |
thursday1024 | 1:3c8fcecce568 | 45 | } |
thursday1024 | 1:3c8fcecce568 | 46 | } |