
If you use the Open API, you can acquire the weather information. This posting explains how embedded device can acquire the weather information from OpenWeahterMap. The device is based on Cortex-M3 platform and using WizFi250 for WiFi connectivity.
For more detail about OpenWeatherMap, clilck below link.
OpenWeatherMap API
JSON format API
GET /data/2.5/weather?q=Seoul HTTP/1.1\r\n Host: api.openweathermap.org\r\n\r\n
XML format API
GET /data/2.5/weather?q=Seoul&mode=xml HTTP/1.1\r\n Host: api.openweathermap.org\r\n\r\n
Below is the WizFi250 AT commands to acquire the weather information.
AT+WSET=0,Team Wiki [OK] AT+WSEC=0,,12345678 [OK] AT+WNET=1 [OK] AT+WJOIN Joining : Team Wiki Successfully joined : Team Wiki [Link-Up Event] IP Addr : 192.168.101.33 Gateway : 192.168.101.1 [OK] AT+FDNS=api.openweathermap.org,3000 128.199.164.95 [OK] AT+SCON=O,TCN,128.199.164.95,80,,1 [OK] [CONNECT 0]
The message from WizFi250 is as below
GET /data/2.5/weather?q=Seoul HTTP/1.1\r\n Host: api.openweathermap.org\r\n\r\n
If above message is well transmitted to OpenWeatherMap server, below response message in JSON format can be received.
HTTP/1.1 200 OK Server: nginx Date: Wed, 06 Aug 2014 00:06:49 GMT Content-Type: application/json; charset=utf-8 Transfer-Encoding: chunked Connection: keep-alive X-Source: redis Access-Control-Allow-Origin: * Access-Control-Allow-Credentials: true Access-Control-Allow-Methods: GET, POST 221 {"coord":{"lon":126.98,"lat":37.57},"sys":{"type":3,"id":8519,"message":0.033,"country":"KR","sunrise":1407184771,"sunset":1407234998},"weather":[{"id":721,"main":"Haze","description":"haze","icon":"50n"},{"id":500,"main":"Rain","description":"light rain","icon":"10n"},{"id":701,"main":"Mist","description":"mist","icon":"50n"}],"base":"cmc stations","main":{"temp":297.26,"pressure":1005,"humidity":83,"temp_min":295.15,"temp_max":298.15},"wind":{"speed":1,"deg":140},"clouds":{"all":40},"dt":1407277800,"id":1835848,"name":"Seoul","cod":200}
Below code can be programmed to cortex-M3
#define SSID "wizohp" #define PASSWORD "wiznet218" #define SERVER_PORT "80" #define SERVER_IP "128.199.164.95" #define WEATHER_QUERY "GET /data/2.5/weather?q=Seoul HTTP/1.1\r\nHost: api.openweathermap.org\r\n\r\n" int main() { char cmd[256]; char recv_data[256]; int32_t idx=0,is_response_ended=0; int32_t uart_recv; int32_t is_connected=0; platform_init(); WizFi250_Restart(); if ( send_and_check_command("AT+WLEAVE", 1, 500, 10, "[OK]", "", 1) !=0 ) { printf("DBG>>> Error : AT Command\r\n");} if ( send_and_check_command("AT+WNET=1", 1, 500, 10, "[OK]", "", 1) !=0 ) { printf("DBG>>> Error : AT Command\r\n");} sprintf(cmd,"AT+WSET=0,%s",SSID); if ( send_and_check_command(cmd, 1, 500, 10, "[OK]", "", 1) !=0 ) { printf("DBG>>> Error : AT Command\r\n");} sprintf(cmd,"AT+WSEC=0,,%s",PASSWORD); if ( send_and_check_command(cmd, 1, 500, 10, "[OK]", "", 1) !=0 ) { printf("DBG>>> Error : AT Command\r\n");} if ( send_and_check_command("AT+WJOIN", 1, 500, 100, "[OK]", "", 1) !=0 ) { printf("DBG>>> Error : AT Command\r\n");} pltfrm_gpio_init(GPIOA,(GPIO_Pin_0 | GPIO_Pin_1),GPIO_Mode_Out_PP); pltfrm_gpio_set(GPIOA,(GPIO_Pin_0 | GPIO_Pin_1),1); while(1) { if(is_connected == 0) { sprintf(cmd,"AT+SCON=O,TCN,%s,%s,,1",SERVER_IP,SERVER_PORT); if ( send_and_check_command(cmd, 1, 500, 100, "[OK]", "[CONNECT", 1) !=0 ) { printf("DBG>>> Error : AT Command\r\n"); break;} is_connected = 1; usart_puts(PF_USART1,"Send Query\r\n",strlen("Send Query\r\n")); usart_puts(PF_USART2,WEATHER_QUERY,strlen(WEATHER_QUERY)); } else { while(1) { if( (uart_recv = usart_getc_nonblk(PF_USART2)) == RET_NOK ) continue; if((is_response_ended == 1) && (uart_recv == ‘\n’)) { is_response_ended=0; break; } if( uart_recv == ‘\n’) { is_response_ended++; } usart_putc(PF_USART1,uart_recv); } delay_ms(1000); } } }
After executing the code, you can get the result as below.
COMMENTS