Hi,
I am reading XML weather data off of Google's website: Google
My code is working and TextFinder returns a string I named "cond" (which is the forecast condition)
I need my code to activate a motor if "cond" is one of 5 phrases "Rain", "Showers", "Chance of Rain", "Chance of Showers", or "Thunderstorms"
I don't really understands how strings and char arrays work yet.
Any suggestions???
Here is the part of the code I am discussing:
if(finder.find("<condition data")){
finder.getString("=", "/", cond, 30);
Serial.print("Forecast is ");
Serial.println(cond);
lcd.setCursor(0,2);
lcd.print(cond);
delay(1);
if (cond == "Chance of Showers" || "Chance of Rain" || "Showers" || "Rain" || "Thunderstorms" ){// THIS PART NEEDS HELP
Serial.println("yes");
}
}
Here is the entire code for context:
//Sources
//Arduino Cookbook 15.5,
//Google weather site http://www.google.com/ig/api?weather=Portland,OR
//wwww.bildr.org/?s=ethernet
//Arduino Forum, Topic: Getting Weather Data from XML with Ehernet Shield, zoomkat posted code from "someone else" based on SimpleClientGoogleWeatherDHCP
//DO NOT USE PIN 11 on ETHERNET SHEILD
#include <Ethernet.h>
#include <TextFinder.h>
#include <SPI.h>
#include <LiquidCrystal.h>
#include <Wire.h>
LiquidCrystal lcd(0);
byte mac[] = {
0x90, 0xA2, 0xDA, 0x0D, 0x14, 0xBF }; //Ethernet Sheild MAC address
byte server[] = {
209,85,229,104 }; //Google XML weather page
EthernetClient client;
TextFinder finder(client);
int LedColdPin = 9;
int LedHotPin = 8;
int LedMedPin = 7;
int testcold = 0;
int testhot = 0;
const byte switchPin = 6; //digital pin
const byte RainMotorPin1 = 3; //digital pin
const byte RainMotorPin2 = 4; //digital pin
const byte SnowMotorPin3 = 16;
const byte SnowMotorPin4 = 17;
const byte enablePinRain = 5; //digital pin, powers that side of H bridge
const byte enablePinSnow = 15; //(on A1),digital pin, powers that side of H bridge
byte state = 0;
char cond[30]; // string for incoming serial data
void setup(){
Serial.begin(9600);
Ethernet.begin(mac);
lcd.begin(20,4);
pinMode(LedColdPin,OUTPUT);
pinMode(LedMedPin, OUTPUT);
pinMode(LedHotPin,OUTPUT);
pinMode(switchPin, INPUT);
pinMode(RainMotorPin1, OUTPUT);
pinMode(RainMotorPin2, OUTPUT);
pinMode(SnowMotorPin3, OUTPUT);
pinMode(SnowMotorPin4, OUTPUT);
pinMode(enablePinRain, OUTPUT);
pinMode(enablePinSnow, OUTPUT);
}//void setup brace
void loop(){
if (client.connect(server,80)) {
client.println("GET /ig/api?weather=Portland,OR HTTP/1.0");
client.println();
}
else{
Serial.println("connection failed");
}
if (client.connected()){
if(finder.find("<low data=")){
int t_low = finder.getValue();
Serial.print("Low Temp is ");
Serial.println(t_low);
lcd.setCursor(0,1);
lcd.print("Low: ");
lcd.setCursor(5,1);
lcd.print(t_low);
delay(1);
lcd.setCursor(8,1);
lcd.print((char)223);
delay(1);
if(t_low <= 45){
digitalWrite(LedColdPin, HIGH);
testcold=1;
}
}
if(finder.find("<high data=")){
int t_high = finder.getValue();
Serial.print("High Temp is ");
Serial.println(t_high);
lcd.setCursor(0,0);
lcd.print("High: ");
lcd.setCursor(6,0);
lcd.print(t_high);
delay(1);
lcd.setCursor(9,0);
lcd.print((char)223);
delay(1);
if(t_high >= 75){
digitalWrite(LedHotPin, HIGH);
testhot=1;
}
}
if(testcold == 0 && testhot == 0){
digitalWrite(LedMedPin, HIGH);
}
if(finder.find("<condition data")){
finder.getString("=", "/", cond, 30);
Serial.print("Forecast is ");
Serial.println(cond);
lcd.setCursor(0,2);
lcd.print(cond);
delay(1);
if (cond == "Chance of Showers" || "Chance of Rain" || "Showers" || "Rain" || "Thunderstorms" ){// THIS PART NEEDS HELP
Serial.println("yes");
}
}//if finder find condition data brace
else{
Serial.print("Could not find condition field");
}
}//if client connect brace
else{
Serial.println("Disconnected");
}
client.stop();
client.flush();
delay(6000);
}//void loop brace