From 6fbc1d350f7c9837315dc66da3aaf389413ee020 Mon Sep 17 00:00:00 2001 From: structix Date: Sat, 16 Sep 2017 18:14:42 +0200 Subject: [PATCH] Added deepsleep --- ESP8266/sensornode/sensornode.ino | 49 ++++++++++++------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/ESP8266/sensornode/sensornode.ino b/ESP8266/sensornode/sensornode.ino index 0ed48d3..2c042ac 100644 --- a/ESP8266/sensornode/sensornode.ino +++ b/ESP8266/sensornode/sensornode.ino @@ -60,42 +60,29 @@ void setup() { } void loop() { - // Wait a few seconds between measurements. - millicounter = millis(); + // Reading temperature or humidity takes about 250 milliseconds! + // 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) { - // Reading temperature or humidity takes about 250 milliseconds! - // 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(); - - // Check if any reads failed and exit early (to try again). - if (isnan(h) || isnan(t)) { - Serial.println("Failed to read from DHT sensor!"); - return; - } else { - // Initialize the client library - HTTPClient client; + // Check if any reads failed and exit early (to try again). + if (isnan(h) || isnan(t)) { + Serial.println("Failed to read from DHT sensor!"); + return; + } else { + // 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; - } + // Make a HTTP request: + String url = "http://raspitemp:1337/abshum/" + String(t) + "/" + String(h); + client.begin(url); + client.GET(); + client.end(); } - //ESP.deepSleep(MEASURESECONDS * 1000); + ESP.deepSleep(MEASURESECONDS * 1000000); //Let the esp chill a bit delay(100); }