Closed jumper-d-1981 closed 9 months ago
I will close this. BUT just so anyone else who happens across it.
WUNDERGROUND was bought by IBM apparently and no longer allows accounts to upload data without a fee and it is not cheap, unless you already had PWS devices uploading prior to the takeover. SO try looking up his Open Weather stations...similar but different site.
Yes IBM purchased WU and it all changed for the worst!
I am using the correct PWS ID, and my wunderground account pw as mentioned in the documentation but cannot successfully connect.
I am testing this with a DHT11, so the only other lines modified is the pin assignment, and the dht type.
It looks like the SW_temp, dewpoint and humidity lines in the system_variables.h file was already set correctly.
I am eventually wanting to add in the wind direction, wind speed, and rain sensors, possibly air quality as well. BUT first things first. This is the complete output I am getting. WiFi connected IP address: 192.168.254.30 Upload date-time: CCYY-MM-DD HH:MM:SS expected Upload date-time: 1970-01-01+00:00:02 Connecting to : weatherstation.wunderground.com Connection failed Error uploading to Weather Underground, trying next time
And just in case you want to view the code as I have it...
ifdef ESP32
include
else
include
endif
include
include // Built-in
include "system_variables.h"
include
include
define DHTPIN 26 // Pin which is connected to the DHT sensor.
// Uncomment the type of sensor in use: //#define DHTTYPE DHT11 // DHT 11
define DHTTYPE DHT11 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// See guide for details on sensor wiring and usage: // https://learn.adafruit.com/dht/overview
// Connect pin 1 (on the left) of the sensor to +5V // NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1 // to 3.3V instead of 5V! // Connect pin 2 of the sensor to whatever your DHTPIN is // Connect pin 4 (on the right) of the sensor to GROUND // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
// Initialize DHT sensor. // Note that older versions of this library took an optional third parameter to // tweak the timings for faster processors. This parameter is no longer needed // as the current DHT reading algorithm adjusts itself to work on faster procs. DHT dht(DHTPIN, DHTTYPE);
const char ssid = "NewHome"; const char password = ""; String WU_pwsID = "KWVCHLOE1"; // The PWS ID as registered and assigned to you by wunderground.com String WU_pwsPASSWORD = "%asz5+mE,MK,xDF"; // **** The PASSWORD registered for your wunderground.com account, not the password issued for the new PWS ID !
const char* host = "weatherstation.wunderground.com";//"rtupdate.wunderground.com"; const int httpsPort = 443;
ifdef ESP32
const unsigned long UpdateInterval = 30L60L1000000L; // Delay between updates, in milliseconds, WU allows 500 requests per-day maximum, this sets the time to 30-mins
else
const unsigned long UpdateInterval = 30L60L1000L; // Delay between updates, in milliseconds, WU allows 500 requests per-day maximum, this sets the time to 30-mins
endif
String UploadData, timenow; float sensor_temperature, sensor_humidity, sensor_pressure, sensor_spare;
void setup() { Serial.begin(115200); dht.begin(); StartWiFi(); StartAndGetTime(); }
void loop() { // NOTE-1: You must define the parameters for upload to WU, goto 'system_variables' tab and uncomment the required parameter e.g. '//#define SW_winddir' becomes '#define SW_winddir' // NOTE-2: If you read a sensor as a floating point, you must assign the result to a corresponding String variable as listed in the WU_variable_names in the 'system_variable.h list' // NOTE: e.g. float Winddir = 270; then WU_winddir = String(Winddir); ReadSensorInformation(); UpdateTime(); timenow = "now"; // or comment this line to upload the local time from the ESP time update if (!UploadDataToWU()); Serial.println("Error uploading to Weather Underground, trying next time"); delay(5601000); // for a 5-min update rate // or to make it sleep uncomment this section and comment out the sleep() line above
ifdef ESP8266
else
endif
}
boolean UploadDataToWU(){ WiFiClientSecure client; // Use WiFiClientSecure class to create SSL connection Serial.println("Connecting to : "+String(host)); if (!client.connect(host, httpsPort)) { Serial.println("Connection failed"); return false; } String url = "/weatherstation/updateweatherstation.php?ID="+WU_pwsID+"&PASSWORD="+WU_pwsPASSWORD+"&dateutc="+timenow +
ifdef SW_tempf
Serial.println("Requesting : "+url); client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "User-Agent: G6EJDFailureDetectionFunction\r\n" + "Connection: close\r\n\r\n"); Serial.print("Request sent : "); while (client.connected()) { String line = client.readStringUntil('\n'); if (line == "\r") { Serial.println("Headers received"); break; } } String line = client.readStringUntil('\n'); //Serial.println(line); boolean Status = true; if (line == "success") line = "Server confirmed all data received"; if (line == "INVALIDPASSWORDID|Password or key and/or id are incorrect") { line = "Invalid PWS/User data entered in the ID and PASSWORD or GET parameters"; Status = false; } if (line == "RapidFire Server") { line = "The minimum GET parameters of ID, PASSWORD, action and dateutc were not set correctly"; Status = false; } Serial.println("Server Response : "+line); Serial.println("Status : Closing connection"); return Status; }
void ReadSensorInformation(){ float sensor_humidity = dht.readHumidity(); float sensor_temperature = dht.readTemperature(true); // Read temperature as Fahrenheit (isFahrenheit = true) if (isnan(sensor_humidity) || isnan(sensor_temperature)) { Serial.println("Failed to read from DHT sensor!"); return; } WU_tempf = String(sensor_temperature); WU_dewptf = String((sensor_temperature-(100-sensor_humidity)/5.0)*9/5+32); WU_humidity = String(sensor_humidity,2); }
void StartWiFi(){ Serial.print("\nConnecting to "); Serial.println(ssid); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); }
void StartAndGetTime(){ configTime(0, 0, "0.uk.pool.ntp.org", "time.nist.gov"); setenv("TZ", "GMT0BST,M3.5.0/01,M10.5.0/02",1); delay(200); time_t rawtime; struct tm *info; char buffer[80]; time( &rawtime ); info = localtime( &rawtime ); // Upload format for time = dateutc [CCYY-MM-DD HH:MM:SS (mysql format)] // 2018-04-30 10:32:35 becomes 2018-04-30+10%3A32%3A35 in url escaped format // See: http://www.cplusplus.com/reference/ctime/strftime/ Serial.println("Upload date-time: CCYY-MM-DD HH:MM:SS expected"); strftime(buffer,80,"%Y-%m-%d+%H:%M:%S", info); //printf("Upload date-time: %s\n", buffer ); timenow = buffer; // timenow is correctly formated for WU timenow.replace(":", "%3A"); }
void UpdateTime(){ time_t rawtime; struct tm *info; char buffer[80]; time( &rawtime ); info = localtime( &rawtime ); strftime(buffer,80,"%Y-%m-%d+%H:%M:%S", info); printf("Upload date-time: %s\n", buffer ); timenow = buffer; timenow.replace(":", "%3A"); // timenow is correctly formated for WU }
//#################################################################### /* A new Personal Weather Station (PWS) needs to setup and wait for it to be activiated, this can take a few minutes, maybe up to 20mins. Upload values allowed: &dateutc=2000-01-01+10%3A32%3A35 or dateutc=now &winddir=230 &windspeedmph=12 &windgustmph=12 &tempf=70
OR using their Rapid Fire Server
http://wiki.wunderground.com/index.php/PWS_-_Upload_Protocol
usage: action [action = updateraw] ID [PWS ID as registered by wunderground.com] PASSWORD [PASSWORD registered with this ID] dateutc - [YYYY-MM-DD HH:MM:SS (mysql format)] or dateutc=now winddir - [0-360] windspeedmph - [mph] windgustmph - [windgustmph ] humidity - [%] tempf - [temperature F] rainin - [rain in] dailyrainin - [daily rain in accumulated] baromin - [barom in] dewptf- [dewpoint F] weather - [text] -- metar style (+RA) clouds - [text] -- SKC, FEW, SCT, BKN, OVC softwaretype - [text] ie: vws or weatherdisplay */