Ethernet shield, problem posting to Weather Underground

I am learning how to do this by building a weather station. So far, I have the arduino, weather shield, xbee sending data to a receiver arduino, also with an xbee and the genuine Wiznet shield. I am able to read the incoming data on a 20x4 LCD shield and see it on the Serial Monitor. For about one hour, I was able to post the data also to Underground. Now it has stopped, although data continues to come across the LCD and Serial Monitor. I’ve checked the Ethernet shield by loading on of the IDE Example programs and it seems to be okay.

I can’t seem to find my error here, but I am sure I have strayed… Please excuse the sloppy code… Thanks in advance for any thoughts you might have.
Phil

/*

WX Reciever - LCD 20X4 display 

     Parses comma delimited strings from the input stream and prints to LCD
     Valid data starts with $ and ends with #
     Each parsed string is stored in a string array   
   
WX Receiver - Ethernet Shield to WeatherUnderground
Wunderground Upload guidelines: http://wiki.wunderground.com/index.php/PWS_-_Upload_Protocol


WX Receiver - Serial Monitor, just to check


*/


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


#include <LiquidCrystal_I2C.h>


LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 20 chars and 4 line display

//position of variables in serial string
#define winddir 1
#define windspeedmph 2
#define windgustmph 3
#define tempf 4
#define rainin 5
#define baromin 6
#define dewptf 7
#define humidity 8
#define windgustdir 9
#define windgustmph_avg2m 10
#define windgustdir_avg2m 11
#define windgustmph_avg10m 12
#define windgustdir_avg10m 13
#define dailyrainin 14
#define batt_lvl 16
#define light_lvl 17




int DEBUG = 0;


// My Ethernet shield
byte mac[] = {0x90, 0xA2, 0XDA, 0x0F, 0x72, 0x90 };//for shield in the system

// My network settings
IPAddress ip(192,168,1,173); //LOCAL IP address not used by other devices on the network

//IPAddress gateway(99,102,156,1); //gateway IP for SSI
//IPAddress subnet(255, 255, 255, 0); //subnet mask for SSI 
//IPAddress gateway(108,72,244,1); //gateway IP for ATLANTA
//IPAddress subnet(255,255,255,0); // subnet mask for ATLANTA


EthernetClient client;


//char SERVER[] = "rtupdate.wunderground.com";           // Realtime update server - RapidFire
char SERVER [] = "weatherstation.wunderground.com";  // Standard server
char WEBPAGE [] = "GET /weatherstation/updateweatherstation.php?";
char ID [] = "KGASAINT3"; //My station ID
char PASSWORD [] = "XXXXX"; // My password

String StringArray[19];  // Array to hold strings set to maximum number of strings to parse
                         // Not sure what number this should be - there are 17 variables sent
                         // from WX transmitter (Serial.print(variable,1); etc
int strCount;            //  number of parsed strings
char incoming_char;      // char coming from serial
boolean ValidStart = false;  // make sure we did not miss start char

void setup() 
{
    
  lcd.init();          // initialize the lcd
  lcd.backlight();     //backlight on
 // uint8_t i = 0;    
  Serial.begin(9600);  // connect to the serial port
  
  // Turn the internet on
  Serial.print("\nInitializing...");
  if (Ethernet.begin(mac) ){
    Serial.println("Initialization complete, LCDMonitor_Ethernet: 9/14/15:08:00");
 	 } 
  else {
    Serial.println("Something went wrong during ethernet startup!");
  	} 
  
}
//end of setup

void loop() {

  //Check for character
  if (Serial.available() > 0) {
    incoming_char = Serial.read();
    // Check for Start End or delimiter
    switch (incoming_char) {
      case '

:
        strCount = 0;  // reset string counter to 0
        StringArray[strCount] = “”;  // clear new string in array
        ValidStart = true;          // got start char
        break;

case ‘,’:
        strCount++;  // set string counter to next string
        StringArray[strCount] = “”; // clear new string in array
        break;

case ‘#’:
        // Print strings to PC
        if (ValidStart )  // make sure we didnt miss start char
          printStrings();
        ValidStart = false;  // reset and wait for next start char
        break;

}
    if (incoming_char != ’


)     // exclude start char and delimiters from parsed strings
      if  (incoming_char != ',')
        StringArray[strCount] += incoming_char;  // append incoming_char to string

  }
}

