php access with authentication

Dependencies:   EthernetInterface HTTPClient mbed-rtos mbed

Fork of SimpleXively by wolf SSL

Revision:
1:87481e00f41f
Parent:
0:a6ee4ada0d57
--- a/main.cpp	Mon Dec 08 12:15:57 2014 +0000
+++ b/main.cpp	Thu Jul 30 07:31:26 2015 +0000
@@ -1,90 +1,70 @@
-/* main.cpp
- *
- * Copyright (C) 2006-2014 wolfSSL Inc.
- *
- * This file is part of CyaSSL.
- *
- * CyaSSL is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * CyaSSL is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-#include "mbed.h"
+// php_acces main.cpp
+ 
+#include "mbed.h" 
 #include "EthernetInterface.h"
 #include "HTTPClient.h"
-
-#define KEYS "https://192.168.49.57/574d76fcb/keys.txt"
+#define BUFF_SIZE 128
 
-#define BUFFSIZE (50+1)
+extern void php_access_main( char *uri, char *ch_name, int* sp );
+char php_uri[]="https://alpha.c.dendai.ac.jp/plot_auth/save_data.php"; 
 
-extern void xively_main(char *feed_id, char *api_key, char *ch_name) ;
+char ch_str[] ="ch13894";
 
 extern HTTPClient http;
 EthernetInterface eth;
 
-void thread_main(void const *av)
-{
-    int ret ; 
-    int i ;
-    char recvBuff[BUFFSIZE*6] ;
-    char dummy1[BUFFSIZE], dummy2[BUFFSIZE], dummy3[BUFFSIZE], dummy4[BUFFSIZE] ;
-    char feed_id[BUFFSIZE] ;
-    char api_key[BUFFSIZE] ;
-    char ch_name[BUFFSIZE] ;
-  
-    memset(recvBuff, '\0', sizeof(recvBuff)) ;
-    ret = http.get(KEYS, recvBuff, sizeof(recvBuff));
-    if (ret) {
-        printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
-        return ;
-    }
+static int speed=0;
+void thread_main( void const *av ){
+    char ch_name[BUFF_SIZE];
+    strcpy( ch_name, ch_str );
+    printf( "Channel Name:%s\n", ch_name );
+    
+    php_access_main( php_uri, ch_name, &speed ); // 
+    
+    while(true) Thread::wait(1000);
+}
+
+// memo
+// R-LED -> LED1; G-LED -> LED2; B-LED -> LED3;
+// sw3 -> PTA4; sw2 -> PTC6;
+
+DigitalOut my_LED0(LED1);
+DigitalOut my_LED1(LED3);
+DigitalOut my_LED2(LED2);
+DigitalIn  my_sw0(PTA4); 
+DigitalIn  my_sw1(PTC6); 
 
-    sscanf(recvBuff, "%50s\n%50s\n%50s\n%50s\n%50s\n%50s", feed_id, api_key,
-         dummy1, dummy2, dummy3, dummy4) ;
-    printf("ID=%s\nKey=%s\n",feed_id, api_key) ;
+int main() {
+    my_LED0=1;
+    my_LED1=1;
+    Timer t;
+    t.start();
     
-    printf("Channel Name:") ;
-    for(i=0; i<BUFFSIZE; i++) {
-        if((ch_name[i] = getchar()) == '\r') {
-            ch_name[i] = '\0' ;
-            putchar('\n') ;
-            break ;
-        } else putchar(ch_name[i]) ;
+    int ret = eth.init(); //Use DHCP
+    printf( "php_test Starting,...\n" ) ;
+    while(1) {
+        ret = eth.connect();
+        if( ret==0 )break ; // DHCP OK
+        Thread::wait( 100 );
     }
-    
-    xively_main(feed_id, api_key, ch_name) ;
+    t.stop();
+    srand(t.read_ms());
+
+    printf( "IP = %s\n", eth.getIPAddress() );
     
-    while (true) {
+    #define STACK_SIZE 20000
+    Thread thr( thread_main, NULL, osPriorityNormal, STACK_SIZE );
+    speed=0;
+    int i=0;
+    while(true){
+        if(!my_sw0 && speed<=0)speed++;
+        if(!my_sw1 && speed>=0)speed--;
+        if(speed>0 ){my_LED0=0;my_LED1=1;my_LED2=1;}
+        if(speed<0 ){my_LED0=1;my_LED1=0;my_LED2=1;}
+        if(speed==0){my_LED0=1;my_LED1=1;my_LED2=0;}
+        speed = (rand()%3)-1;
         Thread::wait(1000);
+        i++;
     }
 }
 
-int main() {
-    int ret ;
-    
-    ret = eth.init(); //Use DHCP
-    printf("Xively Starting,...\n") ;
-
-    while(1) {
-        ret = eth.connect();
-        if(ret == 0)break ;
-        Thread::wait(100);
-    }
-    printf("IP = %s\n", eth.getIPAddress());
-    
-    #define STACK_SIZE 20000
-    Thread t( thread_main, NULL, osPriorityNormal, STACK_SIZE);
-
-    while(1)
-        Thread::wait(1000) ;
-}