From 464929cf8806a42ed29324c5aae825d4a9f54316 Mon Sep 17 00:00:00 2001 From: structix Date: Thu, 24 Aug 2017 22:24:06 +0200 Subject: [PATCH] Decreased the delay of rest response. Finished issue #4 and #6 --- ESP8266/sensornode/sensornode.ino | 44 +++++++++++++++++++------------ 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/ESP8266/sensornode/sensornode.ino b/ESP8266/sensornode/sensornode.ino index e060c25..1eccfee 100644 --- a/ESP8266/sensornode/sensornode.ino +++ b/ESP8266/sensornode/sensornode.ino @@ -39,6 +39,13 @@ WiFiServer server(LISTEN_PORT); float temperature; float humidity; + + +//milli counter +long millitotal = 0; + + + void setup() { Serial.begin(115200); Serial.println("Sensornode start"); @@ -74,25 +81,28 @@ void setup() { void loop() { // Wait a few seconds between measurements. - delay(2000); - - // Reading temperature or humidity takes about 250 milliseconds! - // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) - float h = dht.readHumidity(); - // Read temperature as Celsius (the default) - float 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 { - //set the new values - humidity = h; - temperature = t; + float millicounter = millis(); + 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) + float h = dht.readHumidity(); + // Read temperature as Celsius (the default) + float 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 { + //set the new values + humidity = h; + temperature = t; + + } + //set new milli counter + millitotal = millis() + 2000; + } // Handle REST calls WiFiClient client = server.available(); if (!client) {