Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Getting Weather Data for your zip-code.


  • Please log in to reply
5 replies to this topic

#1 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 27 November 2010 - 07:26 PM

This is a little class I started making, right now it fetches the current weather data and in the future I will add code to get the forecast. I wanted to make it into a project that shows it on a 16x2 LCD, but I couldn't keep this fun little code from you guys! I hope you can find some use for it.

using System;
using Microsoft.SPOT;
using System.Net;
using System.Text;
using System.IO;

namespace NPlus_Ethernet_Testing
{
    public class WebRetrieve
    {
        public WebRetrieve()
        {

        }

        public string GetCurrentConditions(string zipcode)
        {
            Uri address = new Uri("http://xml.weather.yahoo.com/forecastrss?p=" + zipcode);

            // Create the web request  
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);

            // Get response  
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            
            // Get the response stream  
            StreamReader reader = new StreamReader(response.GetResponseStream());
            
            string newLine = reader.ReadLine();
            int lineNumber = 0;

            while (newLine != "") // While we still got data
            {
                if (lineNumber == 32) // The Current weather data seems to be on line 32 always.
                    return newLine.Split('<')[0]; // The line also has a <BR/> at the end, get rid of that by spliting it and using the first part.

                newLine = reader.ReadLine(); // Read next line
                lineNumber++; // Update line number
            }

            return "Could Not Get Data"; // In case that we dont get to line # 32 for some odd reason
        }
    }
}


#2 Chris Seto

Chris Seto

    Advanced Member

  • Members
  • PipPipPip
  • 405 posts

Posted 27 November 2010 - 09:17 PM

I also have a massive class for this that uses AWOS's at local airports. You need an ICAO to make it work. http://files.chrisseto.com/7KE

#3 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 27 November 2010 - 09:32 PM

I also have a massive class for this that uses AWOS's at local airports. You need an ICAO to make it work.

http://files.chrisseto.com/7KE


It looks amazing! Although I did't dive into it, its far too complicated for me. but nice job!

#4 Eric Burdo

Eric Burdo

    Advanced Member

  • Members
  • PipPipPip
  • 130 posts

Posted 28 November 2010 - 02:39 AM

Thanks for both of you for this... I was looking for a project to use on my Netduino Plus. :)
~ Eric D. Burdo ~ http://brick-labs.com/

Today LED's, tomorrow, the world!!! Well, OK, maybe servos.

#5 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 28 November 2010 - 02:45 AM

Thanks for both of you for this... I was looking for a project to use on my Netduino Plus. :)

Could you let me know if my code works out for you?

#6 CwbhX

CwbhX

    Advanced Member

  • Members
  • PipPipPip
  • 85 posts
  • LocationNYC

Posted 29 November 2010 - 02:35 PM

Ahh, feels good to be back (I was on vacation in England :} ). This could be very useful with my new project, I will need to be able to fetch data from an online source, and as of right now am not sure how too :/. The source being Twitter :P Thanks a lot Omar! -Cwbh
-Cwbh




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.