Weather forecasts play an important role in our day-to-day life. A good weather monitoring system helps in better planning and any preparations that may be required in case of adverse weather.
This project deals with the construction of a weather display system using low-cost components so that any electronics hobbyist can build it. Instead of using sensors to gather the weather data, the project gets the information from professional weather stations located around the world through an international weather data provider. The author’s prototype is shown in Fig. 1.
World weather online
During the past few years several weather data providers have proliferated on the Internet. One such provider is worldweatheronline.com. It offers a free application programming interface (API) that can be used by the developers to get the weather data. A client device is needed to access the worldweatheronline.com API to get weather data by sending a uniform resource locator (URL), simply known as the Internet address.
In order to get access to the API one has to register with the weather website. Upon successful registration, a unique access key code is assigned and sent to your email ID. This unique code must be included with the request URL that is sent to the server. One can send approximately 500 requests per hour to the server. The server accepts the client device request and sends the necessary data to the client.
The server provides three types of message formats for weather data: XML, JSON and CSV. The first two formats are a bit difficult to use because one must use format headers and keep track of special string of characters to identify data. The CSV format is simple because it uses readable characters where the data is separated by a comma (,) character.
To request weather data, the URL message shown below is sent to the server.
The response to the URL message is a stream of readable characters that include HTTP protocol information followed by weather data. The HTTP protocol information contained in the weather data is removed by a routine in the client software. The data values that follow are separated by commas. The current data and the forecast are separated by line feed and carriage return. The data layout information is available as comments in the CVS format. The following is an example of response from the server that contains weather data header in CSV format:
HTTP/1.1 200 OK
Cache-Control: public, no-cache=”Set-Cookie”, max-age=120
Content-Type: text/plain; charset=utf-8
Expires: Tue, 14 Jan 2014 06:20:17 GMT
NmQ27xVhqIEhtREITXXX7wBw3Pa5XkM1; expires=Mon, 24-Mar-2014 16:58:17 GMT; path=/;
Date: Tue, 14 Jan 2014 06:18:19 GMT
The following is the CSV data format:
wsymbols01_png_64/wsymbol_0002_sunny_intervals.png,PartlyCloudy ,10,16,37,NE,0.0,60,10,1015,40 2014-01-
The client software
The TCPIP client board, which houses Microchip TCPIP Stack 5.42, is configured to work as client. More detail on the stack can be obtained from www.microchip.com website.
The general TCP Client.c file available in stack is suitably modified to carry out the following tasks:
1. Send required URL to the server
2. Remove the HTML header from the incoming weather data from the server
3. Store weather data in the EEPROM
4. Send the stored data from the EEPROM to the host PC via COM port
Circuit and working
The block diagram of weather forecast monitoring system is shown in Fig. 2 and circuit diagram of the client board is shown in Fig. 3. The circuit contains Microchip PIC18F4685 (IC1), Ethernet controller ENC28J60 (IC2), EEPROM 25LC256 (IC3), quadruple 3-state buffer 74HCT125 (IC4), dual driver/receiver MAX232 (IC5), 16×2 LCD display and magnetic jack RJ45 Ethernet connector.
Ethernet controller ENC28J60 operates with 3.3V supply, so level-shifter IC 74HCT125 is used to maintain proper TTL levels between PIC and ENC via SPI bus. LCD is wired in a 4-bit mode with data lines connected to port pins RD0 through RD3 of the microcontroller IC1. The control lines RS, R/W and EN are connected to RD4, RD5 and RA5. Status LED2 connected to RA2 is used to indicate working of the stack by blinking.