still need some modification

Dependencies:   mbed-http DebounceIn PinDetect OneButton

Files at this revision

API Documentation at this revision

Comitter:
nadaanas1985
Date:
Mon May 06 11:24:39 2019 +0000
Parent:
1:1a06bde4e0db
Commit message:
updated ip

Changed in this revision

ECH_V004.cpp Show annotated file Show diff for this revision Revisions of this file
network-helper.h Show annotated file Show diff for this revision Revisions of this file
diff -r 1a06bde4e0db -r 1d2a43e66b41 ECH_V004.cpp
--- a/ECH_V004.cpp	Wed Apr 03 11:55:23 2019 +0000
+++ b/ECH_V004.cpp	Mon May 06 11:24:39 2019 +0000
@@ -233,136 +233,148 @@
     
     
     int state = STATE_0;
-
-    //network setup
-    NetworkInterface* network = connect_to_default_network_interface();
-    if (!network)
+    while (true) 
     {
-        printf("Cannot connect to the network, see serial output\n");
-                //return 1;
-    }
-    if(network)
-    myled=1;
-
-    while (true) {
-
-
-        switch(state) {
-            case STATE_0:
-                osEvent evt = queue.get();
-                if (evt.status == osEventMessage) 
-                {
-                    message_t *message = (message_t*)evt.value.p;
-
-
-                    if(message->event == BUTTON_PRESS_1) 
-                    {
-                        printf("HttpRequest Sending");
-                        printf(network->get_gateway);
-                        HttpRequest* post_req = new HttpRequest(network, HTTP_POST, "http://192.168.0.57:5500/mch/kick");
-                        
-                        post_req->set_header("Content-Type", "application/json");
-                     
-                        
-                        const char body[] = "{\"hello\":\"Nada\"}";
-                            
-                        HttpResponse* post_res = post_req->send(body, strlen(body));
-                        if (!post_res)
+        Thread::wait(4000);
+        
+        //network setup
+        NetworkInterface* network = connect_to_default_network_interface();
+        if (!network)
+        {
+            printf("Cannot connect to the network, see serial output\n");
+                    //return 1;
+            for(int j = 0 ; j<20;j++)
+            {
+                led4=1;
+                Thread::wait(100);
+                led4=0;
+                Thread::wait(100);
+            }
+        }
+        else
+        {
+            led4=1;
+        
+            while (true) {
+        
+        
+                switch(state) {
+                    case STATE_0:
+                        osEvent evt = queue.get();
+                        if (evt.status == osEventMessage) 
                         {
-                            printf("HttpRequest failed (error code %d)\n", post_req->get_error());
-                           // return 1;
-                           
-                            button_press_2 = 0;
-                            button_press_1 = 0;
-                        }
-                        else
-                        {
-                        
-                            printf("\n----- HTTP POST response 1-----\n");
-                            
-                            dump_response_1(post_res);
-                            
-                            //Thread::wait(5000);
-                            
-
+                            message_t *message = (message_t*)evt.value.p;
+        
+        
+                            if(message->event == BUTTON_PRESS_1) 
+                            {
+                                printf("HttpRequest Sending");
+                                //printf(network->get_gateway);
+                                HttpRequest* post_req = new HttpRequest(network, HTTP_POST, "http://10.5.248.2:5600/mch/kick");
+                                
+                                post_req->set_header("Content-Type", "application/json");
+                             
+                                
+                                const char body[] = "{\"hello\":\"Nada\"}";
+                                    
+                                HttpResponse* post_res = post_req->send(body, strlen(body));
+                                if (!post_res)
+                                {
+                                    printf("HttpRequest failed (error code %d)\n", post_req->get_error());
+                                   // return 1;
+                                   
+                                    button_press_2 = 0;
+                                    button_press_1 = 0;
+                                }
+                                else
+                                {
                                 
-                             delete post_req;
-                         }
-                         
-                         state = STATE_0;
-                    }
-                    else if(message->event == BUTTON_PRESS_2) 
-                    {
-                        
-                        HttpRequest* post_req = new HttpRequest(network, HTTP_POST, "http://192.168.0.57:5500/mch/call");
-                        
-                        post_req->set_header("Content-Type", "application/json");
-                     
-                        
-                        const char body[] = "{\"hello\":\"World\"}";
+                                    printf("\n----- HTTP POST response 1-----\n");
+                                    
+                                    dump_response_1(post_res);
+                                    
+                                    //Thread::wait(5000);
+                                    
+        
+                                        
+                                     delete post_req;
+                                 }
+                                 
+                                 state = STATE_0;
+                            }
+                            else if(message->event == BUTTON_PRESS_2) 
+                            {
+                                
+                                HttpRequest* post_req = new HttpRequest(network, HTTP_POST, "http://10.5.248.2:5600/mch/call");
+                                
+                                post_req->set_header("Content-Type", "application/json");
+                             
+                                
+                                const char body[] = "{\"hello\":\"World\"}";
+                                    
+                                HttpResponse* post_res = post_req->send(body, strlen(body));
+                                if (!post_res)
+                                {
+                                    printf("HttpRequest failed (error code %d)\n", post_req->get_error());
+                                   // return 1;
+                                   
+                                    button_press_2 = 0;
+                                    button_press_1 = 0;                           
+                                }
+                                else
+                                {
                             
-                        HttpResponse* post_res = post_req->send(body, strlen(body));
-                        if (!post_res)
-                        {
-                            printf("HttpRequest failed (error code %d)\n", post_req->get_error());
-                           // return 1;
-                           
-                            button_press_2 = 0;
-                            button_press_1 = 0;                           
-                        }
-                        else
-                        {
+                                    printf("\n----- HTTP POST response 2-----\n");
+                                    
+                                    dump_response_2(post_res);
+                                        
+                                    delete post_req;
+                                    //Thread::wait(5000);
+                                    
+        
+        
                     
-                            printf("\n----- HTTP POST response 2-----\n");
-                            
-                            dump_response_2(post_res);
-                                
-                            delete post_req;
-                            //Thread::wait(5000);
-                            
-
-
-            
+                                }
+                                 state = STATE_0;
+                            }
+        
+                            mpool.free(message);
                         }
-                         state = STATE_0;
-                    }
-
-                    mpool.free(message);
-                }
-
-                timer.start(15000);
-
-                break;
-
-            case STATE_1:
-
-                evt = queue.get();
-                if (evt.status == osEventMessage) 
-                {
-                    message_t *message = (message_t*)evt.value.p;
-
-
-                    if(message->event == BUTTON_PRESS_1) 
-                    {
-                        
-                        state = STATE_0;
-                    }
-                    
-                    mpool.free(message);
-                }
-
-                timer.start(10000);
-
-                break;
-
-
-        }//End of switch
-
-        //toggle led for local testing
-        //led2= !led2;
-
-    }//end of while(1)
-            
+        
+                        timer.start(15000);
+        
+                        break;
+        
+                    case STATE_1:
+        
+                        evt = queue.get();
+                        if (evt.status == osEventMessage) 
+                        {
+                            message_t *message = (message_t*)evt.value.p;
+        
+        
+                            if(message->event == BUTTON_PRESS_1) 
+                            {
+                                
+                                state = STATE_0;
+                            }
+                            
+                            mpool.free(message);
+                        }
+        
+                        timer.start(10000);
+        
+                        break;
+        
+        
+                }//End of switch
+        
+                //toggle led for local testing
+                //led2= !led2;
+        
+            }//end of while(1)
+        }
+    }            
 }
 
 #endif
diff -r 1a06bde4e0db -r 1d2a43e66b41 network-helper.h
--- a/network-helper.h	Wed Apr 03 11:55:23 2019 +0000
+++ b/network-helper.h	Mon May 06 11:24:39 2019 +0000
@@ -13,7 +13,7 @@
     printf("[NWKH] Connecting to network...\n");
 
     NetworkInterface* network = NetworkInterface::get_default_instance();
-     network->set_network("192.168.1.97","255.255.252.0","192.168.0.1");
+     network->set_network("10.5.254.91","255.255.248.0","10.5.248.1");
 
     if (!network) {
         printf("[NWKH] No network interface found, select an interface in 'network-helper.h'\n");