weather forecast WIZwiki-W7500 for academy
Dependencies: Adafruit_GFX WIZnetInterface mbed
Fork of Weather_Forecast_Helloworld_WIZwiki-W7500 by
Revision 17:bf1228469a6c, committed 2017-06-15
- Comitter:
- jcm931213
- Date:
- Thu Jun 15 05:06:26 2017 +0000
- Parent:
- 16:60040aaa87df
- Commit message:
- revert
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 60040aaa87df -r bf1228469a6c main.cpp --- a/main.cpp Tue Jun 13 04:12:33 2017 +0000 +++ b/main.cpp Thu Jun 15 05:06:26 2017 +0000 @@ -3,8 +3,9 @@ #include "Adafruit_SSD1306.h" // W7500 onboard LED & Init +DigitalOut rled(LED1,1); DigitalOut gled(LED2,0); - +DigitalOut bled(LED3,1); // I2C Class I2C i2c(PA_10,PA_9); @@ -19,6 +20,47 @@ TCPSocketConnection sock; +// LED desplay functions +void clean(){ + rled = 0; gled = 0; bled = 0; +} +void clouds(){ + rled = 1; gled = 1; bled = 1; +} +void thunderstorm(){ + while(1){ + rled = 0; gled = 0; bled = 0; + wait(0.5); + rled = 1; gled = 1; bled = 1; + wait(0.5); + }; +} +void rain(){ + rled = 1; gled = 1; bled = 0; +} +void mist(){ + while(1){ + rled = 1; gled = 1; bled = 0; + wait(0.5); + rled = 1; gled = 1; bled = 1; + wait(0.5); + }; +} +void haze(){ + rled = 0; gled = 1; bled = 0; +} +void fog(){ + while(1){ + rled = 1; gled = 0; bled = 0; + wait(1.0); + rled = 1; gled = 1; bled = 0; + wait(1.0); + }; +} +void error(){ + rled = 1; gled = 1; bled = 1; +} + int main() { @@ -29,55 +71,43 @@ uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0xff, 0xff, 0x25}; eth.init(mac_addr); //Use DHCP - - // phy link - do{ - phy_link = eth.ethernet_link(); - printf("..."); - wait(2); - }while(!phy_link); - printf("\r\n"); - - eth.connect(); - - printf("IP Address is %s\r\n\r\n", eth.getIPAddress()); - printf("MASK Address is %s\r\n\r\n", eth.getNetworkMask()); - printf("GATEWAY Address is %s\r\n\r\n", eth.getGateway()); - printf("MAC Address is %s\r\n\r\n", eth.getMACAddress()); while(1){ + + // phy link + do{ + phy_link = eth.ethernet_link(); + printf("..."); + wait(2); + }while(!phy_link); + printf("\r\n"); + + eth.connect(); + + printf("IP Address is %s\r\n\r\n", eth.getIPAddress()); + printf("MASK Address is %s\r\n\r\n", eth.getNetworkMask()); + printf("GATEWAY Address is %s\r\n\r\n", eth.getGateway()); + printf("MAC Address is %s\r\n\r\n", eth.getMACAddress()); + // TCP socket connect to openweather server //TCPSocketConnection sock; - char http_addr[]="api.openweathermap.org"; - int port=80; + sock.connect("api.openweathermap.org", 80); - //connect - /////////////////////////////////////////////////////////// - - //////////////////////////////////////////////////////////// // GET method, to request weather forecast + //char http_cmd[] = "GET /data/2.5/weather?q=Seoul,kr&appid=a0ca47dd7f6066404629b3e1ad728981 HTTP/1.0\n\n"; char http_cmd[] = "GET /data/2.5/weather?q=London,uk&appid=a0ca47dd7f6066404629b3e1ad728981 HTTP/1.0\n\n"; - + //char http_cmd[] = "GET /data/2.5/weather?q=Berlin,de&appid=a0ca47dd7f6066404629b3e1ad728981 HTTP/1.0\n\n"; - //send data - /////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////// + sock.send_all(http_cmd, sizeof(http_cmd)-1); // get data into buffer char buffer[2048]; int ret; while (true) { - // break the while(), when don't received tha data - // save the data to buffer - // save the return value to ret - //receive data - ////////////////////////////////////////////////////// - - - - //////////////////////////////////////////////////// + ret = sock.receive(buffer, sizeof(buffer)-1); + if (ret <= 0) + break; buffer[ret] = '\0'; printf("Received %d chars from server: %s\n", ret, buffer); } @@ -150,12 +180,21 @@ gOled.display(); gOled.setTextCursor(0,0); - + //LED display rely on weather condition + if(strcmp(weather_con,"Clouds")==0) clouds(); + else if(strcmp(weather_con,"Rain")==0) rain(); + else if(strcmp(weather_con,"Thunderstorm")==0) thunderstorm(); + else if(strcmp(weather_con,"Clean")==0) clean(); + else if(strcmp(weather_con,"Mist")==0) mist(); + else if(strcmp(weather_con,"Haze")==0) haze(); + else if(strcmp(weather_con,"Fog")==0) fog(); + else error(); - //close - ////////////////////////////////////////////////// + + //Disconnection + sock.close(); + eth.disconnect(); - ////////////////////////////////////////////////// /* * everytime in delay, request weather forecast */