LCD Weather System

Hello Guys

Im Trying create a basic weather system

Im using

a EtherMega(basically arduino uno with built-in internet)

A Fretronics LCD 16x2

My Aim: I want to display the weather (or just temperature) of a selected country/area onto the lcd through the internet automatically.

I have no clue of how to achieve this impossible goal, As i could find no instructions on a project like this. I have little coding experience.

Dodgy68: My Aim: I want to display the weather (or just temperature) of a selected country/area onto the lcd through the internet automatically.

I have no clue of how to achieve this impossible goal, As i could find no instructions on a project like this. I have little coding experience.

Where do you want to get the data from?

Yahoo Weather API perhaps? https://developer.yahoo.com/weather/

Or where?

You can only display data you can get from anywhere. If you don't measure the temperature in your backyard with a sensor yourself, you possibly take the data ffrom somebody on the Internet, telling you the temperature in your backyard.

I made a weather station using my own sensors.
I have temp, humidity, barometric pressure and lux at the moment.
I need to fix my rain & wind sensor setup.
Get some ideas from my setup.

Getting data from sensors is easy but I live in australia and want data from the London (just temperature and the location projected on lcd) I can't

Yahoo Weather API perhaps?

Yes but how would I achive that Is there any instructables on it ?s

Hello people

I want to make a lcd screen display the word london and current temperature of london using Yahoo weather API