void printStrings() {      //print parsed strings stored in StringArray
  
  // LCD: first screen: vital stats
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print (StringArray[tempf]);
  lcd.setCursor(0,1);
  lcd.print(StringArray[baromin]);
  lcd.setCursor(0,2);
  lcd.print (StringArray[humidity]);
  lcd.setCursor(0,3);
  lcd.print(StringArray[dewptf]);
  delay(5000);
  
  // second screen
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print (StringArray[winddir]);
  lcd.setCursor(0,1);
  lcd.print(StringArray[windspeedmph]);
  lcd.setCursor(0,2);
  lcd.print(StringArray[windgustmph]);
  lcd.setCursor(0,3);
  lcd.print(StringArray[windgustmph_avg10m]);
  delay(5000);
 
  //third screen
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(StringArray[dailyrainin]);
  lcd.setCursor(0,1);
  lcd.print(StringArray[light_lvl]);
 
  lcd.setCursor(0,3);
  lcd.print(StringArray[batt_lvl]);
 
  delay(5000);
  lcd.clear();
  
  lcd.setCursor(0,1);
  lcd.print("waiting....");
  
  
  //Serial monitor
 Serial.print(WEBPAGE); 
 Serial.print("ID=");
 Serial.print(ID);
 Serial.print("&PASSWORD=");
 Serial.print(PASSWORD);
 Serial.print("&dateutc=");
 Serial.print("now");    //can use instead of Real Time Clock if sending in real time
    
  //variables
  Serial.print("&");
  Serial.print (StringArray[winddir]);
  Serial.print ("&");
  Serial.print(StringArray[windspeedmph]);
  Serial.print ("&");
  Serial.print(StringArray[windgustmph]);
  Serial.print ("&");
  Serial.print (StringArray[windgustdir]);
  Serial.print ("&");
  Serial.print (StringArray[windgustmph_avg2m]);
  Serial.print ("&");
  Serial.print (StringArray[windgustdir_avg2m]);
  Serial.print ("&");
  Serial.print (StringArray[windgustmph_avg10m]);
  Serial.print ("&");
  Serial.print (StringArray[windgustmph_avg10m]);
  Serial.print ("&");
  Serial.print (StringArray[windgustdir_avg10m]);
  Serial.print ("&");
  Serial.print (StringArray[humidity]);
  Serial.print ("&");
  Serial.print (StringArray[dewptf]);
  Serial.print ("&");
  Serial.print (StringArray[tempf]);
  Serial.print ("&");
  Serial.print (StringArray[rainin]);
  Serial.print ("&");
  Serial.print (StringArray[dailyrainin]);
  Serial.print ("&");
  Serial.print (StringArray[baromin]);
  Serial.print ("&");
  
  Serial.print ("action=updateraw");
  Serial.print ("&");
  
  Serial.println();
  
   
   

// Output to LAN
  
 //weather underground header 
    client.print(WEBPAGE); 
    client.print("ID=");
    client.print(ID);
    client.print("&PASSWORD=");
    client.print(PASSWORD);
    client.print("&dateutc=");
    client.print("now");    //can use "now" instead of RTC: time is now
    
 //weather data
  client.print (StringArray[winddir]);
  client.print ("&");
  client.print(StringArray[windspeedmph]);
  client.print ("&");
  client.print(StringArray[windgustmph]);
  client.print ("&");
  client.print (StringArray[windgustdir]);
  client.print ("&");
  client.print(StringArray[windgustmph_avg2m]);
  client.print ("&");
  client.print(StringArray[windgustdir_avg2m]);
  client.print ("&");
  client.print(StringArray[windgustmph_avg10m]);
  client.print ("&");
  client.print(StringArray[windgustdir_avg10m]);
  client.print ("&");
  client.print(StringArray[humidity]);
  client.print ("&");
  client.print(StringArray[dewptf]);
  client.print ("&");
  client.print(StringArray[tempf]);
  client.print ("&");
  client.print (StringArray[rainin]);
  client.print ("&");
  client.print(StringArray[baromin]);
  client.print ("&");
  client.print("action=updateraw");
  client.print("&");
  
  client.println();//seen somewhere that a blank line is needed
  client.flush();
}

This is almost certainly your problem:

String StringArray[19];

The String object does not work well when there's not much sram - which Arduino are you using?

You need to use char arrays for each string and manage them yourself.

Pete

I am using an Arduino uno. Ethernet shield R3. The String arrays seem to work for the LCD and Serial monitor, have the used up all the sram when I get to the client routine posting on WeatherUnderground? Sorry I don't completely understand....

The String arrays seem to work for the LCD and Serial monitor

When the String library starts going wonky, it will overwrite some unpredictable part of sram which could be, for example, one or more of the variables used by the Ethernet library.
The UNO has 2kb of sram. The LiquidCrystal and Ethernet libraries require some amount of this plus whatever your own code needs. Your code will also require some space for its stack. This won't leave very much for the String library to do its thing.
Each of the individual measurements you are reading from the serial port appear to be quite short. If the longest one is, say, 5 characters, you could change the declaration of StringArray to be

char StringArray[17][6];

and manage each one yourself.

Pete

I don't really need the LCD to monitor the stream, so I have commented that out. I have also commented out the Serial monitor part of the sketch too, and reloaded it to my arduino/xbee/ethernet shield stack. I am still not seeing the info posted on Underground.

Although I think I understand what you are saying about freeing up sram, I am a little confused about why the original sketch did send data to Underground for a short while - maybe two or three sends = but has since stopped. I can unplug, reset, even reload the sketches, and I can't get it to send at all. Why is this?

Phil

I have gotten it working. Had not added client.connect(SERVER,80); Duh..... The kind of error that has me scratching my head for a week!

The sketch works with Serial monitor and LCD as well as ethernet. Uses 54% of dynamic memory, leaving 925 bytes.

Thanks for your help. Look for KGASAINT3 on weather underground...

Phil

UPDATE: I spoke too soon. This sketch is only sending the serial data to Weather Underground once. Then it stops sending, although the Serial monitor continues to show new data. I have added client.stop(); and "Ethernet.maintain(); at the end of the data string in hopes of solving the problem. These commands did not work. Any further ideas what may be causing this to hang up?

Phil

Perhaps you should just drop back and work on getting reliable uploads to the weather server, then add in the other features.

I've already explained to you what the problem (with 99.99% certainty) is. You can get rid of this known problem now, or waste your time looking for pixies and elves.

Pete

el_supremo:
I've already explained to you what the problem (with 99.99% certainty) is. You can get rid of this known problem now, or waste your time looking for pixies and elves.

Pete

Instead of having a forum hissy-fit, modify his code with your solution and he can see if ti works. Simple!