change official mbed lib and buffer size

Dependencies:   Servo WIZnetInterface mbed

Fork of My_Weatherforecast_WIZwiki-W7500 by Lawrence Lee

Committer:
joon874
Date:
Mon Jun 29 07:41:31 2015 +0000
Revision:
18:a02a73acd3c8
Parent:
17:ca0b0402a4fe
Child:
19:be84bee4118d
Using TCP Client with WIZwiki-W7500, display weather conditions on led and temperatures with servo-motor

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 18:a02a73acd3c8 45 char buffer[420];
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 18:a02a73acd3c8 68 printf("%c",weather_stu[i]);
joon874 17:ca0b0402a4fe 69 }
joon874 17:ca0b0402a4fe 70
joon874 17:ca0b0402a4fe 71 city = strstr(buffer, "name");
joon874 17:ca0b0402a4fe 72 printf("%.6s\n", city + 7);
joon874 17:ca0b0402a4fe 73 for(int k=0; k<6;k++){
joon874 17:ca0b0402a4fe 74 city_name[k] = city[k+7];
joon874 17:ca0b0402a4fe 75 printf("%c",city_name[k]);
joon874 17:ca0b0402a4fe 76 }
joon874 17:ca0b0402a4fe 77
joon874 17:ca0b0402a4fe 78 tempure = strstr(buffer, "temp");
joon874 17:ca0b0402a4fe 79 printf("%.3s\n", tempure + 6);
joon874 17:ca0b0402a4fe 80 for(int j=0; j<6;j++){
joon874 17:ca0b0402a4fe 81 tempure_data[j] = tempure[j+6];
joon874 17:ca0b0402a4fe 82 printf("%c",tempure_data[j]);
joon874 17:ca0b0402a4fe 83 }
joon874 17:ca0b0402a4fe 84
joon874 17:ca0b0402a4fe 85 /*tempurature display */
joon874 17:ca0b0402a4fe 86 float data[2]={0};
joon874 17:ca0b0402a4fe 87 data[0] = tempure_data[1]-'7';
joon874 17:ca0b0402a4fe 88 data[1] = tempure_data[2]-'3';
joon874 17:ca0b0402a4fe 89
joon874 17:ca0b0402a4fe 90 myservo = (data[0]*10+data[1])/40;
joon874 17:ca0b0402a4fe 91
joon874 17:ca0b0402a4fe 92 printf("%f",(data[0]*10+data[1])/40);
joon874 17:ca0b0402a4fe 93
joon874 17:ca0b0402a4fe 94 /* weather display */
joon874 17:ca0b0402a4fe 95 if(strcmp(weather_stu,"Clo")==0) {
joon874 17:ca0b0402a4fe 96 rled = 1;
joon874 17:ca0b0402a4fe 97 gled = 1;
joon874 17:ca0b0402a4fe 98 bled = 1;
joon874 17:ca0b0402a4fe 99 }else if(strcmp(weather_stu,"Rai")==0) {
joon874 17:ca0b0402a4fe 100 rled = 0;
joon874 17:ca0b0402a4fe 101 gled = 0;
joon874 17:ca0b0402a4fe 102 bled = 1;
joon874 17:ca0b0402a4fe 103 }else if(strcmp(weather_stu,"Cle")==0){
joon874 17:ca0b0402a4fe 104 rled = 1;
joon874 17:ca0b0402a4fe 105 gled = 1;
joon874 17:ca0b0402a4fe 106 bled = 0;
joon874 18:a02a73acd3c8 107 }else if(strcmp(weather_stu,"Mis")==0){
joon874 18:a02a73acd3c8 108 rled = 1;
joon874 18:a02a73acd3c8 109 gled = 0;
joon874 18:a02a73acd3c8 110 bled = 1;
joon874 18:a02a73acd3c8 111 }else if(strcmp(weather_stu,"Haz")==0) {
joon874 18:a02a73acd3c8 112 rled = 1;
joon874 18:a02a73acd3c8 113 gled = 1;
joon874 18:a02a73acd3c8 114 bled = 1;
joon874 18:a02a73acd3c8 115 }else if(strcmp(weather_stu,"Fog")==0){
joon874 18:a02a73acd3c8 116 rled = 1;
joon874 18:a02a73acd3c8 117 gled = 0;
joon874 18:a02a73acd3c8 118 bled = 1;
joon874 17:ca0b0402a4fe 119 }else {
joon874 17:ca0b0402a4fe 120 rled = 0;
joon874 18:a02a73acd3c8 121 gled = 0;
joon874 17:ca0b0402a4fe 122 bled = 0;
joon874 18:a02a73acd3c8 123 }
joon874 17:ca0b0402a4fe 124
emilmont 7:65188f4a8c25 125 sock.close();
donatien 0:bb128f0e952f 126
emilmont 7:65188f4a8c25 127 eth.disconnect();
donatien 5:01f6c3e112af 128
joon874 17:ca0b0402a4fe 129 wait(60.0);
joon874 17:ca0b0402a4fe 130 };
joon874 17:ca0b0402a4fe 131
joon874 17:ca0b0402a4fe 132 }