bus
Dependencies: Servo WIZnetInterface mbed-src
Fork of My_Weatherforecast_WIZwiki-W7500 by
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 #include "Servo.h" 00004 00005 //internal led 00006 DigitalOut rled(LED1,1); 00007 DigitalOut gled(LED2,1); 00008 DigitalOut bled(LED3,1); 00009 00010 //gpio 00011 DigitalOut wealed(D2); 00012 DigitalOut busled_00(D15); 00013 DigitalOut busled_01(D14); 00014 DigitalOut busled_02(D13); 00015 DigitalOut busled_03(D12); 00016 DigitalOut busled_10(D11); 00017 DigitalOut busled_11(D10); 00018 DigitalOut busled_12(D9); 00019 DigitalOut busled_13(D8); 00020 DigitalOut busled_20(D7); 00021 DigitalOut busled_21(D6); 00022 DigitalOut busled_22(D5); 00023 DigitalOut busled_23(D4); 00024 00025 int main() 00026 { 00027 int phy_link; 00028 printf("Wait a second...\r\n"); 00029 uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x09}; 00030 00031 EthernetInterface eth; 00032 eth.init(mac_addr); //Use DHCP 00033 00034 eth.connect(); 00035 00036 //phy link 00037 do{ 00038 phy_link = eth.ethernet_link(); 00039 printf("..."); 00040 wait(2); 00041 }while(!phy_link); 00042 printf("PHY_LINK_OK\n"); 00043 printf("IP Address is %s\r\n", eth.getIPAddress()); 00044 00045 //get info 00046 char buffer_wea[1000]; 00047 char buffer_0[1000]; 00048 char buffer_1[1000]; 00049 char buffer_2[1000]; 00050 int ret_wea; 00051 int ret_0; 00052 int ret_1; 00053 int ret_2; 00054 00055 //weather 00056 char http_cmd_wea[] = "GET /data/2.5/weather?q=Seongnam,kr HTTP/1.0\n\n"; 00057 00058 00059 //BUS 00060 //char http_cmd[] = "GET /ws/rest/busarrivalservice/station?serviceKey=test&stationId=206000606 \n\n"; 00061 char http_cmd_0[] = "GET /ws/rest/busarrivalservice?serviceKey=test&routeId=204000039&stationId=206000606 \n\n"; //330 00062 char http_cmd_1[] = "GET /ws/rest/busarrivalservice?serviceKey=test&routeId=204000044&stationId=206000606 \n\n"; //350 00063 char http_cmd_2[] = "GET /ws/rest/busarrivalservice?serviceKey=test&routeId=204000079&stationId=206000606 \n\n"; //380 00064 00065 00066 while(1) 00067 { 00068 //TCP socket[weather] connect 00069 TCPSocketConnection sock_wea; 00070 sock_wea.connect("api.openweathermap.org", 80); 00071 printf("Socket[weather] connected\n"); 00072 00073 sock_wea.send_all(http_cmd_wea, sizeof(http_cmd_wea)-1); 00074 00075 while (true) 00076 { 00077 ret_wea = sock_wea.receive(buffer_wea, sizeof(buffer_wea)-1); 00078 if (ret_wea <= 0) 00079 printf("fail\n"); 00080 break; 00081 00082 buffer_wea[ret_wea] = '\0'; 00083 } 00084 00085 //TCP socket0 connect 00086 TCPSocketConnection sock_0; 00087 sock_0.connect("openapi.gbis.go.kr", 80); 00088 printf("Socket0 connected\n"); 00089 00090 sock_0.send_all(http_cmd_0, sizeof(http_cmd_0)-1); 00091 00092 while (true) 00093 { 00094 ret_0 = sock_0.receive(buffer_0, sizeof(buffer_0)-1); 00095 if (ret_0 <= 0) 00096 printf("fail\n"); 00097 break; 00098 00099 buffer_0[ret_0] = '\0'; 00100 } 00101 00102 00103 //TCP socket1 connect 00104 TCPSocketConnection sock_1; 00105 sock_1.connect("openapi.gbis.go.kr", 80); 00106 printf("Socket1 connected\n"); 00107 00108 sock_1.send_all(http_cmd_1, sizeof(http_cmd_1)-1); 00109 while (true) 00110 { 00111 ret_1 = sock_1.receive(buffer_1, sizeof(buffer_1)-1); 00112 if (ret_1 <= 0) 00113 printf("fail\n"); 00114 break; 00115 00116 buffer_1[ret_1] = '\0'; 00117 } 00118 00119 00120 //TCP socket2 connect 00121 TCPSocketConnection sock_2; 00122 sock_2.connect("openapi.gbis.go.kr", 80); 00123 printf("Socket2 connected\n"); 00124 00125 sock_2.send_all(http_cmd_2, sizeof(http_cmd_2)-1); 00126 00127 while (true) 00128 { 00129 ret_2 = sock_2.receive(buffer_2, sizeof(buffer_2)-1); 00130 if (ret_2 <= 0) 00131 printf("fail\n"); 00132 break; 00133 00134 buffer_2[ret_0] = '\0'; 00135 } 00136 00137 00138 //print 00139 //printf("\nWeather\n\n Received %d chars from server=> \n%s\n\n", ret_wea, buffer_wea); 00140 //wait(2); 00141 //printf("\n330\n\n Received %d chars from server=> \n%s\n\n", ret_0, buffer_0); 00142 //wait(2); 00143 //printf("\n350\n\n Received %d chars from server=> \n%s\n\n", ret_1, buffer_1); 00144 //wait(2); 00145 //printf("\n380\n\n Received %d chars from server=> \n%s\n\n", ret_2, buffer_2); 00146 //wait(2); 00147 00148 00149 //get weather, city, tempurature 00150 char *weather; 00151 char *city; 00152 char *tempure; 00153 00154 char weather_stu[3]; 00155 char tempure_data[6]; 00156 00157 int weather_id; 00158 int weather_id_[3]; 00159 00160 int tempure_d; 00161 int tempure_[3]; 00162 00163 weather = strstr(buffer_wea, "id"); 00164 printf("\nWeather ID=> %.3s\n", weather+4); 00165 for(int i=0; i<3; i++) 00166 { 00167 weather_stu[i] = (weather[i+4]); 00168 weather_id_[i] = weather_stu[i]-'0'; 00169 //printf("%c", weather_stu[i]); 00170 } 00171 weather_id = weather_id_[0]*100+weather_id_[1]*10*weather_id_[2]; 00172 //printf("%d\n", weather_id); 00173 00174 city = strstr(buffer_wea, "name"); 00175 printf("City Name=> %.8s\n", city + 7); 00176 00177 tempure = strstr(buffer_wea, "temp"); 00178 printf("Tempurature=> %.3sK\n", tempure + 6); 00179 for(int i=0; i<3; i++) 00180 { 00181 tempure_data[i] = (tempure[i+6]); 00182 tempure_[i] = tempure_data[i]-'0'; 00183 //printf("%c", tempure_data[i]); 00184 } 00185 tempure_d = tempure_[0]*100+tempure_[1]*10+tempure_[2]; 00186 00187 printf("Tempurature=> %dC\n\n", (tempure_d - 273)); 00188 00189 00190 //weather display 00191 if((weather_id>=200)&&(weather_id<300)) 00192 { 00193 printf("<<< Thunderstom >>>\n"); 00194 printf("<<< You need an umbrella >>>\n"); 00195 //rled = 1;gled = 0;bled = 0; 00196 wealed = 1; 00197 } 00198 else if((weather_id>=300)&&(weather_id<400)) 00199 { 00200 printf("<<< Drizzle >>>\n"); 00201 printf("<<< You need an umbrella >>>\n"); 00202 //rled = 1;gled = 0;bled = 0; 00203 wealed = 1; 00204 } 00205 else if((weather_id>=500)&&(weather_id<600)) 00206 { 00207 printf("<<< Rain >>>\n"); 00208 printf("<<< You need an umbrella >>>\n"); 00209 //rled = 1;gled = 0;bled = 0; 00210 wealed = 1; 00211 } 00212 else if((weather_id>=600)&&(weather_id<700)) 00213 { 00214 printf("<<< Snow >>>\n"); 00215 printf("<<< You need an umbrella >>>\n"); 00216 //rled = 1;gled = 0;bled = 0; 00217 wealed = 1; 00218 } 00219 else 00220 { 00221 printf("<<< You don't need an umbrella >>>\n"); 00222 //rled = 0;gled = 1;bled = 0; 00223 wealed = 0; 00224 } 00225 00226 00227 //get location 00228 char *location_0; 00229 char *location_1; 00230 char *location_2; 00231 00232 char loca_0[2]; 00233 char loca_1[2]; 00234 char loca_2[2]; 00235 00236 int INT_location_0[2]; 00237 int INT_location_1[2]; 00238 int INT_location_2[2]; 00239 00240 int S_location_0; 00241 int S_location_1; 00242 int S_location_2; 00243 00244 printf("\n<<< locationNo1 >>>\n"); 00245 00246 location_0 = strstr(buffer_0, "<locationNo1>"); 00247 printf("330 => %.2s\n", location_0+13); 00248 00249 location_1 = strstr(buffer_1, "<locationNo1>"); 00250 printf("350 => %.2s\n", location_1+13); 00251 00252 location_2 = strstr(buffer_2, "<locationNo1>"); 00253 printf("380 => %.2s\n", location_1+13); 00254 00255 00256 //330 display 00257 for(int i=0; i<2; i++) 00258 { 00259 loca_0[i] = (location_0[i+13]); 00260 INT_location_0[i] = loca_0[i]-'0'; 00261 } 00262 00263 printf("\n<<< Remaining station >>>\n"); 00264 00265 if(INT_location_0[1]==12) 00266 { 00267 printf("330 => %d\n",INT_location_0[0]); 00268 S_location_0 = INT_location_0[0]; 00269 } 00270 else 00271 { 00272 printf("330 => %d\n",INT_location_0[0]*10+INT_location_0[1]); 00273 S_location_0 = INT_location_0[0]*10+INT_location_0[1]; 00274 } 00275 00276 //330 position sign 00277 //if(S_location_0>=5) 00278 //{ 00279 // rled=0;bled=1;gled=1; 00280 //} 00281 //else if (S_location_0==4) 00282 //{ 00283 // rled=1;bled=0;gled=0; 00284 //} 00285 //else if (S_location_0==3) 00286 if (S_location_0>=4) 00287 { 00288 //rled=1;bled=1;gled=0; 00289 busled_00=0;busled_01=0;busled_02=0;busled_03=1; 00290 } 00291 else if (S_location_0==3) 00292 { 00293 //rled=1;bled=0;gled=1; 00294 busled_00=0;busled_01=0;busled_02=1;busled_03=0; 00295 } 00296 else if (S_location_0==2) 00297 { 00298 //rled=0;bled=0;gled=0; 00299 busled_00=0;busled_01=1;busled_02=0;busled_03=0; 00300 } 00301 else if (S_location_0==1) 00302 { 00303 //rled=1;bled=1;gled=1; 00304 busled_00=1;busled_01=0;busled_02=0;busled_03=0; 00305 } 00306 else 00307 { 00308 busled_00=0;busled_01=0;busled_02=0;busled_03=0; 00309 } 00310 00311 00312 //350 display 00313 for(int i=0; i<2; i++) 00314 { 00315 loca_1[i] = (location_1[i+13]); 00316 INT_location_1[i] = loca_1[i]-'0'; 00317 } 00318 00319 if(INT_location_1[1]==12) 00320 { 00321 printf("350 => %d\n",INT_location_1[0]); 00322 S_location_1 = INT_location_1[0]; 00323 } 00324 else 00325 { 00326 printf("350 => %d\n",INT_location_1[0]*10+INT_location_1[1]); 00327 S_location_1 = INT_location_1[0]*10+INT_location_1[1]; 00328 } 00329 00330 //350 position sign 00331 if (S_location_1>=4) 00332 { 00333 //rled=1;bled=1;gled=0; 00334 busled_10=0;busled_11=0;busled_12=0;busled_13=1; 00335 } 00336 else if (S_location_1==3) 00337 { 00338 //rled=1;bled=0;gled=1; 00339 busled_10=0;busled_11=0;busled_12=1;busled_13=0; 00340 } 00341 else if (S_location_1==2) 00342 { 00343 //rled=0;bled=0;gled=0; 00344 busled_10=0;busled_11=1;busled_12=0;busled_13=0; 00345 } 00346 else if (S_location_1==1) 00347 { 00348 //rled=1;bled=1;gled=1; 00349 busled_10=1;busled_11=0;busled_12=0;busled_13=0; 00350 } 00351 else 00352 { 00353 busled_10=0;busled_11=0;busled_12=0;busled_13=0; 00354 } 00355 00356 00357 //380 display 00358 for(int i=0; i<2; i++) 00359 { 00360 loca_2[i] = (location_2[i+13]); 00361 INT_location_2[i] = loca_2[i]-'0'; 00362 } 00363 00364 if(INT_location_2[1]==12) 00365 { 00366 printf("380 => %d\n",INT_location_2[0]); 00367 S_location_2 = INT_location_2[0]; 00368 } 00369 else 00370 { 00371 printf("380 => %d\n",INT_location_2[0]*10+INT_location_2[1]); 00372 S_location_2 = INT_location_2[0]*10+INT_location_2[1]; 00373 } 00374 00375 //380 position sign 00376 if (S_location_2>=4) 00377 { 00378 //rled=1;bled=1;gled=0; 00379 busled_20=0;busled_21=0;busled_22=0;busled_23=1; 00380 } 00381 else if (S_location_2==3) 00382 { 00383 //rled=1;bled=0;gled=1; 00384 busled_20=0;busled_21=0;busled_22=1;busled_23=0; 00385 } 00386 else if (S_location_2==2) 00387 { 00388 //rled=0;bled=0;gled=0; 00389 busled_20=0;busled_21=1;busled_22=0;busled_23=0; 00390 } 00391 else if (S_location_2==1) 00392 { 00393 //rled=1;bled=1;gled=1; 00394 busled_20=1;busled_21=0;busled_22=0;busled_23=0; 00395 } 00396 else 00397 { 00398 busled_20=0;busled_21=0;busled_22=0;busled_23=0; 00399 } 00400 00401 00402 sock_wea.close(); 00403 sock_0.close(); 00404 sock_1.close(); 00405 sock_2.close(); 00406 00407 eth.disconnect(); 00408 printf("\nSocket disconnected\n\n"); 00409 00410 wait(12); 00411 }; 00412 00413 }
Generated on Tue Jul 12 2022 21:31:36 by
1.7.2
