Project Description

This post will explain how to get instant weather update for a specific city (i.e. Seoul) provided by OpenWeatherMap. With JSON (supplied by OpenWeatherMap), XML and an Ethernet module, we operated WIZnet’s WizFi250.

First, check the API content at OpenWeatherMap.

Calls by city name. API respond with a list of results that matchs a searching word. In JSON : api.openweathermap.org/data/2.5/weather?q=London,uk In XML : api.openweathermap.org/data/2.5/weather?q=London&mode=xml http://openweathermap.org/current

Then, following the provided instructions above, bring forth Seoul’s weather data in JSON and XML format on a PC. A screenshot of the Network Packet during this process is down below for reference.

openweathermap

 

The parts highlighted in red above are data sent from a PC. We plan to eliminate the unnecessary parts and input the data below using Request Data.

At this step, \r(Carriage return, 0x0d), \n(Line Feed, 0x0a) must be input exactly and the transmitted data size (72 Byte, 81 Byte) should be paid special attention as well.

* JSON
GET /data/2.5/weather?q=Seoul HTTP/1.1\r\n
Host: api.openweathermap.org\r\n\r\n
(72 Byte)
* XML
GET /data/2.5/weather?q=Seoul&mode=xml HTTP/1.1\r\n
Host: api.openweathermap.org\r\n\r\n
(81 Byte)

Now that the initial setup is complete we will operate WizFi250. First, establish Association at AP.
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]

Bring forth OpenWeatherMap API server’s IP address.
AT+FDNS=api.openweathermap.org,3000
128.199.164.95
[OK]

Connect with OpenWeatherMap API server.
AT+SCON=O,TCN,128.199.164.95,80,,0
[OK]
[CONNECT 0]

Send JSON Request Data to OpenWeatherMap API server.
AT+SSEND=0,,,72
[0,,,72]
(여기에서 위에 설명된 72 Byte를 전송하면 된다.)
[OK]

Then, OpenWeatherMap API server will respond with a JSON Reply like below.
{0,128.199.164.95,80,857}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}
0

If once reception is complete and the connection is still ongoing, end the connection with OpenWeatherMap API server.
AT+SMGMT=ALL
[DISCONNECT 0]
[OK]

Now, analyze the JSON data received above and use the desired weather data (Seoul’s temperature, humidity, wind speed, etc.) Enjoy!
Below is in the case of when you receive the data in XML format. However, WizFi250’s fundamental rules of operation are similar to JSON so it should be straightforward.
AT+SCON=O,TCN,128.199.164.95,80,,0
[OK]
[CONNECT 0]
AT+SSEND=0,,,81
[0,,,81]
(여기에서 위에 설명된 81 Byte를 전송한다.)
[OK]
{0,128.199.164.95,80,969}HTTP/1.1 200 OK
Server: nginx
Date: Tue, 05 Aug 2014 23:59:54 GMT
Content-Type: text/xml; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Source: back
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST
29a

<current>
<city id="1835848" name="Seoul">
<coord lon="126.98" lat="37.57">
<country>KR</country>
<sun set="2014-08-06T10:35:34" rise="2014-08-05T20:40:21">
</sun></coord></city>
<temperature value="297.38" unit="kelvin" min="296.15" max="298.15">
<humidity value="83" unit="%">
<pressure value="1006" unit="hPa">
<wind>
<speed value="1" name="Calm">
<direction value="170" name="South" code="S">
</direction></speed></wind>
<clouds value="75" name="broken clouds">
<visibility>
<precipitation mode="no">
<weather value="haze" number="721" icon="50n">
<lastupdate value="2014-08-05T23:30:00">
</lastupdate></weather></precipitation></visibility></clouds></pressure></humidity></temperature></current>

0
AT+SMGMT=ALL
[DISCONNECT 0]
[OK]