@@ -39,6 +39,13 @@ WiFiServer server(LISTEN_PORT);
|
|||||||
float temperature;
|
float temperature;
|
||||||
float humidity;
|
float humidity;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//milli counter
|
||||||
|
long millitotal = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("Sensornode start");
|
Serial.println("Sensornode start");
|
||||||
@@ -74,25 +81,28 @@ void setup() {
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// Wait a few seconds between measurements.
|
// Wait a few seconds between measurements.
|
||||||
delay(2000);
|
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();
|
||||||
|
|
||||||
// Reading temperature or humidity takes about 250 milliseconds!
|
// Check if any reads failed and exit early (to try again).
|
||||||
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
|
if (isnan(h) || isnan(t)) {
|
||||||
float h = dht.readHumidity();
|
Serial.println("Failed to read from DHT sensor!");
|
||||||
// Read temperature as Celsius (the default)
|
return;
|
||||||
float t = dht.readTemperature();
|
} else {
|
||||||
|
//set the new values
|
||||||
|
humidity = h;
|
||||||
|
temperature = t;
|
||||||
|
|
||||||
// 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
|
// Handle REST calls
|
||||||
WiFiClient client = server.available();
|
WiFiClient client = server.available();
|
||||||
if (!client) {
|
if (!client) {
|
||||||
|
Reference in New Issue
Block a user