Added deepsleep
This commit is contained in:
@@ -60,42 +60,29 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// Wait a few seconds between measurements.
|
// Reading temperature or humidity takes about 250 milliseconds!
|
||||||
millicounter = millis();
|
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
|
||||||
|
h = dht.readHumidity();
|
||||||
|
// Read temperature as Celsius (the default)
|
||||||
|
t = dht.readTemperature();
|
||||||
|
|
||||||
if (millicounter >= millitotal) {
|
// Check if any reads failed and exit early (to try again).
|
||||||
// Reading temperature or humidity takes about 250 milliseconds!
|
if (isnan(h) || isnan(t)) {
|
||||||
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
|
Serial.println("Failed to read from DHT sensor!");
|
||||||
h = dht.readHumidity();
|
return;
|
||||||
// Read temperature as Celsius (the default)
|
} else {
|
||||||
t = dht.readTemperature();
|
// Initialize the client library
|
||||||
|
HTTPClient client;
|
||||||
|
|
||||||
// Check if any reads failed and exit early (to try again).
|
// Make a HTTP request:
|
||||||
if (isnan(h) || isnan(t)) {
|
String url = "http://raspitemp:1337/abshum/" + String(t) + "/" + String(h);
|
||||||
Serial.println("Failed to read from DHT sensor!");
|
client.begin(url);
|
||||||
return;
|
client.GET();
|
||||||
} else {
|
client.end();
|
||||||
// Initialize the client library
|
|
||||||
HTTPClient client;
|
|
||||||
|
|
||||||
// Make a HTTP request:
|
|
||||||
String url = "http://raspitemp:1337/abshum/" + String(t) + "/" + String(h);
|
|
||||||
client.begin(url);
|
|
||||||
client.GET();
|
|
||||||
client.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
//set new milli counter
|
|
||||||
//millis will overflow after approx. 52 days. To prevent errors we're checking the limits
|
|
||||||
if (millis() + (MEASURESECONDS * 1000) <= ULONG_MAX) {
|
|
||||||
millitotal = millis() + (MEASURESECONDS * 1000);
|
|
||||||
} else {
|
|
||||||
millitotal = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//ESP.deepSleep(MEASURESECONDS * 1000);
|
ESP.deepSleep(MEASURESECONDS * 1000000);
|
||||||
//Let the esp chill a bit
|
//Let the esp chill a bit
|
||||||
delay(100);
|
delay(100);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user