change official mbed lib and buffer size

Dependencies:   Servo WIZnetInterface mbed

Fork of My_Weatherforecast_WIZwiki-W7500 by Lawrence Lee

Committer:
joon874
Date:
Tue Nov 10 11:15:39 2015 +0000
Revision:
21:52e70a564a2b
Parent:
20:8d57b80e24aa
openweathermap.org api format changed

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 20:8d57b80e24aa 39
joon874 20:8d57b80e24aa 40 //char http_cmd[] = "GET /data/2.5/weather?id=2172797 HTTP/1.0\n\n";
joon874 20:8d57b80e24aa 41 //char http_cmd[] = "GET /data/2.5/weather?q=Seoul,kr HTTP/1.0\n\n";
joon874 20:8d57b80e24aa 42 char http_cmd[] = "GET /data/2.5/weather?q=London,uk,&appid=2de143494c0b295cca9337e1e96b00e0 HTTP/1.0\r\n\r\n";
joon874 17:ca0b0402a4fe 43 //char http_cmd[] = "GET /data/2.5/weather?q=Berlin,de HTTP/1.0\n\n";
emilmont 11:59dcefdda506 44 sock.send_all(http_cmd, sizeof(http_cmd)-1);
emilmont 7:65188f4a8c25 45
joon874 17:ca0b0402a4fe 46 /* get info */
joon874 19:be84bee4118d 47 char buffer[1024];
donatien 0:bb128f0e952f 48 int ret;
emilmont 7:65188f4a8c25 49 while (true) {
emilmont 9:4757a976148d 50 ret = sock.receive(buffer, sizeof(buffer)-1);
emilmont 7:65188f4a8c25 51 if (ret <= 0)
emilmont 7:65188f4a8c25 52 break;
emilmont 9:4757a976148d 53 buffer[ret] = '\0';
joon874 17:ca0b0402a4fe 54 printf("Received %d chars from server: %s\n", ret, buffer);
emilmont 7:65188f4a8c25 55 }
joon874 17:ca0b0402a4fe 56
joon874 17:ca0b0402a4fe 57 /* get weather, city, tempurature */
joon874 17:ca0b0402a4fe 58 char *weather;
joon874 17:ca0b0402a4fe 59 char *city;
joon874 17:ca0b0402a4fe 60 char *tempure;
joon874 17:ca0b0402a4fe 61
joon874 17:ca0b0402a4fe 62 char weather_stu[3];
joon874 17:ca0b0402a4fe 63 char city_name[6];
joon874 17:ca0b0402a4fe 64 char tempure_data[6];
joon874 17:ca0b0402a4fe 65
joon874 17:ca0b0402a4fe 66 weather = strstr(buffer, "main");
joon874 17:ca0b0402a4fe 67 printf("%.4s\n", weather + 7);
joon874 17:ca0b0402a4fe 68 for(int i=0; i<3;i++){
joon874 17:ca0b0402a4fe 69 weather_stu[i] = weather[i+7];
joon874 18:a02a73acd3c8 70 printf("%c",weather_stu[i]);
joon874 17:ca0b0402a4fe 71 }
joon874 17:ca0b0402a4fe 72
joon874 17:ca0b0402a4fe 73 city = strstr(buffer, "name");
joon874 17:ca0b0402a4fe 74 printf("%.6s\n", city + 7);
joon874 17:ca0b0402a4fe 75 for(int k=0; k<6;k++){
joon874 17:ca0b0402a4fe 76 city_name[k] = city[k+7];
joon874 17:ca0b0402a4fe 77 printf("%c",city_name[k]);
joon874 17:ca0b0402a4fe 78 }
joon874 17:ca0b0402a4fe 79
joon874 17:ca0b0402a4fe 80 tempure = strstr(buffer, "temp");
joon874 17:ca0b0402a4fe 81 printf("%.3s\n", tempure + 6);
joon874 17:ca0b0402a4fe 82 for(int j=0; j<6;j++){
joon874 17:ca0b0402a4fe 83 tempure_data[j] = tempure[j+6];
joon874 17:ca0b0402a4fe 84 printf("%c",tempure_data[j]);
joon874 17:ca0b0402a4fe 85 }
joon874 17:ca0b0402a4fe 86
joon874 17:ca0b0402a4fe 87 /*tempurature display */
joon874 17:ca0b0402a4fe 88 float data[2]={0};
joon874 17:ca0b0402a4fe 89 data[0] = tempure_data[1]-'7';
joon874 17:ca0b0402a4fe 90 data[1] = tempure_data[2]-'3';
joon874 17:ca0b0402a4fe 91
joon874 17:ca0b0402a4fe 92 myservo = (data[0]*10+data[1])/40;
joon874 17:ca0b0402a4fe 93
joon874 17:ca0b0402a4fe 94 printf("%f",(data[0]*10+data[1])/40);
joon874 17:ca0b0402a4fe 95
joon874 17:ca0b0402a4fe 96 /* weather display */
joon874 17:ca0b0402a4fe 97 if(strcmp(weather_stu,"Clo")==0) {
joon874 17:ca0b0402a4fe 98 rled = 1;
joon874 17:ca0b0402a4fe 99 gled = 1;
joon874 17:ca0b0402a4fe 100 bled = 1;
joon874 17:ca0b0402a4fe 101 }else if(strcmp(weather_stu,"Rai")==0) {
joon874 17:ca0b0402a4fe 102 rled = 0;
joon874 17:ca0b0402a4fe 103 gled = 0;
joon874 17:ca0b0402a4fe 104 bled = 1;
joon874 17:ca0b0402a4fe 105 }else if(strcmp(weather_stu,"Cle")==0){
joon874 17:ca0b0402a4fe 106 rled = 1;
joon874 17:ca0b0402a4fe 107 gled = 1;
joon874 17:ca0b0402a4fe 108 bled = 0;
joon874 18:a02a73acd3c8 109 }else if(strcmp(weather_stu,"Mis")==0){
joon874 18:a02a73acd3c8 110 rled = 1;
joon874 18:a02a73acd3c8 111 gled = 0;
joon874 18:a02a73acd3c8 112 bled = 1;
joon874 18:a02a73acd3c8 113 }else if(strcmp(weather_stu,"Haz")==0) {
joon874 18:a02a73acd3c8 114 rled = 1;
joon874 18:a02a73acd3c8 115 gled = 1;
joon874 18:a02a73acd3c8 116 bled = 1;
joon874 18:a02a73acd3c8 117 }else if(strcmp(weather_stu,"Fog")==0){
joon874 18:a02a73acd3c8 118 rled = 1;
joon874 18:a02a73acd3c8 119 gled = 0;
joon874 18:a02a73acd3c8 120 bled = 1;
joon874 17:ca0b0402a4fe 121 }else {
joon874 17:ca0b0402a4fe 122 rled = 0;
joon874 18:a02a73acd3c8 123 gled = 0;
joon874 17:ca0b0402a4fe 124 bled = 0;
joon874 18:a02a73acd3c8 125 }
joon874 17:ca0b0402a4fe 126
emilmont 7:65188f4a8c25 127 sock.close();
donatien 0:bb128f0e952f 128
emilmont 7:65188f4a8c25 129 eth.disconnect();
donatien 5:01f6c3e112af 130
joon874 17:ca0b0402a4fe 131 wait(60.0);
joon874 17:ca0b0402a4fe 132 };
joon874 17:ca0b0402a4fe 133
joon874 17:ca0b0402a4fe 134 }