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