bus

Dependencies:   Servo WIZnetInterface mbed-src

Fork of My_Weatherforecast_WIZwiki-W7500 by Lawrence Lee

Files at this revision

API Documentation at this revision

Comitter:
joon874
Date:
Thu Jun 25 23:54:47 2015 +0000
Parent:
14:72be2b8b7f24
Commit message:
Using TCP client, do have your own weatherforecast

Changed in this revision

EthernetInterface.lib Show diff for this revision Revisions of this file
Servo.lib Show annotated file Show diff for this revision Revisions of this file
WIZnetInterface.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show diff for this revision Revisions of this file
mbed-src.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show diff for this revision Revisions of this file
--- a/EthernetInterface.lib	Wed May 14 15:07:26 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/#097a9996f8d5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Servo.lib	Thu Jun 25 23:54:47 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/Servo/#36b69a7ced07
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WIZnetInterface.lib	Thu Jun 25 23:54:47 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/WIZnet/code/WIZnetInterface/#6bf73f3f341c
--- a/main.cpp	Wed May 14 15:07:26 2014 +0000
+++ b/main.cpp	Thu Jun 25 23:54:47 2015 +0000
@@ -1,31 +1,119 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
+#include "Servo.h"
+
+DigitalOut bled(D6);
+DigitalOut gled(D5);
+DigitalOut rled(D4);
+
+Servo myservo(D15);
 
 int main() {
+   
+    int phy_link;
+    printf("Wait a second...\r\n");
+    uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02}; 
+    
     EthernetInterface eth;
-    eth.init(); //Use DHCP
+    eth.init(mac_addr); //Use DHCP
+    
+    while(1){
+    
     eth.connect();
-    printf("IP Address is %s\n", eth.getIPAddress());
     
+    /* phy link */
+     do{
+        phy_link = eth.ethernet_link();
+        printf("...");
+        wait(2);
+     }while(!phy_link);
+     printf("\r\n");
+     
+    printf("IP Address is %s\r\n", eth.getIPAddress());
+    
+    /* TCP socket connect */
     TCPSocketConnection sock;
-    sock.connect("mbed.org", 80);
+    sock.connect("api.openweathermap.org", 80);
     
-    char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
+    /* weather */
+    char http_cmd[] = "GET /data/2.5/weather?q=Seoul,kr HTTP/1.0\n\n";
+    //char http_cmd[] = "GET /data/2.5/weather?q=London,uk HTTP/1.0\n\n";
+    //char http_cmd[] = "GET /data/2.5/weather?q=Berlin,de HTTP/1.0\n\n";
     sock.send_all(http_cmd, sizeof(http_cmd)-1);
     
-    char buffer[300];
+    /* get info */
+    char buffer[500];
     int ret;
     while (true) {
         ret = sock.receive(buffer, sizeof(buffer)-1);
         if (ret <= 0)
             break;
         buffer[ret] = '\0';
-        printf("Received %d chars from server:\n%s\n", ret, buffer);
+        printf("Received %d chars from server: %s\n", ret, buffer);     
     }
-      
+
+    /* get weather, city, tempurature */
+    char *weather;
+    char *city;
+    char *tempure;
+    
+    char weather_stu[3];
+    char city_name[6];
+    char tempure_data[6];
+    
+   weather = strstr(buffer, "main");
+        printf("%.4s\n", weather + 7);
+        for(int i=0; i<3;i++){
+            weather_stu[i] = weather[i+7];
+       }
+   
+   city = strstr(buffer, "name");
+        printf("%.6s\n", city + 7);
+        for(int k=0; k<6;k++){
+            city_name[k] = city[k+7];
+            printf("%c",city_name[k]);
+        }
+ 
+   tempure = strstr(buffer, "temp");
+        printf("%.3s\n", tempure + 6);
+        for(int j=0; j<6;j++){
+            tempure_data[j] = tempure[j+6];
+            printf("%c",tempure_data[j]);
+        }
+        
+        /*tempurature display */ 
+        float data[2]={0};
+        data[0] = tempure_data[1]-'7';
+        data[1] = tempure_data[2]-'3';
+        
+        myservo = (data[0]*10+data[1])/40;
+
+        printf("%f",(data[0]*10+data[1])/40);
+   
+   /* weather display */
+   if(strcmp(weather_stu,"Clo")==0) {
+        rled = 1; 
+        gled = 1; 
+        bled = 1;
+    }else if(strcmp(weather_stu,"Rai")==0) {
+        rled = 0; 
+        gled = 0;
+        bled = 1; 
+    }else if(strcmp(weather_stu,"Cle")==0){
+        rled = 1; 
+        gled = 1;
+        bled = 0; 
+    }else {
+        rled = 0;
+        bled = 0;
+        gled = 0;
+        }
+
     sock.close();
     
     eth.disconnect();
     
-    while(1) {}
+    wait(60.0);
+   };
+
 }
--- a/mbed-rtos.lib	Wed May 14 15:07:26 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#5dfe422a963d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-src.lib	Thu Jun 25 23:54:47 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-src/#30f9462b5296
--- a/mbed.bld	Wed May 14 15:07:26 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/8a40adfe8776
\ No newline at end of file