But i have no clue how to achieve this. :(

Im using

a EtherMega(basically arduino uno with built-in internet)

A Fretronics LCD 16x2

Sorry for me not bringing much to work with. :confused:

What is your experience level in software programming and especially network programming? This sounds to me as not a beginners project.

Do you have documentation about the API? Why not post it?

Make a plan for the project, list all the things that you need to do in small steps like printint to LCD

You need to master all those steps one at a time and then combine that knowledge.

Dodgy68: Yahoo Weather API perhaps?

Yes but how would I achive that Is there any instructables on it ?s

I don't know about "instructables".

First you'd need a HTTP page where you can get the data from the Internet.

For example a Yahoo XML page like: http://weather.yahooapis.com/forecastrss?p=UKXX3326 Or if you prefer metric SI units you can request metric units by using an extra parameter: http://weather.yahooapis.com/forecastrss?p=UKXX3326&u=c

This page would contain the data for "City of London, UK".

But which "London" do you mean, exactly? Yahoo knows different "Londons" in the world: https://weather.codes/search/?q=london

Is "City of London, UK" the location you mean? Or one of the other "London" locations provided by Yahoo Weather?

If you have a HTTP page where you can retrieve the data, you send a "HTTP GET request" to that page, and from the HTTP response you extract the data you want to display.

Essentially identical threads merged.

Weather Underground has an API. Here is the getting started page http://www.wunderground.com/weather/api/d/docs

They also have code samples in PHP, Python and other languages. http://www.wunderground.com/weather/api/d/docs?d=resources/code-samples

You might want to look for sites that provide raw data without all the web page html. Below is some old code that still works!

//////////////////////////////////////////////
// Get XML formatted data from the web.
// 1/6/08 Bob S. - Created
//  Assumptions: single XML line looks like: 
//    <tag>data</tag> or <tag>data 
// Include description files for other libraries used (if any)
//
// updated at later dates zoomkat
//////////////////////////////////////////////

#include <SPI.h>
#include <Ethernet.h>

// Define Constants
// Max string length may have to be adjusted depending on data to be extracted
#define MAX_STRING_LEN  20

// Setup vars
char tagStr[MAX_STRING_LEN] = "";
char dataStr[MAX_STRING_LEN] = "";
char tmpStr[MAX_STRING_LEN] = "";
char endTag[3] = {'<', '/', '\0'};
int len;

// Flags to differentiate XML tags from document elements (ie. data)
boolean tagFlag = false;
boolean dataFlag = false;

// Ethernet vars
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//byte ip[] = { 192, 168, 1, 102 };
byte server[] = { 140, 90, 113, 200 }; // www.weather.gov

// Start ethernet client
EthernetClient client;

void setup()
{
  Serial.begin(9600);
  Serial.println("Starting WebWx");
  Serial.println("connecting...");
  //Ethernet.begin(mac, ip);
  Ethernet.begin(mac);
  delay(1000);

  if (client.connect(server, 80)) {
    Serial.println("connected");
    client.println("GET /xml/current_obs/KRDU.xml HTTP/1.0");    
    client.println();
    delay(2000);
  } else {
    Serial.println("connection failed");
  }  
}

void loop() {

  // Read serial data in from web:
  while (client.available()) {
    serialEvent();
  }

  if (!client.connected()) {
    Serial.println();
    Serial.println("Disconnected");
    Serial.println("==================================");
    Serial.println("");
    client.stop();

    // Time until next update
    //Serial.println("Waiting");
    for (int t = 1; t <= 15; t++) {
      delay(60000); // 1 minute
    }

    if (client.connect(server, 80)) {
      //Serial.println("Reconnected");
      client.println("GET /xml/current_obs/KRDU.xml HTTP/1.0");    
      client.println();
      delay(2000);
    } else {
      Serial.println("Reconnect failed");
    }      
  }
}

// Process each char from web
void serialEvent() {

   // Read a char
	 char inChar = client.read();
   //Serial.print(".");
  
   if (inChar == '<') {
      addChar(inChar, tmpStr);
      tagFlag = true;
      dataFlag = false;

   } else if (inChar == '>') {
      addChar(inChar, tmpStr);

      if (tagFlag) {      
         strncpy(tagStr, tmpStr, strlen(tmpStr)+1);
      }

      // Clear tmp
      clearStr(tmpStr);

      tagFlag = false;
      dataFlag = true;      
      
   } else if (inChar != 10) {
      if (tagFlag) {
         // Add tag char to string
         addChar(inChar, tmpStr);

         // Check for </XML> end tag, ignore it
         if ( tagFlag && strcmp(tmpStr, endTag) == 0 ) {
            clearStr(tmpStr);
            tagFlag = false;
            dataFlag = false;
         }
      }
      
      if (dataFlag) {
         // Add data char to string
         addChar(inChar, dataStr);
      }
   }  
  
   // If a LF, process the line
   if (inChar == 10 ) {

/*
      Serial.print("tagStr: ");
      Serial.println(tagStr);
      Serial.print("dataStr: ");
      Serial.println(dataStr);
*/

      // Find specific tags and print data
      if (matchTag("<temp_f>")) {
	      Serial.print("Temp: ");
         Serial.print(dataStr);
      }
      if (matchTag("<relative_humidity>")) {
	      Serial.print(", Humidity: ");
         Serial.print(dataStr);
      }
      if (matchTag("<pressure_in>")) {
	      Serial.print(", Pressure: ");
         Serial.print(dataStr);
         Serial.println("");
      }

      // Clear all strings
      clearStr(tmpStr);
      clearStr(tagStr);
      clearStr(dataStr);

      // Clear Flags
      tagFlag = false;
      dataFlag = false;
   }
}

/////////////////////
// Other Functions //
/////////////////////

// Function to clear a string
void clearStr (char* str) {
   int len = strlen(str);
   for (int c = 0; c < len; c++) {
      str[c] = 0;
   }
}

//Function to add a char to a string and check its length
void addChar (char ch, char* str) {
   char *tagMsg  = "<TRUNCATED_TAG>";
   char *dataMsg = "-TRUNCATED_DATA-";

   // Check the max size of the string to make sure it doesn't grow too
   // big.  If string is beyond MAX_STRING_LEN assume it is unimportant
   // and replace it with a warning message.
   if (strlen(str) > MAX_STRING_LEN - 2) {
      if (tagFlag) {
         clearStr(tagStr);
         strcpy(tagStr,tagMsg);
      }
      if (dataFlag) {
         clearStr(dataStr);
         strcpy(dataStr,dataMsg);
      }

      // Clear the temp buffer and flags to stop current processing
      clearStr(tmpStr);
      tagFlag = false;
      dataFlag = false;

   } else {
      // Add char to string
      str[strlen(str)] = ch;
   }
}

// Function to check the current tag for a specific string
boolean matchTag (char* searchTag) {
   if ( strcmp(tagStr, searchTag) == 0 ) {
      return true;
   } else {
      return false;
   }
}