Nokia LCD Weather Application
Goal
Our goal with this project was to fix/update the existing Nokia LCD Weather application by Jim Hamblen (page found here). A casual glance suggests that maybe a few libraries are either obsolete or require other, more up-to-date libraries to function properly. Additionally, Google's old weather API is no longer functional, so we needed to find another API to use.
Process
Our first job was to figure what libraries were needed to get the application to compile again. We ended up finding that all that was really necessary was to remove HTTPClient from the libraries and it compiles fine. Apparently, the support that HTTPClient provided got lumped into some other library (likely NetServices) and so it is no longer necessary for this application to run.
Our next step was to build a new XML parser by editing the old one. The old Google XML gave data that looked like this:
Google Weather API XML
<current_conditions> <condition data="Clear" /> <temp_f data="65" /> <temp_c data="18" /> <humidity data="Humidity: 70%" /> <icon data="/ig/images/weather/sunny.gif" /> <wind_condition data="Wind: N at 5 mph" /> </current_conditions>
While the Yahoo! XML gives information like this:
Yahoo! Weather API XML
<item> <title>Conditions for Seattle, WA at 9:53 am PST</title> <geo:lat>47.6</geo:lat> <geo:long>-122.33</geo:long> <link> http://us.rd.yahoo.com/dailynews/rss/weather/Seattle__WA/*http://weather.yahoo.com/forecast/USWA0395_c.html </link> <pubDate>Wed, 06 Mar 2013 9:53 am PST</pubDate> <yweather:condition text="Light Rain" code="11" temp="8" date="Wed, 06 Mar 2013 9:53 am PST"/>
All of the information we care about is found on one line under the tag "yweather:condition," so data extraction was easy. The edited parsing class looks like this:
Edited XML Parser
void parseWeather(SP_XmlElementNode *node, string loc) { //extracts current weather XML data fields for LCD SP_XmlHandle handle(node); SP_XmlElementNode * condition = handle.getChild( "item" ).getChild("yweather:condition").toElement(); lcd.cls(); // Print the name of the city lcd.locate(0,2); lcd.printf("%s:", loc); //Print the weather conditions lcd.locate(0,3); lcd.printf("%s",condition->getAttrValue("text")); //Print the termperature (in degrees Celcius) lcd.locate(0,4); lcd.printf("%sC",condition->getAttrValue("temp")); //Print the date and time lcd.locate(0,5); lcd.printf("%s",condition->getAttrValue("date")); }
A new argument was added such that the location can be passed, since we planned on offering the ability to change the location whose weather forecast we'd be retrieving. The ability to select locations was implemented using a pair of pushbuttons, and is as follows:
Code to select location
// string arrays associating cities with their codes for the yahoo! API string cities[5] = { "Atlanta", "Houston", "New York", "Seattle", "Sunnyvale" }; string codes[5] = { "2357024", "2424766", "2459115", "2490383", "2442047" }; string head = "http://weather.yahooapis.com/forecastrss?w="; //Display the cities to choose from for(int i = 0; i < 5; i++){ lcd.locate(1, i); lcd.printf("%i: %s", i+1, cities[i]); } int curr = 0; int accept = but1, select = but2, pushed = 0; //This while loop handles selection of cities for display. while(accept == 0){ lcd.locate(0, curr); lcd.printf(" "); //The next two if statements check to see if the button has been pushed, and then cycles through the selection choices as appropriate. if(select == 1){ pushed = 1; } if((select == 0)&&(pushed == 1)){ pushed = 0; curr = (curr + 1)%5; } lcd.locate(0, curr); lcd.printf(">"); accept = but1; select = but2; } //Concatenate the city code for use by the Yahoo! API head += codes[curr]; head += "&u=c";
The Result
Connections
Ethernet Connector (Magjack)
- [Mbed -> Slave]
- TD+ -> P1
- TD- -> P2
- RD+ -> P7
- RD- -> P8
LCD Display
- Gnd -> Gnd
- p5 (mosi) -> DIO
- p7 (sclk) -> SCK
- p8 -> CS
- p9 -> Reset
- Vout (3.3V)-> 3.3V
- Vout (3.3V)-> Vbat
Push Buttons
- [Function : Pin]
- Accept : P13
- Select : P14
In all, the code looks much like the original version made by Professor Hamblen:
Import programweather_Nokia_LCD_display_yahoo
Updated version of Jim Hamblen's Nokia LCD weather App. Updated to suport Yahoo!'s weather API instead of the Google API. Also removed extraneous Libraries.
Future work
We'd like to see if we could add functionality to type in locations instead of just selecting one from a list. An API search could then be used to pull up the necessary XML pages for parsing. One of our other ideas was to maybe include icons to display weather conditions instead of text.
Please log in to post comments.