171Views2Replies

Author Options:

Arduino WX code help for Weather Underground data upload? Answered

Hello-

I tried to recreate this WiFi Weather Station project using most of the same parts except for the Arduino WiFi101 shield.  I am having a problem with the data only being uploaded once.  The code tries again, but it seems the connection to WU fails after the first time.  I have to hit the reset button on the board or reload the code for it to upload again.  

I am wondering if the connection to WU needs to be severed after each upload and the entire process needs to repeat after that.  I have no idea...  Someone else posted a comment in the comment section for the project with same issue and the author has never responded to the upload issue. 

Any help would be great.  

Here is the code:

int DEBUG = 1;

#include <DHT.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085.h>
#include <Adafruit_SI1145.h>    //UV sensor
#include <SPI.h>
#include <WiFi101.h>

#define DHTPIN 2

#define DHTTYPE DHT22 //DHT22

//Constants
char ssid[] = "******";     //  your network SSID (name)
char pass[] = "******";    // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status

char SERVER[] = "rtupdate.wunderground.com";           // Realtime update server - RapidFire
char WEBPAGE [] = "GET /weatherstation/updateweatherstation.php?";
char ID [] = "**********";
char PASSWORD [] = "*********";

DHT dht(DHTPIN, DHTTYPE);

Adafruit_SI1145 uv = Adafruit_SI1145(); // UV Sensor
Adafruit_BMP085 bmp;

WiFiClient client;

void setup(void)
{
  Serial.begin(9600);
  Wire.begin();
  dht.begin();
  uv.begin();
  bmp.begin();

  Serial.println("Attempting to connect to WPA network...");
  status = WiFi.begin(ssid, pass);

   //if you're not connected, stop here:
  if ( status != WL_CONNECTED) {
    Serial.println("Couldn't get a wifi connection");
    while(true);
  }
   //if you are connected, print out info about the connection:
  else {
    Serial.println("WiFi is a Go!!");
 
  }

}
void loop(void){ 

  //Get sensor data
  float tempc = bmp.readTemperature(); 
  float tempf =  (tempc * 9.0)/ 5.0 + 32.0; 
  float humidity = dht.readHumidity();
  float baromin = bmp.readPressure()* 0.0002953;
  float dewptf = (dewPoint(tempf, dht.readHumidity())); 
  float UVindex = uv.readUV();
        UVindex /= 100.0;
                           
  if (DEBUG) {  

  Serial.println("+++++++++++++++++++++++++");

  Serial.print("temp= ");
  Serial.print(tempf);
  Serial.println(" *F");
  Serial.print("baro= ");
  Serial.print(baromin);
  Serial.println(" inHg");
  Serial.print("dew point= ");
  Serial.println(dewptf);
  Serial.print("humidity= ");
  Serial.println(humidity);
  Serial.print("UV: "); 
  Serial.println(UVindex);
  }//End debug loop

//Send data to Weather Underground
if (client.connect(SERVER, 80)) {
    if (DEBUG) {   
      Serial.println("Sending DATA ");
      }
    // Ship it!
    client.print(WEBPAGE);
    client.print("ID=");
    client.print(ID);
    client.print("&PASSWORD=");
    client.print(PASSWORD);
    client.print("&dateutc=");
    client.print("now");

    client.print("&tempf=");
    client.print(tempf);
    client.print("&baromin=");
    client.print(baromin);
    client.print("&dewptf=");
    client.print(dewptf);
    client.print("&humidity=");
    client.print(humidity);
    client.print("&uv=");
    client.print(UVindex);
    client.print("&softwaretype=Arduino%20UNO%20version1&action=updateraw&realtime=1&rtfreq=2.5");//Rapid Fire
    client.println();
   
    if (DEBUG) {  
      Serial.println("Upload complete");
      }
     
   }//End send loop
    else {
      if (DEBUG) { Serial.println(F("Connection failed")); }
      return;
      }
   
    delay(2500);
   

}//End loop

/****************************************************************

  Function Fun Time

****************************************************************/

double dewPoint(double tempf, double humidity)
{
  double A0= 373.15/(273.15 + tempf);
  double SUM = -7.90298 * (A0-1);
  SUM += 5.02808 * log10(A0);
  SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
  SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
  SUM += log10(1013.246);
  double VP = pow(10, SUM-3) * humidity;
  double T = log(VP/0.61078);  
  return (241.88 * T) / (17.558-T);
}

Discussions

0
None
rwcwx

1 year ago

I was able to figure this out by adding the following line after the "Upload Complete" statement:

client.stop();

which disconnects from the WU server, but doesn't kill the WiFi connection.

0
None
Downunder35mrwcwx

Answer 1 year ago

I am not 100% sure as I don't play with WiFi shields but I think you might have to test the data transfer in your LOOP.
If the module is only initialised in the setup and instead of all the sensor stuff you simply transfer a line of data like "Hello World" in the loop section you should see if it transmits or not.
Also you seem to stay connected to the website at all times, it might help to change the code so the data is collected only every 5 minutes or so and to initialise the connection fresh each time.