change official mbed lib and buffer size

Dependencies:   Servo WIZnetInterface mbed

Fork of My_Weatherforecast_WIZwiki-W7500 by Lawrence Lee

Committer:
joon874
Date:
Fri Jun 26 00:05:31 2015 +0000
Revision:
17:ca0b0402a4fe
Parent:
11:59dcefdda506
Child:
18:a02a73acd3c8
Using TCP Client with WIZwiki-W7500, Have your own Weatherforecast.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:bb128f0e952f 1 #include "mbed.h"
donatien 0:bb128f0e952f 2 #include "EthernetInterface.h"
joon874 17:ca0b0402a4fe 3 #include "Servo.h"
joon874 17:ca0b0402a4fe 4
joon874 17:ca0b0402a4fe 5 DigitalOut bled(D6);
joon874 17:ca0b0402a4fe 6 DigitalOut gled(D5);
joon874 17:ca0b0402a4fe 7 DigitalOut rled(D4);
joon874 17:ca0b0402a4fe 8
joon874 17:ca0b0402a4fe 9 Servo myservo(D15);
donatien 0:bb128f0e952f 10
emilmont 7:65188f4a8c25 11 int main() {
joon874 17:ca0b0402a4fe 12
joon874 17:ca0b0402a4fe 13 int phy_link;
joon874 17:ca0b0402a4fe 14 printf("Wait a second...\r\n");
joon874 17:ca0b0402a4fe 15 uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02};
joon874 17:ca0b0402a4fe 16
donatien 0:bb128f0e952f 17 EthernetInterface eth;
joon874 17:ca0b0402a4fe 18 eth.init(mac_addr); //Use DHCP
joon874 17:ca0b0402a4fe 19
joon874 17:ca0b0402a4fe 20 while(1){
joon874 17:ca0b0402a4fe 21
donatien 0:bb128f0e952f 22 eth.connect();
donatien 0:bb128f0e952f 23
joon874 17:ca0b0402a4fe 24 /* phy link */
joon874 17:ca0b0402a4fe 25 do{
joon874 17:ca0b0402a4fe 26 phy_link = eth.ethernet_link();
joon874 17:ca0b0402a4fe 27 printf("...");
joon874 17:ca0b0402a4fe 28 wait(2);
joon874 17:ca0b0402a4fe 29 }while(!phy_link);
joon874 17:ca0b0402a4fe 30 printf("\r\n");
joon874 17:ca0b0402a4fe 31
joon874 17:ca0b0402a4fe 32 printf("IP Address is %s\r\n", eth.getIPAddress());
joon874 17:ca0b0402a4fe 33
joon874 17:ca0b0402a4fe 34 /* TCP socket connect */
emilmont 7:65188f4a8c25 35 TCPSocketConnection sock;
joon874 17:ca0b0402a4fe 36 sock.connect("api.openweathermap.org", 80);
donatien 0:bb128f0e952f 37
joon874 17:ca0b0402a4fe 38 /* weather */
joon874 17:ca0b0402a4fe 39 char http_cmd[] = "GET /data/2.5/weather?q=Seoul,kr HTTP/1.0\n\n";
joon874 17:ca0b0402a4fe 40 //char http_cmd[] = "GET /data/2.5/weather?q=London,uk HTTP/1.0\n\n";
joon874 17:ca0b0402a4fe 41 //char http_cmd[] = "GET /data/2.5/weather?q=Berlin,de HTTP/1.0\n\n";
emilmont 11:59dcefdda506 42 sock.send_all(http_cmd, sizeof(http_cmd)-1);
emilmont 7:65188f4a8c25 43
joon874 17:ca0b0402a4fe 44 /* get info */
joon874 17:ca0b0402a4fe 45 char buffer[500];
donatien 0:bb128f0e952f 46 int ret;
emilmont 7:65188f4a8c25 47 while (true) {
emilmont 9:4757a976148d 48 ret = sock.receive(buffer, sizeof(buffer)-1);
emilmont 7:65188f4a8c25 49 if (ret <= 0)
emilmont 7:65188f4a8c25 50 break;
emilmont 9:4757a976148d 51 buffer[ret] = '\0';
joon874 17:ca0b0402a4fe 52 printf("Received %d chars from server: %s\n", ret, buffer);
emilmont 7:65188f4a8c25 53 }
joon874 17:ca0b0402a4fe 54
joon874 17:ca0b0402a4fe 55 /* get weather, city, tempurature */
joon874 17:ca0b0402a4fe 56 char *weather;
joon874 17:ca0b0402a4fe 57 char *city;
joon874 17:ca0b0402a4fe 58 char *tempure;
joon874 17:ca0b0402a4fe 59
joon874 17:ca0b0402a4fe 60 char weather_stu[3];
joon874 17:ca0b0402a4fe 61 char city_name[6];
joon874 17:ca0b0402a4fe 62 char tempure_data[6];
joon874 17:ca0b0402a4fe 63
joon874 17:ca0b0402a4fe 64 weather = strstr(buffer, "main");
joon874 17:ca0b0402a4fe 65 printf("%.4s\n", weather + 7);
joon874 17:ca0b0402a4fe 66 for(int i=0; i<3;i++){
joon874 17:ca0b0402a4fe 67 weather_stu[i] = weather[i+7];
joon874 17:ca0b0402a4fe 68 }
joon874 17:ca0b0402a4fe 69
joon874 17:ca0b0402a4fe 70 city = strstr(buffer, "name");
joon874 17:ca0b0402a4fe 71 printf("%.6s\n", city + 7);
joon874 17:ca0b0402a4fe 72 for(int k=0; k<6;k++){
joon874 17:ca0b0402a4fe 73 city_name[k] = city[k+7];
joon874 17:ca0b0402a4fe 74 printf("%c",city_name[k]);
joon874 17:ca0b0402a4fe 75 }
joon874 17:ca0b0402a4fe 76
joon874 17:ca0b0402a4fe 77 tempure = strstr(buffer, "temp");
joon874 17:ca0b0402a4fe 78 printf("%.3s\n", tempure + 6);
joon874 17:ca0b0402a4fe 79 for(int j=0; j<6;j++){
joon874 17:ca0b0402a4fe 80 tempure_data[j] = tempure[j+6];
joon874 17:ca0b0402a4fe 81 printf("%c",tempure_data[j]);
joon874 17:ca0b0402a4fe 82 }
joon874 17:ca0b0402a4fe 83
joon874 17:ca0b0402a4fe 84 /*tempurature display */
joon874 17:ca0b0402a4fe 85 float data[2]={0};
joon874 17:ca0b0402a4fe 86 data[0] = tempure_data[1]-'7';
joon874 17:ca0b0402a4fe 87 data[1] = tempure_data[2]-'3';
joon874 17:ca0b0402a4fe 88
joon874 17:ca0b0402a4fe 89 myservo = (data[0]*10+data[1])/40;
joon874 17:ca0b0402a4fe 90
joon874 17:ca0b0402a4fe 91 printf("%f",(data[0]*10+data[1])/40);
joon874 17:ca0b0402a4fe 92
joon874 17:ca0b0402a4fe 93 /* weather display */
joon874 17:ca0b0402a4fe 94 if(strcmp(weather_stu,"Clo")==0) {
joon874 17:ca0b0402a4fe 95 rled = 1;
joon874 17:ca0b0402a4fe 96 gled = 1;
joon874 17:ca0b0402a4fe 97 bled = 1;
joon874 17:ca0b0402a4fe 98 }else if(strcmp(weather_stu,"Rai")==0) {
joon874 17:ca0b0402a4fe 99 rled = 0;
joon874 17:ca0b0402a4fe 100 gled = 0;
joon874 17:ca0b0402a4fe 101 bled = 1;
joon874 17:ca0b0402a4fe 102 }else if(strcmp(weather_stu,"Cle")==0){
joon874 17:ca0b0402a4fe 103 rled = 1;
joon874 17:ca0b0402a4fe 104 gled = 1;
joon874 17:ca0b0402a4fe 105 bled = 0;
joon874 17:ca0b0402a4fe 106 }else {
joon874 17:ca0b0402a4fe 107 rled = 0;
joon874 17:ca0b0402a4fe 108 bled = 0;
joon874 17:ca0b0402a4fe 109 gled = 0;
joon874 17:ca0b0402a4fe 110 }
joon874 17:ca0b0402a4fe 111
emilmont 7:65188f4a8c25 112 sock.close();
donatien 0:bb128f0e952f 113
emilmont 7:65188f4a8c25 114 eth.disconnect();
donatien 5:01f6c3e112af 115
joon874 17:ca0b0402a4fe 116 wait(60.0);
joon874 17:ca0b0402a4fe 117 };
joon874 17:ca0b0402a4fe 118
joon874 17:ca0b0402a4fe 119 }