Created
January 17, 2016 01:53
-
-
Save wero1414/f7172973d0552641ab33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include "DHT.h" | |
const char* ssid = "Your SSID"; | |
const char* password = "Your password"; | |
const int sleepTimeS = 600; //18000 for Half hour | |
#define DHTPIN 2 | |
#define DHTTYPE DHT11 | |
char server [] = "weatherstation.wunderground.com"; | |
char WEBPAGE [] = "GET /weatherstation/updateweatherstation.php?"; | |
char ID [] = "Your weather station ID"; | |
char PASSWORD [] = "Your password"; | |
DHT dht(DHTPIN, DHTTYPE); | |
void setup(){ | |
Serial.begin(9600); | |
dht.begin(); | |
delay(1000); | |
Serial.println(); | |
Serial.print("Connecting to "); | |
Serial.println(ssid); | |
WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
} | |
void loop(){ | |
//Get sensor data | |
float tempc = dht.readTemperature(); | |
float tempf = (tempc * 9.0)/ 5.0 + 32.0; | |
float humidity = dht.readHumidity(); | |
float dewptf = (dewPoint(tempf, dht.readHumidity())); | |
//check sensor data | |
Serial.println("+++++++++++++++++++++++++"); | |
Serial.print("tempF= "); | |
Serial.print(tempf); | |
Serial.println(" *F"); | |
Serial.print("tempC= "); | |
Serial.print(tempc); | |
Serial.println(" *C"); | |
Serial.print("dew point= "); | |
Serial.println(dewptf); | |
Serial.print("humidity= "); | |
Serial.println(humidity); | |
//Send data to Weather Underground | |
Serial.print("connecting to "); | |
Serial.println(server); | |
WiFiClient client; | |
if (!client.connect(server, 80)) { | |
Serial.println("Conection Fail"); | |
return; | |
} | |
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("&dewptf="); | |
client.print(dewptf); | |
client.print("&humidity="); | |
client.print(humidity); | |
client.print("&softwaretype=ESP%208266O%20version1&action=updateraw&realtime=1&rtfreq=2.5"); | |
client.println(); | |
delay(2500); | |
sleepMode(); | |
} | |
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); | |
} | |
void sleepMode(){ | |
Serial.print(F("Sleeping...")); | |
ESP.deepSleep(sleepTimeS * 1000000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment