find text on webpage

I am trying to make an arduino weather alert, from this website: http://api.openweathermap.org/data/2.5/weather?q=Melbourne,au and I need to find the contents of the quotation marks in "weather" after "main".

Currently my code looks like this:

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "api.openweathermap.org";  

IPAddress ip(192,168,1,77);

EthernetClient client;

void setup() {
  Serial.begin(9600);
   while (!Serial) {
    ;
  }

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    Ethernet.begin(mac, ip);
  }
  delay(1000);

  if (client.connect(server, 80)) {
    client.println("GET /data/2.5/weather?q=Melbourne,au HTTP/1.1");
    client.println("Host: api.openweathermap.org");
    client.println("Connection: close");
    client.println();
  } 
  else {
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

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

    while(true);
  }
}

and it returns:

HTTP/1.1 200 OK
Server: nginx
Date: Sun, 07 Jun 2015 21:17:44 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: close
X-Source: redis
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST

1d2
{"coord":{"lon":144.96,"lat":-37.81},"sys":{"message":0.0117,"country":"AU","sunrise":1433626204,"sunset":1433660872},"weather":[{"id":800,"main":"Clear","description":"Sky is Clear","icon":"01n"}],"base":"stations","main":{"temp":284.532,"temp_min":284.532,"temp_max":284.532,"pressure":1011.27,"sea_level":1030.68,"grnd_level":1011.27,"humidity":80},"wind":{"speed":4.43,"deg":331.501},"clouds":{"all":0},"dt":1433711139,"id":2158177,"name":"Melbourne","cod":200}

0

(which is correct)
But for this output I want it to say: Clear (because that's what's in the quotation marks in "weather" after "main")

thanks in advance for the help.

You could either use a regex parser like Nick Gammons.
Or you could analyse the datastructure and write a acceptor state machine or model the data structure into a jsp program structure.

hazzdood123:
But for this output I want it to say:

Clear

(because that's what's in the quotation marks in "weather" after "main")

That sounds an easy task.

If I'd do that, I'd write a small data reading routine that would do:

  • read in server response char by char
  • ignore all HTTP header lines sent from the server (until first empty line)
  • parse the one and only data line char by char
  • scan for the first occurance of "main":
  • if found, then the next word included in inverted commas is what we look for

Is that the only data you need to extract from the server response?
Do you need help in coding that?

The discussion may have what you need with the textfinder application. As what is sent back is not too big, you might use the below code to parse what you need from the returned data using the various String functions.

http://forum.arduino.cc/index.php?topic=326822.msg2256243#msg2256243

//zoomkat 11-04-13
//simple client test
//for use with IDE 1.0.1
//with DNS, DHCP, and Host
//open serial monitor and send an e to test client GET
//for use with W5100 based ethernet shields
//remove SD card if inserted
//data from myIP server captured in readString 

#include <SPI.h>
#include <Ethernet.h>
String readString;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address

char serverName[] = "api.openweathermap.org"; // myIP server test web page server
EthernetClient client;

//////////////////////

void setup(){

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }

  Serial.begin(9600); 
  Serial.println("client readString test 11/04/13"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
  Serial.println();
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
    {
      sendGET(); // call sendGET function below when byte is an e
    }
  }  
} 

//////////////////////////

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET /data/2.5/weather?q=Melbourne,au HTTP/1.1");
    client.println("Host: api.openweathermap.org");
    client.println("Connection: close");
    client.println();
  } 
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    readString += c; //places captured byte in readString
  }

  //Serial.println();
  client.stop(); //stop client
  Serial.println("client disconnected.");
  Serial.println("Data from server captured in readString:");
  Serial.println();
  Serial.print(readString); //prints readString to serial monitor 
  Serial.println();  
  Serial.println();
  Serial.println("End of readString");
  Serial.println("==================");
  Serial.println();
  readString=""; //clear readString variable

}